vb.net中label控件拖放问题

anging 2010-10-30 12:17:55
请教一下 在form窗体中有3个label控件,现在要实现它的拖放
原来排序 1 2 3 4
拖放后 3 1 2 4
或 2 4 1 3
把label3拖放label1的位置后 label3排在第一 label1 label2 label4自动排到他的后面
或把label2拖放label1的位置后 label4拖在第二 label1 label3 自动排到他的后面
如何实现?
...全文
132 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tosp2012 2010-10-31
  • 打赏
  • 举报
回复
看看这个.

Dim flag As Boolean = True

Private Sub Label3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label3.MouseDown
If flag Then
flag = False
Dim x As Integer
Dim y As Integer
x = Label3.Left
y = Label3.Top

Label3.Left = Label1.Left
Label3.Top = Label1.Top

Label1.Left = Label2.Left
Label2.Top = Label1.Top

Label2.Left = x
Label2.Top = y

End If

End Sub

Private Sub Label2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseDown
If flag Then
flag = False
Dim x As Integer
Dim y As Integer

x = Label2.Left
y = Label2.Top

Label2.Left = Label1.Left
Label2.Top = Label1.Top

Label1.Left = Label3.Left
Label1.Top = Label3.Top

Label3.Left = Label4.Left
Label3.Top = Label4.Top

Label4.Left = x
Label4.Top = y



End If
anging 2010-10-31
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]

Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
If draging = False Then……
[/Quote]


里面的那些变量如何定义呢?
anging 2010-10-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 tosp2012 的回复:]

看看这个.

Dim flag As Boolean = True

Private Sub Label3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label3.MouseDown
If flag Then
……
[/Quote]


这段代码只能进行他的水平排列
anging 2010-10-30
  • 打赏
  • 举报
回复
4个label控件
请教一下 在form窗体中有4个label控件,现在要实现它的拖放
原来排序 1 2 3 4
拖放后 3 1 2 4
或 2 4 1 3
把label3拖放label1的位置后 label3排在第一 label1 label2 label4自动排到他的后面
或把label2拖放label1的位置后 label4拖在第二 label1 label3 自动排到他的后面
如何实现?
wuyq11 2010-10-30
  • 打赏
  • 举报
回复
Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
If draging = False Then
draging = True
MousePos2 = New Point(MousePosition.X - Left - Button2.Left, MousePosition.Y - Top - Button2.Top)
MakeRect()
End If
End Sub

Private Sub MakeRect()
DragRect = New Rectangle(Left + MousePos2.X, Top + MousePos2.Y, Width - Button2.Width, Height - Button2.Height - TitleHeight)
End Sub

Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
If draging Then
If MousePosition.X < DragRect.Left Then
Button2.Left = 0
ElseIf MousePosition.X > DragRect.Right Then
Button2.Left = Me.Width - Button2.Width
Else
Button2.Left = MousePosition.X - Left - MousePos2.X
End If

If MousePosition.Y < DragRect.Top Then
Button2.Top = 0
ElseIf MousePosition.Y > DragRect.Bottom Then
Button2.Top = Height - Button2.Height - TitleHeight
Else
Button2.Top = MousePosition.Y - Top - MousePos2.Y
End If
End If
End Sub

Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp
draging = False
End Sub
http://msdn.microsoft.com/zh-cn/za0zx9y0(VS.80).aspx
jieon 2010-10-30
  • 打赏
  • 举报
回复
http://hi.baidu.com/xiazhenlai/blog/item/19e7674c9f71c3f1d72afcc3.html
这是拖动的,拖动排放算好控件Location值就行。
兔子-顾问 2010-10-30
  • 打赏
  • 举报
回复
控件的拖放可以参考我这个文章
http://blog.csdn.net/wuyazhe/archive/2010/06/23/5690116.aspx
是c#写的,你可以用下面网址翻译
http://www.developerfusion.com/tools/convert/csharp-to-vb/
拖动实现了,松开鼠标的时候,你在事件中处理一下几个label的位置代码不用写了,你会的把,仔细点,设置好left,height或是Location属性就可以了。

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧