473,327 Members | 1,920 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,327 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 3312

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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.