Click here to Skip to main content
6,293,171 members and growing! (11,709 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate

Resizable Controls at Runtime!

By Phylum

This simple code will allow the user to resize controls at runtime
VB, .NET, Win2K, WinXP, Win2003, Visual Studio, Dev
Posted:17 Apr 2004
Views:28,648
Bookmarked:11 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
16 votes for this article.
Popularity: 2.32 Rating: 1.92 out of 5
7 votes, 43.8%
1
4 votes, 25.0%
2
3 votes, 18.8%
3

4
2 votes, 12.5%
5

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Phylum


Member

Location: Canada Canada

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralWidth and Height, both are resizeable. PinmemberKrrrishna6:50 19 Jun '06  
Generalcode in c#, Pinmemberacharyakrishna1978@yahoo.com21:43 25 May '06  
GeneralAll I can say is nice! PinmemberKhookie4:10 4 Feb '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Apr 2004
Editor:
Copyright 2004 by Phylum
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project