private Button b;
private Point location;
private void button1_MouseDown(object sender, MouseEventArgs e)
{
location = e.Location;
b = sender as Button;
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
int pos_x, pos_y;
if (e.Button == MouseButtons.Left)
{
pos_x = b.Location.X + (e.X - location.X);
pos_y = b.Location.Y + (e.Y - location.Y);
b.Location = new Point(pos_x, pos_y);
}
}
C#创建可拖动按钮
最新推荐文章于 2025-07-10 12:37:41 发布
本文介绍了一个使用 C# 编写的简单示例程序,演示了如何通过鼠标操作来改变界面上按钮的位置。具体实现包括捕获鼠标点击事件并记录初始位置,然后在鼠标移动时更新按钮的位置。
312

被折叠的 条评论
为什么被折叠?



