学院首页>网络编程>ASP.NET>运行时拉伸和移动控件的类

运行时拉伸和移动控件的类

作者: 来源: 添加时间:2006-5-21 19:56:42
   '光标的位置

   Me.cursorL = Cursor.Position.X

   Me.cursorT = Cursor.Position.Y

   '控件的原来宽与高

   Me.ctrlWidth = Me.ctrl.Width

   Me.ctrlHeight = Me.ctrl.Height

  End If

  ctrlRectangle.Location = New System.Drawing.Point(Me.ctrlLeft, Me.ctrlTop)

  ctrlRectangle.Size = New System.Drawing.Size(ctrlWidth, ctrlHeight)

  '绘制框架(矩形大小,背景色,边框风格(这里是虚线框))

  ControlPaint.DrawReversibleFrame(ctrlRectangle, Color.Empty, System.Windows.Forms.FrameStyle.Dashed)

End Sub

Private Sub MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)

  If frm Is Nothing Then

   Return

  End If

  '如果是鼠标左键

  If e.Button = MouseButtons.Left Then

   If Me.IsMoving Then

'

If ctrlLastLeft = 0 Then

  ctrlLastLeft = ctrlLeft

End If

'

If ctrlLastTop = 0 Then

  ctrlLastTop = ctrlTop

End If

Dim locationX As Integer = (Cursor.Position.X - Me.cursorL + Me.frm.DesktopLocation.X + Me.Wtap + Me.ctrl.Location.X)

Dim locationY As Integer = (Cursor.Position.Y - Me.cursorT + Me.frm.DesktopLocation.Y + Me.Htap + Me.ctrl.Location.Y)

If locationX < Me.frm.DesktopLocation.X + Me.Wtap Then

  locationX = Me.frm.DesktopLocation.X + Me.Wtap

End If

If locationY < Me.frm.DesktopLocation.Y + Me.Htap Then

  locationY = Me.frm.DesktopLocation.Y + Me.Htap

End If

Me.ctrlLeft = locationX

Me.ctrlTop = locationY

ctrlRectangle.Location = New System.Drawing.Point(Me.ctrlLastLeft, Me.ctrlLastTop)

ctrlRectangle.Size = New System.Drawing.Size(ctrlWidth, ctrlHeight)

ControlPaint.DrawReversibleFrame(ctrlRectangle, Color.Empty, System.Windows.Forms.FrameStyle.Dashed)

ctrlLastLeft = ctrlLeft

ctrlLastTop = ctrlTop

ctrlRectangle.Location = New System.Drawing.Point(ctrlLeft, ctrlTop)

ctrlRectangle.Size = New System.Drawing.Size(ctrlWidth, ctrlHeight)

ControlPaint.DrawReversibleFrame(ctrlRectangle, Color.Empty, System.Windows.Forms.FrameStyle.Dashed)

Return

   End If

   Dim sizeageX As Integer = (Cursor.Position.X - Me.frm.DesktopLocation.X - Me.Wtap - Me.ctrl.Location.X)

   Dim sizeageY As Integer = (Cursor.Position.Y - Me.frm.DesktopLocation.Y - Me.Htap - Me.ctrl.Location.Y)

   If sizeageX < 2 Then

sizeageX = 1

   End If

   If sizeageY < 2 Then

sizeageY = 1

   End If

   ctrlWidth = sizeageX

   ctrlHeight = sizeageY

   If ctrlLastWidth = 0 Then

ctrlLastWidth = ctrlWidth

   End If

   If ctrlLastHeight = 0 Then

ctrlLastHeight = ctrlHeight

   End If

   If ctrlIsResizing Then

ctrlRectangle.Location = New System.Drawing.Point(Me.frm.DesktopLocation.X + Me.ctrl.Left + Me.Wtap, Me.frm.DesktopLocation.Y + Me.Htap + Me.ctrl.Top)

ctrlRectangle.Size = New System.Drawing.Size(ctrlLastWidth, ctrlLastHeight)

   End If

   ctrlIsResizing = True

   ControlPaint.DrawReversibleFrame(ctrlRectangle, Color.Empty, System.Windows.Forms.FrameStyle.Dashed)

   ctrlLastWidth = ctrlWidth

   ctrlLastHeight = ctrlHeight

   ctrlRectangle.Location = New System.Drawing.Point(Me.frm.DesktopLocation.X + Me.Wtap + Me.ctrl.Left, Me.frm.DesktopLocation.Y + Me.Htap + Me.ctrl.Top)

   ctrlRectangle.Size = New System.Drawing.Size(ctrlWidth, ctrlHeight)

   ControlPaint.DrawReversibleFrame(ctrlRectangle, Color.Empty, System.Windows.Forms.FrameStyle.Dashed)

  End If

End Sub

第 2 页,共 3 页 [1] [2] [3]
站内搜索