Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
cannot create a button programmatically using visual studio C# windows form but no response here is my code below
C#
Button btn = new Button();
btn.Name = "Btn";
btn.Size = new Size(50, 20);
btn.Text = "Browse-";
btn.Location = new Point(115, 173);
btn.Click += new EventHandler(btn_Click);
Posted
Updated 4-Jul-14 17:52pm
v2

1 solution

You did not add this button to anything in your UI. The missing piece is something like
C#
btn.Parent = someParentControl; // such as Panel or Form

// same as:
sameParentControl.Controls.Add(btn);


—SA
 
Share this answer
 
Comments
zakirox123 4-Jul-14 21:47pm    
thank you Sergey Alexandrovich problem solved ;) Controls.Add(btn);
Sergey Alexandrovich Kryukov 4-Jul-14 22:32pm    
My pleasure.
Good luck, call again.
—SA

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