運(yùn)行時拉伸與移動控件的類
發(fā)表時間:2024-06-11 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
Public Class Resize
'移動了嗎?
Private IsMoving As Boolean = False
'控件最后的寬
Private ctrlLastWidth As Integer = 0
'控件最后的高
Private ctrlLastHeight As Integer = 0
'控件原來的寬
Private ctrlWidth As Integer
'最后的左側(cè)坐標(biāo)
Private ctrlLastLeft As Integer
'最后的頂部坐標(biāo)
Private ctrlLastTop As Integer
'控件原來的高
Private ctrlHeight As Integer
'控件的左側(cè)坐標(biāo)
Private ctrlLeft As Integer
'控件的頂部坐標(biāo)
Private ctrlTop As Integer
'光標(biāo)的左側(cè)坐標(biāo)
Private cursorL As Integer
'光標(biāo)的頂部坐標(biāo)
Private cursorT As Integer
'
Private Htap As Integer
Private Wtap As Integer
Private ctrlIsResizing As Boolean = False
'控件的大小矩形
Private ctrlRectangle As System.Drawing.Rectangle = New System.Drawing.Rectangle()
Private ctrl As Control '操作的控件
Private frm As Form '控件的父親窗體
'構(gòu)造函數(shù)
Public Sub New(ByVal c As Control, ByVal frm As Form)
ctrl = c
Me.frm = frm
'標(biāo)題欄和橫向滾動條以及邊框的寬
Me.Htap = Me.frm.Height - Me.frm.ClientRectangle.Height
'縱向滾動條和邊框的寬
Me.Wtap = Me.frm.Width - Me.frm.ClientRectangle.Width
AddHandler ctrl.MouseDown, AddressOf MouseDown
AddHandler ctrl.MouseMove, AddressOf MouseMove
AddHandler ctrl.MouseUp, AddressOf MouseUp
End Sub
'鼠標(biāo)按下后的處理
Private Sub MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
If frm Is Nothing Then
Return
End If
MessageBox.Show(e.Y.ToString)
MessageBox.Show((Me.ctrl.Height - 10).ToString)
MessageBox.Show(e.X.ToString)
MessageBox.Show((Me.ctrl.Width - 10).ToString)
'設(shè)置第一次有效單擊的范圍
If e.X < Me.ctrl.Width - 10 OrElse e.Y < Me.ctrl.Height - 10 Then
Me.IsMoving = True
'指定要繪制的虛線框的坐標(biāo)(相對屏幕)
Me.ctrlLeft = Me.frm.DesktopLocation.X + Me.Wtap + Me.ctrl.Left
Me.ctrlTop = Me.frm.DesktopLocation.Y + Me.Htap + Me.ctrl.Top