本文介绍了如何在标签箱内移动标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我写这段代码来移动label1,我创建int x和y来取得label1的新位置,它正常工作。 我的问题是我创建了图片框,我将label1放在图片框的左上角位置,我希望label1在图片框内移动而不是在图片的任何地方。 private void label1_MouseDown( object sender,MouseEventArgs e) { if (e.Button == MouseButtons .Left) { _Offset = new Point(eX,eY); } } private void label1_MouseUp( object sender,MouseEventArgs e) { _Offset = Point.Empty; } private void label1_MouseMove( object sender,MouseEventArgs e) { if (_ Offset!= Point.Empty) { Point newlocation = label1.Location; newlocation.X + = e.X - _Offset.X; newlocation.Y + = e.Y - _Offset.Y; label1.Location = newlocation; x = newlocation.X; y = newlocation.Y; } label3.Text = x.ToString(); label4.Text = y.ToString(); } 关心所有。解决方案 你完全错了。 我写了一篇关于这几年前的文章。 创建自己的运行时可移动Windows窗体控件 [ ^ Hi all,I write this code to move the label1 and i create int x and y to take the new position of the label1 and it works correctly.My problem that I create picturebox and I place label1 in the top left position inside the picturebox and I want label1 to move just inside the picturebox not in anywhere in the form.private void label1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { _Offset = new Point(e.X, e.Y); } } private void label1_MouseUp(object sender, MouseEventArgs e) { _Offset = Point.Empty; } private void label1_MouseMove(object sender, MouseEventArgs e) { if (_Offset != Point.Empty) { Point newlocation = label1.Location; newlocation.X += e.X - _Offset.X; newlocation.Y += e.Y - _Offset.Y; label1.Location = newlocation; x = newlocation.X; y = newlocation.Y; } label3.Text = x.ToString(); label4.Text = y.ToString(); }Regards all. 解决方案 You're doing it entirely wrong.I wrote an article on doing exactly this years ago. Create your Own Runtime Movable Windows Forms Controls[^] 这篇关于如何在标签箱内移动标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-15 23:01