Click here to Skip to main content
15,902,029 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
create button dynamically and place in specific position inside the form. when the form load already created button also should retrieve and visible .
Posted
Updated 23-Aug-12 8:57am
v2
Comments
[no name] 23-Aug-12 9:36am    
do you mean programmatically ?
[no name] 23-Aug-12 9:37am    
Was there a question mixed in here anywhere?
ZurdoDev 23-Aug-12 9:38am    
How far have you gotten?

C#
button btn = new Button();
btn.Location = new System.Drawing.Point(this.width-10, this.height-10);
this.controls.add(btn);
btn.BringToFront();

Happy Coding!
:)
 
Share this answer
 
Comments
ridoy 23-Aug-12 15:01pm    
this is good one.
Aarti Meswania 24-Aug-12 0:11am    
thank you! :)
Create a button
C#
Button btnOlder = new Button();

Set the position of the Button.
C#
btnOlder.Location = new System.Drawing.Point(X-Axis, Y-Axis);
 
Share this answer
 
v2
Try this...

Button btn = new Button();
btn.Name = "btn_1";
btn.Top = 50;//specify the top position
btn.Left = 50;
btn.Width = 200;
btn.Height = 200;
//btn.Location = new System.Drawing.Point(50, 50); //alternative solution
btn.Text = "Button Created Dynamically"
this.Controls.Add(btn);
btn.BringToFront();


Hope this helps.
cheers
 
Share this answer
 
Comments
Umapathi K 25-Aug-12 1:49am    
from database i getting value from 100,101,102.... 210 ., according to this i have to create buttons dynamically text of button is no's which i mentioned above
Sandip.Nascar 25-Aug-12 4:32am    
okay, then you make a loop and create button in each loop.
So, lets you get 100,101, 102.....

Here is the code
string str = "100,101,102,103,109,112";
string[] arrStr = str.Split(',');
int spacecount=10;
foreach (string s in arrStr)
{
if (s != string.Empty)
{
Button btn = new Button();
btn.Name = "btn_1";
btn.Text = s;//here you specify the button text
btn.Top = 50 + spacecount;//specify the top position
btn.Left = 50;
btn.Width = 200;
btn.Height = 200;
this.Controls.Add(btn);
btn.BringToFront();
}
}

cheers
Sandip.Nascar 25-Aug-12 4:33am    
in the code above, just make the height of the button less than spacecount.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900