本文介绍了动态创建按钮并单击事件!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个win表单应用程序,我需要在运行时制作按钮 这是我正在做的代码
I am creating a win form application in which i need to make button at run-time this is code how i am doing
Button button1= new Button(); panel1.Controls.Add(button1); button1.Location=new Point(220,457); button1.Name="btnnextimage11"; button1.Size=new Size(118, 39); button1.Text = "Next Image"; button1.UseVisualStyleBackColor = true; button1.Click += new System.EventHandler(button1_Click); private void button1_click(object sender, EventArgs e) { }推荐答案
C#区分大小写 - 重命名您的功能从 button1_click 到 button1_Click C# is case sensitive - rename your function from button1_click to button1_Click
非常感谢您的帮助: ) 我发布我的最终代码以动态创建一个Button和相关的东西 Thanks a lot to helping hands :) I am posting my final code to create a Button dynamically and related stuff too { Button button1= new Button(); button1.Location=new Point(220,457); button1.Name="button1"; button1.Size=new Size(118, 39); button1.Text = "Click This button "; button1.UseVisualStyleBackColor = true; button1.Click += new EventHandler(button1_Click); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show(" I am button1 , you just clicked me "); }
你已经创建了一个按钮, 现在在代码下面会将button1添加到表单中
you have created a button, now below code will add the button1 to the form
Controls.Add(button1);或者如果你想要你可以添加button1到panel1
or if you want you can add the button1 to the panel1
panel1.Controls.Add(button9);
这将对您有所帮助。 ... C#区分大小写,语言查看您的活动 This Will help you....C# is case sensitive, language check your event Button btn = new Button(); btn.Click += new EventHandler(btn_Click); private void btn_Click(object sender, EventArgs e) { }
更多推荐
动态创建按钮并单击事件!
发布评论