Click here to Skip to main content
Click here to Skip to main content
Go to top

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.

Introduction

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
   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

License

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

Share

About the Author

Phylum

Canada Canada
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberHeaven20203-Nov-10 6:57 
good way
GeneralWidth and Height, both are resizeable. PinmemberKrrrishna19-Jun-06 5:50 
Generalcode in c#, Pinmemberacharyakrishna1978@yahoo.com25-May-06 20:43 
GeneralAll I can say is nice! PinmemberKhookie4-Feb-06 3:10 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 18 Apr 2004
Article Copyright 2004 by Phylum
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid