473,661 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get access to a control created at runtime

Inside a method some controls are created at runtime.
I added an event handler to one of these controls:

tracker.Scroll += new System.EventHan dler(this.track er_Scroll);

So in the event handler I used unboxing to get access to the value of the
TrackBar:

private void tracker_Scroll( object sender, System.EventArg s e)
{
TrackBar currTrack = (TrackBar)sende r;
MessageBox.Show (currTrack.Valu e.ToString());
}

It works fine, but inside the event handler I also want to change the
property of another control created at runtime (set a TextBox to the value
of the TrackBar).
My question is, of course, how do I do that, how do I get access to the
TextBox created at runtime?

Thank you.
Nov 16 '05 #1
5 5521
Have you tried playing with the Controls collection of your form?

Telmo Sampaio

"Andrei Pociu" <an**********@g eekpedia.com> wrote in message
news:OH******** ******@TK2MSFTN GP12.phx.gbl...
Inside a method some controls are created at runtime.
I added an event handler to one of these controls:

tracker.Scroll += new System.EventHan dler(this.track er_Scroll);

So in the event handler I used unboxing to get access to the value of the
TrackBar:

private void tracker_Scroll( object sender, System.EventArg s e)
{
TrackBar currTrack = (TrackBar)sende r;
MessageBox.Show (currTrack.Valu e.ToString());
}

It works fine, but inside the event handler I also want to change the
property of another control created at runtime (set a TextBox to the value
of the TrackBar).
My question is, of course, how do I do that, how do I get access to the
TextBox created at runtime?

Thank you.

Nov 16 '05 #2
At design time, if you know you will eventually create the Textbox, you can
create its reference. At compile time it will be null. In you eventhandler,
before using it, check to make sure your control was actually created (and
assigned to your Textbox reference).

If this doesn't apply, you'll have to know something (i.e. its name) about
the control. So when the Textbox is created, add it to the Form Controll
collection. In your eventhandler, search the Controls collection for the
Textbox with the matching name.

good luck
kevin aubuchon

"Andrei Pociu" <an**********@g eekpedia.com> wrote in message
news:OH******** ******@TK2MSFTN GP12.phx.gbl...
Inside a method some controls are created at runtime.
I added an event handler to one of these controls:

tracker.Scroll += new System.EventHan dler(this.track er_Scroll);

So in the event handler I used unboxing to get access to the value of the
TrackBar:

private void tracker_Scroll( object sender, System.EventArg s e)
{
TrackBar currTrack = (TrackBar)sende r;
MessageBox.Show (currTrack.Valu e.ToString());
}

It works fine, but inside the event handler I also want to change the
property of another control created at runtime (set a TextBox to the value
of the TrackBar).
My question is, of course, how do I do that, how do I get access to the
TextBox created at runtime?

Thank you.

Nov 16 '05 #3
Telmo, I have tried that, unfortunately it doesn't seem to work.

Kevin, I did this (creating the TextBox reference) some time ago when I had
the same problem and it works.
Probably I'll end up doing it again, but there are lots of controls created
at runtime in different methods, so I thought that there might be a better
solution than creating a reference to all of them.

Thank you both.

"Andrei Pociu" <an**********@g eekpedia.com> wrote in message
news:OH******** ******@TK2MSFTN GP12.phx.gbl...
Inside a method some controls are created at runtime.
I added an event handler to one of these controls:

tracker.Scroll += new System.EventHan dler(this.track er_Scroll);

So in the event handler I used unboxing to get access to the value of the
TrackBar:

private void tracker_Scroll( object sender, System.EventArg s e)
{
TrackBar currTrack = (TrackBar)sende r;
MessageBox.Show (currTrack.Valu e.ToString());
}

It works fine, but inside the event handler I also want to change the
property of another control created at runtime (set a TextBox to the value
of the TrackBar).
My question is, of course, how do I do that, how do I get access to the
TextBox created at runtime?

Thank you.

Nov 16 '05 #4
What do you mean by "it doesn't seem to work" (regarding the Controls
collection)?
If the control was added to the Controls collection, it'll be there. The
'problem' is if you didn't add the control straight on the form but on
one of the panels/tabpages/etc. on it, in which case you should traverse
the container-control relationships along the way.

Andrei Pociu wrote:
Telmo, I have tried that, unfortunately it doesn't seem to work.

Kevin, I did this (creating the TextBox reference) some time ago when I had
the same problem and it works.
Probably I'll end up doing it again, but there are lots of controls created
at runtime in different methods, so I thought that there might be a better
solution than creating a reference to all of them.

Thank you both.

"Andrei Pociu" <an**********@g eekpedia.com> wrote in message
news:OH******** ******@TK2MSFTN GP12.phx.gbl...
Inside a method some controls are created at runtime.
I added an event handler to one of these controls:

tracker.Scrol l += new System.EventHan dler(this.track er_Scroll);

So in the event handler I used unboxing to get access to the value of the
TrackBar:

private void tracker_Scroll( object sender, System.EventArg s e)
{
TrackBar currTrack = (TrackBar)sende r;
MessageBox.Show (currTrack.Valu e.ToString());
}

It works fine, but inside the event handler I also want to change the
property of another control created at runtime (set a TextBox to the value
of the TrackBar).
My question is, of course, how do I do that, how do I get access to the
TextBox created at runtime?

Thank you.


Nov 16 '05 #5
Yes, the control is in a panel... that's why the control couldn't be added
to the Controls collection.
I'll try this, thanks.

"Uri Dor" <ta****@newsgro ups.nospam> wrote in message
news:eb******** ******@tk2msftn gp13.phx.gbl...
What do you mean by "it doesn't seem to work" (regarding the Controls
collection)?
If the control was added to the Controls collection, it'll be there. The
'problem' is if you didn't add the control straight on the form but on
one of the panels/tabpages/etc. on it, in which case you should traverse
the container-control relationships along the way.

Andrei Pociu wrote:
Telmo, I have tried that, unfortunately it doesn't seem to work.

Kevin, I did this (creating the TextBox reference) some time ago when I had the same problem and it works.
Probably I'll end up doing it again, but there are lots of controls created at runtime in different methods, so I thought that there might be a better solution than creating a reference to all of them.

Thank you both.

"Andrei Pociu" <an**********@g eekpedia.com> wrote in message
news:OH******** ******@TK2MSFTN GP12.phx.gbl...
Inside a method some controls are created at runtime.
I added an event handler to one of these controls:

tracker.Scrol l += new System.EventHan dler(this.track er_Scroll);

So in the event handler I used unboxing to get access to the value of theTrackBar:

private void tracker_Scroll( object sender, System.EventArg s e)
{
TrackBar currTrack = (TrackBar)sende r;
MessageBox.Show (currTrack.Valu e.ToString());
}

It works fine, but inside the event handler I also want to change the
property of another control created at runtime (set a TextBox to the valueof the TrackBar).
My question is, of course, how do I do that, how do I get access to the
TextBox created at runtime?

Thank you.


Nov 16 '05 #6

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

Similar topics

49
14324
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The application is relatively big: around 200 tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data (SQL Server 2000), 40 users. I'm wondering what are the disadvantages of using Access as front-end? Other that it's not...
7
8850
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
7
6986
by: Lau Lei Cheong | last post by:
Hello, I'm using javascript's insertAdjacentHtml() to insert images to the webform at runtime. This runs fine(image successfully displayed at the browser) but when I tried to access the control's src using FindControl() function in the code-behind, it seems that the control doesn't even exist. I know that I can add controls on the server-side, but then a postback will be needed which is the thing I want to avoid. Does anyone have idea...
5
1995
by: Guillaume BRAUX | last post by:
Hello, What I want to do is to add a userControl to a form class witch is a different class from the one the button is generated. For example, I want to instanciate a label in "class1" and add it ("show it") on a WinForm situated in "class2" (without having to add code to class2 !) The problem is that I need to instanciate "class2" from "class1" to be able to do a class2.controls.add(myLabel) in class1..
7
7056
by: ddecoste | last post by:
I have a need to add a visual representation to some data in Access. I need to draw a matix of squares inside another square. I have all the data that I need in a record in Access. The data changes according to what the user inputs. I know that Access does not allow you to draw on forms so I decided to put the output in an Excel file for the user but I am having trouble drawing the rectange from Access. Here is my simple code so far: ...
17
7659
by: Neil | last post by:
A client of mine likes some of the new bells and whistles in Access 2007, and is thinking about converting our A03 format MDB to an A07 format file. However, while some of the users have A07, many do not, and it's not clear when they would get it. His thought was to use the upcoming Access 2007 runtime to allow the users who are still running Office 2003 to be able to run the database. While I use multiple versions of Access on my...
16
11062
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might know one way or the other whether that was true or not, or could point me to an article or help text that would. What I have seen so far online and in Access 2007 help seems to confirm the above. But that (or at least (b)) seems incredible that it...
7
2289
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using FindControl the only way to do it?
5
5879
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of the screen. I have been unable to find any way to disable this button in Access 2007 and subsequently I have been forced to find ways to detect and handle the situations after the Access Close button has been clicked. I have been largely...
0
8341
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
8754
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
8630
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...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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
5650
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();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.