473,387 Members | 1,892 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.

Help on dinamic button creation

6
I guess what I have to do is quite simple, but I'm really stuck!
I need to create, in a form, a particular number "i" of "Button"s (i is given at runtime), whose reference name should be "button1","button2", ...
I mean something like: Button button1 = new System.Windows.Forms.Button(); ...
So I tried with a "for" looping i times, ech time to create a new Button called button; I wrote a function that, given parameter i, returns the string "button<i>".
This function is called each loop, but I can't manage to make this "button<i>" string become the reference name of the new created button, thus getting a separate object from the previous.
I hope to have been clear.
Thanx a lot in advance, for whoever'll try to help me!

Davide
//Trying desperetely to end up my thesis on time
Feb 21 '07 #1
4 1092
enreil
86
You can creat an Array or an ArrayList of Buttons and stash your buttons in there. You can write a single method to hand the click event and then associate it with each button as it is created. Note: You'll need to do this in the Page_Init method, so that everytime your page is refreshed, the buttons are recreated.

Hope that helps.
Feb 21 '07 #2
lupus
6
You can creat an Array or an ArrayList of Buttons and stash your buttons in there. You can write a single method to hand the click event and then associate it with each button as it is created. Note: You'll need to do this in the Page_Init method, so that everytime your page is refreshed, the buttons are recreated.

Hope that helps.
Thank you for the advice, I think I understood..just one thing: by Page_Init you mean the constructor of the form i'm talkin about, right?
I have a problem, then:
The form I have to create as I told u (AppWin) is called inside the main Application.Run (new StartUp), where StartUp is another form that is needed at the beginning to perform some initial operation and to decide how AppWin must be looking like.
But when I call the constructor of AppWin, how can I turn the control of the application on this form instead than on the previous one?
I mean, as how my program works by now, AppWin is created and after its constructor ends, the first form StartUp is again shown and active.
Instead, how can I have AppWin active in full screen mode so that the buttons can be clickable?

Thanx very much!!!
Feb 21 '07 #3
enreil
86
Duh, I should have read your first post more clearly. Of coures there's no Page_Init in Forms.

After you create an instance of AppWin with the constructor, use the AppWin.Show() method to display the form. When you are done using the form, use the Dispose() method.

Hope that helps.


Thank you for the advice, I think I understood..just one thing: by Page_Init you mean the constructor of the form i'm talkin about, right?
I have a problem, then:
The form I have to create as I told u (AppWin) is called inside the main Application.Run (new StartUp), where StartUp is another form that is needed at the beginning to perform some initial operation and to decide how AppWin must be looking like.
But when I call the constructor of AppWin, how can I turn the control of the application on this form instead than on the previous one?
I mean, as how my program works by now, AppWin is created and after its constructor ends, the first form StartUp is again shown and active.
Instead, how can I have AppWin active in full screen mode so that the buttons can be clickable?

Thanx very much!!!
Feb 21 '07 #4
kuzen
20
I hope I did not misunderstand you
Following is what I did in VB, seems to be working
Expand|Select|Wrap|Line Numbers
  1.  
  2. For i As Integer = 0 To 5
  3.             Dim Button As New System.Windows.Forms.Button
  4.             Me.SuspendLayout()
  5.             Button.Location = New System.Drawing.Point(112, 96 + i * 96)
  6.             Button.Name = "Button" + i.ToString
  7.             Button.TabIndex = 0
  8.             Button.Text = "Button" + i.ToString
  9.             Me.Controls.Add(Button)
  10. Next
  11.  
You definitely know you can play with the object location and size
Regards
Feb 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
4
by: raulgz | last post by:
hi I need generate dinamic sql: I need a select sentence with all fields of one table 't1' and all fields of tables which 't1' have foreings keys 't1 ( reflexive ) ,t2,t3,...' Now, l have de...
1
by: dddddd | last post by:
i need do create simple dinamic site - built mainly of pictures(they are the only dinamic part). pictuers differ by the -Location- and by -Time- (in which they were taken)... so on the index...
3
by: Jose Garcia | last post by:
Hi there, Can somebody explain me how can i use matrixes with dinamic memory? I use malloc and free (NOT new & delete). I want to access to the matrix like Matrix but i don't know how to do that...
6
by: gp | last post by:
Hi all, I'm using Microsoft Visual C++ 6.0, I would like to see, debugging my project, all the elements of my dinamic objects.... I have a dinamic array and a STL vector and I need to know...
7
by: Morgan | last post by:
I have read much posts on the argument but no one clearly says if this operation is possible or not. Simply I have a routine which reads from a text file some integer arrays (1 or 2D). The...
2
by: Alessandro | last post by:
i want to create dinamicaly an image Button, but i'm not able to associate a relative server command on click, any idea ? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As...
2
by: Liqun Xu | last post by:
Hallo NG, I created a Button with Click-Event dynamically: System.Web.UI.WebControls.Button bt_1 = new Button(); bt_1.Click += new EventHandler(bt_1_click); and I implemented the Funktion...
10
by: javuchi | last post by:
I just want to share some code with you, and have some comments and improvements if you want. This header file allocates and add and delete items of any kind of data from a very fast array: ...
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...
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:
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...
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.