473,811 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can i dynamically set a reference to a form control?

i want to allow my "Cut" command to dynamically determine the active control
and cut any selected text from it (assuming it's a textBox control). so far
i've got this:

private void menuItem5_Click (object sender, System.EventArg s e)

{

Object oControlType =
System.Windows. Forms.Form.Acti veForm.ActiveCo ntrol.GetType() ;

if (oControlType.T oString() == "System.Windows .Forms.TextBox" )

{

oActiveControl = System.Windows. Forms.Form.Acti veForm.ActiveCo ntrol;

if(oActiveContr ol.SelectedText != "")

{

oActiveControl. Cut();

}

}

}

i want to set oActiveControl to the active textBox and cut any text, but
this doesn't work. is there a way to pull this off or do i have to first
determine exactly which textBox is active and then cut from there?

tks
Nov 17 '05 #1
2 1809
Dica,

You should be able to do something like this:

// Get the control.
object control = System.Windows. Forms.Form.Acti veForm.ActiveCo ntrol;

// Try to cast to a textbox.
TextBox textBox = control as System.Windows. Forms.TextBox;

// If the textbox exists, then work with it.
if (textBox != null)
{
// Do your cut and paste operation here.
}

The "as" operator will attempt to cast the variable before it (in this
case "control") to the type that comes after it. If it succeeds, it returns
the typed result, otherwise it returns null (it returns null if the variable
is null as well).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dica" <ge*****@hotmai l.com> wrote in message
news:0b******** *************** *******@rogers. com...
i want to allow my "Cut" command to dynamically determine the active
control
and cut any selected text from it (assuming it's a textBox control). so
far
i've got this:

private void menuItem5_Click (object sender, System.EventArg s e)

{

Object oControlType =
System.Windows. Forms.Form.Acti veForm.ActiveCo ntrol.GetType() ;

if (oControlType.T oString() == "System.Windows .Forms.TextBox" )

{

oActiveControl = System.Windows. Forms.Form.Acti veForm.ActiveCo ntrol;

if(oActiveContr ol.SelectedText != "")

{

oActiveControl. Cut();

}

}

}

i want to set oActiveControl to the active textBox and cut any text, but
this doesn't work. is there a way to pull this off or do i have to first
determine exactly which textBox is active and then cut from there?

tks

Nov 17 '05 #2

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:uu******** ******@TK2MSFTN GP10.phx.gbl...
Dica,

You should be able to do something like this:

// Get the control.
object control = System.Windows. Forms.Form.Acti veForm.ActiveCo ntrol;

// Try to cast to a textbox.
TextBox textBox = control as System.Windows. Forms.TextBox;

// If the textbox exists, then work with it.
if (textBox != null)
{
// Do your cut and paste operation here.
}

The "as" operator will attempt to cast the variable before it (in this
case "control") to the type that comes after it. If it succeeds, it returns the typed result, otherwise it returns null (it returns null if the variable is null as well).

Hope this helps.
works like a charm. tks nicholas.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dica" <ge*****@hotmai l.com> wrote in message
news:0b******** *************** *******@rogers. com...
i want to allow my "Cut" command to dynamically determine the active
control
and cut any selected text from it (assuming it's a textBox control). so
far
i've got this:

private void menuItem5_Click (object sender, System.EventArg s e)

{

Object oControlType =
System.Windows. Forms.Form.Acti veForm.ActiveCo ntrol.GetType() ;

if (oControlType.T oString() == "System.Windows .Forms.TextBox" )

{

oActiveControl = System.Windows. Forms.Form.Acti veForm.ActiveCo ntrol;

if(oActiveContr ol.SelectedText != "")

{

oActiveControl. Cut();

}

}

}

i want to set oActiveControl to the active textBox and cut any text, but
this doesn't work. is there a way to pull this off or do i have to first
determine exactly which textBox is active and then cut from there?

tks


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3024
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g....
1
2580
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g. wucCustomerInfo.ascx,
12
13283
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the same Tag number. (I thought it might help) The checkboxes name is a concatenation of "chkCancel" and a number that represents the order in which they were created: chkCancel0 (Tag = 0) chkCancel1 (Tag = 1)
7
6677
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
3
5280
by: Allen Chen [MSFT] | last post by:
Hi Richard, Quote from Richard================================================== However I also want to be able to remove the panes. I have tried to include this, but find that when I first add the pane the remove event does not get handled, though thereafter it is handled without problems. ==================================================
0
9731
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4342
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.