欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

C#如何绑定多个按钮到同一个事件

时间:2023-02-02 10:13:01|栏目:.NET代码|点击:

绑定多个按钮到同一个事件

1.添加代码

private void clauseElementClicked(object sender, EventArgs e)
{undefined
textBoxWhereClause.SelectedText = ((Button)sender).Text;
}

2.选择你要添加代码的控件

右键–属性–找到click这个事件,让后选择clauseElementClicked这个事件就可以了。 

 多个控件有同一个事件,优化

先自己声明方法,再用事件调用

public void borderS3D(object sender,EventArgs e)
        {
               ((PictureBox)sender).BorderStyle=BorderStyle.Fixed3D;         
        } public void borderSNo(object sender, EventArgs e)
        {
            ((PictureBox)sender).BorderStyle = BorderStyle.None;
        }
public FormMain()
        {
            InitializeComponent();
            pictureBox1.MouseHover += new  EventHandler(borderS3D);
            pictureBox1.MouseLeave += new EventHandler(borderSNo);
            pictureBox2.MouseHover += new EventHandler(borderS3D);
            pictureBox2.MouseLeave += new EventHandler(borderSNo);
            pictureBox3.MouseHover += new EventHandler(borderS3D);
            pictureBox3.MouseLeave += new EventHandler(borderSNo);
            pictureBox4.MouseHover += new EventHandler(borderS3D);
            pictureBox4.MouseLeave += new EventHandler(borderSNo);
            pictureBox5.MouseHover += new EventHandler(borderS3D);
            pictureBox5.MouseLeave += new EventHandler(borderSNo);
            pictureBox6.MouseHover += new EventHandler(borderS3D);
            pictureBox6.MouseLeave += new EventHandler(borderSNo);
            pictureBox7.MouseHover += new EventHandler(borderS3D);
            pictureBox7.MouseLeave += new EventHandler(borderSNo);
            pictureBox8.MouseHover += new EventHandler(borderS3D);
            pictureBox8.MouseLeave += new EventHandler(borderSNo);
            pictureBox9.MouseHover += new EventHandler(borderS3D);
            pictureBox9.MouseLeave += new EventHandler(borderSNo);
            pictureBox10.MouseHover += new EventHandler(borderS3D);
            pictureBox10.MouseLeave += new EventHandler(borderSNo);
            pictureBox11.MouseHover += new EventHandler(borderS3D);
            pictureBox11.MouseLeave += new EventHandler(borderSNo);
           
        }

上一篇:ASP.NET MVC从控制器中获取URL值

栏    目:.NET代码

下一篇:没有了

本文标题:C#如何绑定多个按钮到同一个事件

本文地址:http://www.codeinn.net/misctech/224942.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有