Click here to Skip to main content
13,191,642 members (66,208 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 17 Apr 2004

Resizable Controls at Runtime!

, 17 Apr 2004
Rate this:
Please Sign up or sign in to vote.
This simple code will allow users to resize controls at runtime.


These simple bits of code will show you how to allow your users to resize a Label at runtime. Simply paste this code into an empty form (below the Windows generated stuff) and draw a Label (called Label1) anywhere on 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

      If e.X >= Label1.Width - 3 Then
         Label1.Cursor = Cursors.VSplit
         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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Canada Canada
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Heaven20203-Nov-10 6:57
memberHeaven20203-Nov-10 6:57 
good way
GeneralWidth and Height, both are resizeable. Pin
Krrrishna19-Jun-06 5:50
memberKrrrishna19-Jun-06 5:50 
Generalcode in c#, Pin
acharyakrishna1978@yahoo.com25-May-06 20:43
memberacharyakrishna1978@yahoo.com25-May-06 20:43 
GeneralAll I can say is nice! Pin
Khookie4-Feb-06 3:10
memberKhookie4-Feb-06 3:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171017.2 | Last Updated 18 Apr 2004
Article Copyright 2004 by Phylum
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid