Actually what i succeeded to code is this:
Public Class Form3
Dim mouseclikresization As Boolean = False
' Class variable that handles all instances of Label control.
Private newLabel As System.Windows.Forms.Label
' Class members to control dragging behavior.
Private dragNow As Boolean
Private mouseLocation As Point
Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Form2.Show()
' Not dragging now.
dragNow = False
'Setting up the Form canvas.
Me.Size = New Size(1024, 768)
Me.Button1.SetBounds(794, 688, 200, 25)
Me.Button1.Text = "&Cliccami per instanziare e spostare nuove label."
End Sub
' You click this button to instantiate a new Label control and set initial properties.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
mouseclikresization = False
' Instantiate and set properties.
Me.newLabel = New System.Windows.Forms.Label()
Me.newLabel.Location = New System.Drawing.Point(100, 100)
Me.newLabel.Name = "newLabel"
Me.newLabel.Text = " "
Me.newLabel.Size = New Size(8, 8)
Me.newLabel.BorderStyle = BorderStyle.FixedSingle
' Add generic handlers to handle these three mouse events.
AddHandler Me.newLabel.MouseDown, AddressOf Label_GenericMouseDown
AddHandler Me.newLabel.MouseMove, AddressOf Label_GenericMouseMove
AddHandler Me.newLabel.MouseUp, AddressOf Label_GenericMouseUp
' Add label to Form's control collection.
Me.Controls.Add(Me.newLabel)
End Sub
' Handles generic MouseDown event for labels.
Private Sub Label_GenericMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
' Mr. Label, if left mouse button is down then get ready to be dragged.
If e.Button = Windows.Forms.MouseButtons.Left Then
dragNow = True
mouseLocation = e.Location
End If
End Sub
' Handles generic MouseMove event for labels.
Private Sub Label_GenericMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If (dragNow = True) Then
' This little equation do the actual job.
CType(sender, Label).Location -= mouseLocation - e.Location
End If
End Sub
' Handles generic MouseUp event for labels.
Private Sub Label_GenericMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
' Now you can relax Mr. Label. Dragging is over now.
If dragNow = True Then dragNow = False
End Sub
'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
dragNow = False
End Sub
End Class
and in another form i coded this:
Public Class Form2
Dim mouseclikresization As Boolean = False
Private Sub newLabel_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles newLabel.MouseMove
If mouseclikresization = True Then
newLabel.Width = e.X
Else
If e.X >= newLabel.Width - 3 Then
newLabel.Cursor = Cursors.Cross
Else
newLabel.Cursor = Me.Cursor
End If
End If
If mouseclikresization = True Then
newLabel.Height = e.Y
Else
If e.Y >= newLabel.Height - 3 Then
newLabel.Cursor = Cursors.Cross
Else
newLabel.Cursor = Me.Cursor
End If
End If
End Sub
Private Sub newLabel_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles newLabel.MouseDown
mouseclikresization = True
newLabel.Cursor = Cursors.Cross
End Sub
Private Sub newLabel_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles newLabel.MouseUp
mouseclikresization = False
newLabel.Cursor = Me.Cursor
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
now i should merge them, but when i copy the second piece to the first form i am said that the newLabel variable is not valid.....why?
Andrea.