|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionThese simple bits of code will show you how to allow your users to resize a label at runtime. Simple paste this code into an empty form (below the windows generated stuff) and draw a label (called Label1) anywhere onto the form. Run the program and notice the cursor change when your mouse is over the right side of the label. Click and drag and watch the label resize. This can be used for almost any control and the code can be easily changed to allow width resizing as well. Dim _mouseDown as boolean = false
Private Sub Label1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If _mouseDown = True Then
Label1.Width = e.X
Else
If e.X >= Label1.Width - 3 Then
Label1.Cursor = Cursors.VSplit
Else
Label1.Cursor = Me.Cursor
End If
End If
End Sub
Private Sub Label1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
_mouseDown = True
Label1.Cursor = Cursors.VSplit
End Sub
Private Sub Label1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
_mouseDown = False
Label1.Cursor = Me.Cursor
End Sub
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||