Inside a method some controls are created at runtime.
I added an event handler to one of these controls:
tracker.Scroll += new System.EventHandler(this.tracker_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.EventArgs e)
{
TrackBar currTrack = (TrackBar)sender;
MessageBox.Show(currTrack.Value.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. 5 5504
Have you tried playing with the Controls collection of your form?
Telmo Sampaio
"Andrei Pociu" <an**********@geekpedia.com> wrote in message
news:OH**************@TK2MSFTNGP12.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.EventHandler(this.tracker_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.EventArgs e) { TrackBar currTrack = (TrackBar)sender; MessageBox.Show(currTrack.Value.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.
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**********@geekpedia.com> wrote in message
news:OH**************@TK2MSFTNGP12.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.EventHandler(this.tracker_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.EventArgs e) { TrackBar currTrack = (TrackBar)sender; MessageBox.Show(currTrack.Value.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.
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**********@geekpedia.com> wrote in message
news:OH**************@TK2MSFTNGP12.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.EventHandler(this.tracker_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.EventArgs e) { TrackBar currTrack = (TrackBar)sender; MessageBox.Show(currTrack.Value.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.
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**********@geekpedia.com> wrote in message news:OH**************@TK2MSFTNGP12.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.EventHandler(this.tracker_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.EventArgs e) { TrackBar currTrack = (TrackBar)sender; MessageBox.Show(currTrack.Value.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.
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****@newsgroups.nospam> wrote in message
news:eb**************@tk2msftngp13.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**********@geekpedia.com> wrote in message news:OH**************@TK2MSFTNGP12.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.EventHandler(this.tracker_Scroll);
So in the event handler I used unboxing to get access to the value of
theTrackBar:
private void tracker_Scroll(object sender, System.EventArgs e) { TrackBar currTrack = (TrackBar)sender; MessageBox.Show(currTrack.Value.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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
| |