动态创建按钮并单击事件!

编程入门 行业动态 更新时间:2024-10-17 23:36:23
本文介绍了动态创建按钮并单击事件!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个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) { }

更多推荐

动态创建按钮并单击事件!

本文发布于:2023-11-02 14:20:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   按钮   事件   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!