在C#中实现标签(Label)随鼠标移动而移动
2010-03-17 09:46
555 查看
文档及代码下载:http://www.dingos.cn/index.php?topic=1420.0
1. 定义一个Point对象mouse_offset,用于保存鼠标的位置
2. 对标签(Label)添加MouseDown事件,记录当前鼠标所在的位置为实例化mouse_offset对象
view plaincopy to clipboardprint?
private void lblMove_MouseDown(object sender, MouseEventArgs e) {
mouse_offset = new Point(-e.X, -e.Y);
}
3. 对标签(Label)添加MouseMove事件,实现标签(Label)随鼠标的移动而移动
view plaincopy to clipboardprint?
private void lblMove_MouseMove(object sender, MouseEventArgs e) {
if(e.Button == MouseButtons.Left) {
Point mousePos = Control.MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
((Control)sender).Location =
((Control)sender).Parent.PointToClient(mousePos);
}
}
1. 定义一个Point对象mouse_offset,用于保存鼠标的位置
2. 对标签(Label)添加MouseDown事件,记录当前鼠标所在的位置为实例化mouse_offset对象
view plaincopy to clipboardprint?
private void lblMove_MouseDown(object sender, MouseEventArgs e) {
mouse_offset = new Point(-e.X, -e.Y);
}
3. 对标签(Label)添加MouseMove事件,实现标签(Label)随鼠标的移动而移动
view plaincopy to clipboardprint?
private void lblMove_MouseMove(object sender, MouseEventArgs e) {
if(e.Button == MouseButtons.Left) {
Point mousePos = Control.MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
((Control)sender).Location =
((Control)sender).Parent.PointToClient(mousePos);
}
}
相关文章推荐
- 在MFC中,想要实现当鼠标移动到某个标签中的时候鼠标变成超链接时候的“手”状
- c#打印预览控件中实现用鼠标移动页面功能代码分享
- C#利用Label标签控件模拟窗体标题的移动及窗体颜色不断变换效果
- C#实现鼠标移动到曲线图上显示值的方法
- JSP输入框空验证:利用onblur标签实现的移动鼠标时的验证
- c#实现随鼠标移动窗体
- C#中用鼠标移动页面功能的实现
- 鼠标移动实现标签自动切换
- C#实现随鼠标移动窗体实例
- [C#]使用Label标签控件模拟窗体标题的移动及窗体颜色不断变换
- 标签(Label)随鼠标移动而移动
- C#如何实现标题栏随鼠标移动的效果?
- C#中用鼠标移动页面功能的实现
- c#实现随鼠标移动窗体
- C#中用鼠标移动页面功能的实现
- C#中用鼠标移动页面功能的实现
- c#实现随鼠标移动窗体
- c#实现随鼠标移动窗体
- qt 实现label部件中的图片随鼠标移动
- C# winform 中实现label字体移动