473,387 Members | 1,790 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,387 software developers and data experts.

Create button control at runtime

This one should be easy ;)
How can I create a button control at runtime using one that is already
created and adjust the properties ?

Thanks in advance

Dec 15 '06 #1
4 3314

WebNewsReader wrote:
This one should be easy ;)
How can I create a button control at runtime using one that is already
created and adjust the properties ?

Thanks in advance
So you want a clone of an existing button, then change one or two
things?

Well, just creating a new button is easy:

Dim b as new system.windows.forms.form.Button

I don't think buttons have a clone method, so you could make a
ClonableButton by defining a new class tha inherits Button and
implements ICloneable.
Or just set the properties you want (for quick and dirty solution):
b.property1 = oldButton.property1
b.property2 = oldButton.property2
....

Dec 15 '06 #2
ok, that fixes my needs
but there is a way to create using an array ?

<lo*********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
>
WebNewsReader wrote:
>This one should be easy ;)
How can I create a button control at runtime using one that is already
created and adjust the properties ?

Thanks in advance

So you want a clone of an existing button, then change one or two
things?

Well, just creating a new button is easy:

Dim b as new system.windows.forms.form.Button

I don't think buttons have a clone method, so you could make a
ClonableButton by defining a new class tha inherits Button and
implements ICloneable.
Or just set the properties you want (for quick and dirty solution):
b.property1 = oldButton.property1
b.property2 = oldButton.property2
...
Dec 15 '06 #3

WebNewsReader wrote:
ok, that fixes my needs
but there is a way to create using an array ?
So now you want an array filled with buttons, huh? Ok!

You can try this:
dim btnArray as new ArrayList(10) 'estimate the capacity you'll need. I
guessed at "10".
there are other structures you can use, such as a generic list.

then you can add buttons like this:
dim myButton as new Button
btnArray.add(myButton)

and loop through the array like this:
for each btn as Button in btnArray
...
'some code goes in here
next

Dec 15 '06 #4


<lo*********@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
>
WebNewsReader wrote:
>ok, that fixes my needs
but there is a way to create using an array ?

So now you want an array filled with buttons, huh? Ok!

You can try this:
dim btnArray as new ArrayList(10) 'estimate the capacity you'll need. I
guessed at "10".
there are other structures you can use, such as a generic list.

then you can add buttons like this:
dim myButton as new Button
btnArray.add(myButton)

and loop through the array like this:
for each btn as Button in btnArray
...
'some code goes in here
next
Hmm, if the number of buttons are known at compile-time, or even at runtime
prior to creating the buttons, I would use an array rather than arraylist.
But if the total number of buttons are unknown until they are all created,
then using an ArrayList or List would be the way to go (I'm unfamiliar with
the List<generic class, so you may also want to look into this as it may
be just as efficient as using a normal array, but I'm not sure)...

HTH,
Mythran
Dec 15 '06 #5

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

Similar topics

5
by: Patrick Marti | last post by:
I wish to create some LinkButtons in DotNet. Because I will do it in dependence of the entries in a database, I can not add them with the mouse to the form as usually. I can create them in the...
3
by: leon | last post by:
hello friends, i am writing a page aspx and creating controls dinamicaly and then i must to create for each control the events as well. Anybody to know how????? happy day lion
8
by: frankcvc | last post by:
I created a control array at runtime using the following code. I also wanted to code the controlarray click event. My code can respond to click event but cannot identify the specific control...
4
by: Dale Levesque | last post by:
I get this message. any ideas?? See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text **************...
7
by: Matt | last post by:
Hi all, I'm trying to create a system where it reads a number of records from a database and then creates a row in the GUI that contains a single field from the database and a button that has a...
1
by: amitsaxena1981 | last post by:
Hi, I am using asp.net with vb.net and creating the user control .My user control generate the table at runtime in which each column has button so i want to create the event handler for each run...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
3
by: chandan | last post by:
Hi, Is any way to palce a control(button/label) at a location on webPage in runtime?? In page_load envet I am adding a button on the page in the contol collection of a panel but not able to...
0
by: Brian Roisentul | last post by:
Hi All, I want to programmatically(c# fmw 2.0) create a folder under my IIS Web Site. I figured that I needed to create an entry in the IIS Metabase. So, after investigating a while and i...
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?
0
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,...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.