如题,做了一个在运行时可拖动的按钮,可是每次一拖动就会触发Click事件,怎样才能实现只拖动按钮而不触发Click事件,Click事件是必要的,不可省
2条回答 默认 最新
- threenewbee 2016-11-14 06:38关注
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private Point buttonlocation; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("button1"); } private void button1_MouseUp(object sender, MouseEventArgs e) { buttonlocation = e.Location; } private void button1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { this.button1.Click -= button1_Click; this.button1.Location = new Point(this.button1.Left + (e.X - buttonlocation.X), this.button1.Top + (e.Y - buttonlocation.Y)); } } private void button1_MouseDown(object sender, MouseEventArgs e) { buttonlocation = e.Location; this.button1.Click -= button1_Click; this.button1.Click += button1_Click; } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用
悬赏问题
- ¥15 eda:门禁系统设计
- ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
- ¥15 376.1电表主站通信协议下发指令全被否认问题
- ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
- ¥15 复杂网络,变滞后传递熵,FDA
- ¥20 csv格式数据集预处理及模型选择
- ¥15 部分网页页面无法显示!
- ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
- ¥15 QTOF MSE数据分析
- ¥15 平板录音机录音问题解决