Click here to Skip to main content
14,384,019 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hai
i am create buttons dynamically like
Dim btn As New Button
btn.Text="ONE"
btn.Name="ONE"
btn.FlatStyle = FlatStyle.Flat
btn.BackColor = Color.Transparent
btn.Font = New Font("Segoe UI", 9.0)
btn.Font = New Font(btn.Font, FontStyle.Bold)
btn.FlatAppearance.MouseOverBackColor = Color.Transparent
btn.FlatAppearance.MouseDownBackColor = Color.Transparent
btn.Width = 60  'By default width is 60
btn.Height = 40  'By default height is 40

in above i will give default button height and width so only can see in form,after created buttons need to resize the button,i mean actually we do in visual studio design time(click button border and drag for resize)



Pls reply asap...


Regards
Aravind
Posted
Updated 21-Jan-14 19:53pm
v4
Rate this:
Please Sign up or sign in to vote.

Solution 1

btn.Size = new Size(width, height)

or
btn.Width = width
btn.Height = height


I'm assuming Windows Forms here, but you may want to read the documentation on the Button class, here[^].
   
Comments
Aravindba 22-Jan-14 0:17am
   
for width and height variable wht u give ? i think this for hardcoded height and width
width=10 and height=20 finally btn.size=new size(width, height),pls read clearlly, i will ask dynamically created button.in running time button created,example Form load event it create one button and need to click button border and drag to resize.
Ron Beyer 22-Jan-14 0:32am
   
This is different than what your question eludes to. What you are asking is runtime resizing of controls, not changing the size of dynamically created controls. See my solution.
Aravindba 22-Jan-14 0:35am
   
i am asking resize (change size) for dynamically created button in running time.
Ron Beyer 22-Jan-14 0:35am
   
+5 for answering what he asked, even though he didn't mean what he meant :)
Aravindba 22-Jan-14 0:56am
   
i am ask for resize for dynamically create button,dynamically created means running time only,not in design time,pls understand yourself.
Ron Beyer 22-Jan-14 0:57am
   
Yes, I understand, see the solution 2 I posted, it shows exactly how to do this.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Runtime Control Resizer[^]

What you are asking for is Runtime resizing, not changing dynamically created controls since the above will work for both dynamically created controls and statically made ones.
   
Comments
Aravindba 22-Jan-14 1:01am
   
thank u for ur reply,but in dynamically created button not work,i will write like this
private void Form1_Load(object sender, EventArgs e)
{
//new ResizeControl(this.button1, true);


Button btn = new Button();
btn.Name ="Aravind";
btn.Text ="Aravind";

btn.Width = 60;
btn.Height = 40;
new ResizeControl(btn, true);

}

pls check this dynamically created button.
Ron Beyer 22-Jan-14 1:04am
   
Did you add all the code from the article into your project? Resizing controls at runtime is not a simple setting, its actually quite complicated. Please thoroughly read the article I linked that includes all the extra code you need to put in place to be able to resize controls at runtime.

Again, this is not a simple property setting it requires a lot of extra code to do!
Aravindba 22-Jan-14 1:09am
   
Actually i download source file form that article,and i add dynamicall create button code in Form1_Load event,in this event only call ResizeControl class file. like new ResizeControl(this.button1, true); so same like i create dynamically button like
Button btn = new Button();
btn.Name = "Aravind";
btn.Text ="Aravind";
btn.Width = 60;
btn.Height = 40;
new ResizeControl(btn, true);
Ron Beyer 22-Jan-14 1:13am
   
You need to add your dynamic button to the controls collection, like:

Button btn = new Button();
this.Controls.Add(btn);
...

Aravindba 22-Jan-14 1:16am
   
yes,sorry i forgot it,bcz in my code first create lot of dynamically buttons at last(it take 200 lines) after that i add button to form like this.Controls.Add(btn);.
Aravindba 22-Jan-14 5:08am
   
Hai,what i need like that it work,but i already use mousemove,down,up event for button,acctually my problem is if i move button,the resize box symbol(i.e in design time if click controls ,in all border side we get small box,using that one can increase and decrease the size) still there in old place.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100