我编写了一些代码来在“拖动模式”下拖动表单上的任何文本框并调整其大小这是发生了什么的 gif,而不是文本框正确拖动,
代码:
#Region "Texbox Dragging"
Private txt As TextBox
Private txtptX, txtptY As Integer
Private txtdrag As Boolean
Private txtresize As Boolean
Private Sub txt_MouseLeave(sender As Object, e As EventArgs)
Me.Cursor = Cursors.Arrow
End Sub
Private Sub txt_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If DragMode = True Then
If e.Button = MouseButtons.Left Then
txtdrag = True
txtresize = True
txt = CType(sender, TextBox)
txtptX = e.X : txtptY = e.Y
End If
End If
End Sub
Private Sub txt_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If txtdrag = True Then
txt.Location = New Point(txt.Location.X + e.X - txtptX, txt.Location.Y + e.Y - txtptY)
Me.Refresh()
txtdrag = True
End If
If txtresize = True Then
txtdrag = False
If txt.Cursor = Cursors.Cross Then
txt.Width = e.X
txt.Height = e.Y
Else
If e.X >= txt.Width - 10 Then
txt.Cursor = Cursors.Cross
Else
txt.Cursor = Cursors.IBeam
End If
If e.Y >= txt.Height - 10 Then
txt.Cursor = Cursors.Cross
Else
txt.Cursor = Cursors.IBeam
End If
End If
End If
End Sub
Private Sub txt_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
txt = CType(sender, TextBox)
If txt.Cursor = Cursors.Cross Then
txt.Cursor = Cursors.IBeam
End If
txtdrag = False
txtresize = False
End Sub
#End Region
我为自己是一个凌乱的编码员而道歉,但这是关于第 12 次尝试,我正在尽一切努力让它发挥作用......
- 它们都可以独立工作,但是我遇到了这个奇怪的错误,当它们在一起时我只能拖动 0.25 秒...