473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to reference a control which was added programmingly

Hi, everyone

After adding a control into a container like form using form.controls.add(myControl), how could I reference it
For example
dim aControl as new butto
me.controls.add(aControl

then I want set backcolor of this button, how

Thanks

william
Jul 21 '05 #1
3 1302
\\\
Dim aControl As New Button

Me.Controls.Add(aControl)

aControl.BackColor = Color.Blue
///

HTH,
Gary

"william" <an*******@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Hi, everyone,

After adding a control into a container like form using form.controls.add(myControl), how could I reference it? For example,
dim aControl as new button
me.controls.add(aControl)

then I want set backcolor of this button, how?

Thanks.

william

Jul 21 '05 #2
APG
Hi William,

You can use the same button object till it is within scope. For example,

Dim aControl As New Button
Me.Controls.Add(aControl)

aControl.BackColor = Color.AliceBlue

HTH.

william wrote:
Hi, everyone,

After adding a control into a container like form using form.controls.add(myControl), how could I reference it?
For example,
dim aControl as new button
me.controls.add(aControl)

then I want set backcolor of this button, how?

Thanks.

william

Jul 21 '05 #3

"william" <an*******@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
Hi,
The problem is I did it in a function, so the object(control) is out of the scope. Here is the case:
In my form load event, I call a function to load all controls programmingly, then in other function, I want to use these controls. For example,
private sub Form_Load(...)
...
LoadControl
end sub
private sub LoadControl
dim aButton as new button
aButton.name="MyButton"
aButton.text="OK"
'add other properties here
me.Controls.Add(aButton)
...
end sub
private sub MyFunction
...
'todo: need set Backcolor=blue to the button with name of "MyButton"

end sub

How can I get the proper button handler?

thanks

william


The simplest approach is to declare your control variables at the form
scope, not the LoadControl scope. You can then access the variables from any
method in the form class.

Your only other approach is to loop through the controls in the form's
controls collection, looking for the control that matches the criteria you
want to match, then setting the BackColor of that control. This is a very
bad option, though, since you would be looping through every time you wanted
to change a property of a control. Better to just declare the variables at
the form's scope.
Jul 21 '05 #4

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

Similar topics

3
by: william | last post by:
Hi, everyone After adding a control into a container like form using form.controls.add(myControl), how could I reference it For example dim aControl as new butto me.controls.add(aControl ...
2
by: Steve Harclerode | last post by:
Hi all, I've been doing web service development for a year, with a break for the last few months. What I remember is how easy it is to reference a web service using Visual Studio. So today, I...
1
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have...
1
by: Quentin Huo | last post by:
Hi: I programmingly created a TextBox control, as: TextBox tbPublisher = new TextBox(); tbPublisher.ID="thepublisher"; tbPublisher.Text="Quentin";
2
by: Quentin Huo | last post by:
Hi: Some of my controls (e.g. TextBox, DropDownList, ...) are created programmingly, so I have to check if a certain control exists, like: if the TextBox control exists, get it value. else...
0
by: Nikhil Patel | last post by:
Hi all, I am having a problem adding a reference in an ASP.Net project. I have written a custom control using a Web Control Library project. I compiled this project and generated a dll. Now...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
1
by: Rob R. Ainscough | last post by:
This is definitely a major weak spot in VS 2005 .NET development. It was a big problem in VS 2003 and apparently has carried over to VS 2005. It really should NOT be this complicated (it wasn't...
2
by: sravan_reddy001 | last post by:
I created a tabcontrol toolin my application.(actually i am creating a tabbed browser) when the user clicks on the newtab button(provided by me) the new tab is added and the webbrowser control...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...

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.