VB.Net/GUI/Drag Move — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:43, 26 мая 2010
Drag to move a Component inside a Container
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1
Application.Run(form1)
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents lblDragger As System.Windows.Forms.Label
"Required by the Windows Form Designer
Private components As System.ruponentModel.Container
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lblDragger = New System.Windows.Forms.Label()
Me.SuspendLayout()
"
"lblDragger
"
Me.lblDragger.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblDragger.Image = New Bitmap("figure2.bmp")
Me.lblDragger.Location = New System.Drawing.Point(40, 40)
Me.lblDragger.Name = "lblDragger"
Me.lblDragger.Size = New System.Drawing.Size(72, 56)
Me.lblDragger.TabIndex = 1
"
"FakeDragAndDrop
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(232, 162)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblDragger})
Me.Name = "FakeDragAndDrop"
Me.Text = "Fake Drag And Drop"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub cmdDragger_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private IsDragging As Boolean = False
Private ClickOffsetX, ClickOffsetY As Integer
Private Sub lblDragger_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblDragger.MouseDown
IsDragging = True
ClickOffsetX = e.X
ClickOffsetY = e.Y
End Sub
Private Sub lblDragger_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblDragger.MouseUp
IsDragging = False
End Sub
Private Sub lblDragger_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblDragger.MouseMove
If IsDragging = True Then
lblDragger.Left = e.X + lblDragger.Left - ClickOffsetX
lblDragger.Top = e.Y + lblDragger.Top - ClickOffsetY
End If
End Sub
End Class