Skip to main content
Email Password   helpLost your password?

Introduction

These 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
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralWidth and Height, both are resizeable. Pin
Krrrishna
6:50 19 Jun '06  
Generalcode in c#, Pin
acharyakrishna1978@yahoo.com
21:43 25 May '06  
GeneralAll I can say is nice! Pin
Khookie
4:10 4 Feb '06  


Last Updated 17 Apr 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009