Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys,

Can you help me on how to disable the user to re-size the form width.
Scenario:
I have want to set a given width where it is the boundary or the limit width where
the user can re-size.
User can re-size the form except when it have reach to my limit width of the form...

Can you please help me...
Sorry for poor English... :O
Thanks in advance....
Posted
Updated 2-Aug-20 5:16am

Just set the form's MaximumSize property[^] and MinimumSize property[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Jul-11 22:37pm    
I would use this way, too. My 5.
--SA
I take it this is a WinForms app. The window will have a Resize event which fires when the control gets resized (funnily enough). You could use this event to check the size of the form, and if it is greater than the max size you want just force it to the correct size . Something like this(pseudo C#)

C#
void Resize(object sender, eventArgs e)
        {
            if (this.Width >= MaxWidth)
            {
                this.Width = MaxWidth;
            }
        }


Hope this helps

[UPDATE]

Here is a VB version
VB
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
       Dim maxWidth As Integer = 800
       If Me.Width >= maxWidth Then
           Me.Width = maxWidth
       End If
   End Sub


Good Luck
 
Share this answer
 
v2
Comments
Dave Kreskowiak 21-Jul-11 13:01pm    
That's doing it the hard way. I prefer to use the MaximumSize and MinimumSize properties of the Form class.
Philippe Mori 21-Jul-11 21:03pm    
Exactly
Sergey Alexandrovich Kryukov 22-Jul-11 22:36pm    
Agree.
--SA
it is very easy please set your size like mine width and height then write this code the first is width and the second is height 499
this.Size = new Size(749, 499);
 
Share this answer
 
v2
Comments
Ralf Meier 2-Aug-20 14:04pm    
You answer to a 9 years old question ... AND ... your answer isn't so solution to the question.
The right answer was given (MaximumSize-Property).
Perhaps in future read the questions carefully ... and look when they were asked ...

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900