Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i have a Windows Application with containts of buttons,textboxes,pictureboxes,etc. in C#.Net! now what i want just add there a manual button of Maximize, to Maximize the form! and after that the all containts which are present in form like button, textboxes,picture boxes should be automatically resizable when i click the Maximize button..! please give me the solution..!

if my form normal size is 784,517! and when i click the maximize button it should be 784,593..! so what will be solution.?
Posted
Comments
Orcun Iyigun 20-Jan-12 11:59am    
What do you mean by "after that the all containts which are present in form like button, textboxes,picture boxes should be automatically resizable"? So user can resize the controls or when you maximize the form the controls should automatically be resized?
Dnyanesh Wahiley 21-Jan-12 0:48am    
see sir! there is fix form of 784,517 size! now what i want when i click on Maximize button! that form will be risized by 784,593! the first thing is that i just want to add user defined button for Maximize on the right side top of the form! i m not talking about predifined maximize or minimize system properties button! and after that what i want, suppose just take an example of this codeproject web page, when i click on maximize button on this page so in that case every images, advertisements etc.. containts of this page automatically will be resized! and when i click restore button then again it would be fix autosize with the page!
Dnyanesh Wahiley 21-Jan-12 0:51am    
and my question was how can i add Maximize button on the form! and what will be solution on that to fill the requirment!
Thanks sir..!

I totally agree to OriginalGiff's solution but no matter what if you really want to apply it. Here are some reference links that might be helpful to you;

Runtime resizable controls![^]
Allow the User to Resize Controls at Runtime[^]
Resizing controls at runtime[^]

Good luck,
OI
 
Share this answer
 
Comments
Dnyanesh Wahiley 21-Jan-12 0:48am    
see sir! there is fix form of 784,517 size! now what i want when i click on Maximize button! that form will be risized by 784,593! the first thing is that i just want to add user defined button for Maximize on the right side top of the form! i m not talking about predifined maximize or minimize system properties button! and after that what i want, suppose just take an example of this codeproject web page, when i click on maximize button on this page so in that case every images, advertisements etc.. containts of this page automatically will be resized! and when i click restore button then again it would be fix autosize with the page!.
Dnyanesh Wahiley 21-Jan-12 0:52am    
and my question was how can i add Maximize button on the form! and what will be solution on that to fill the requirment!
Thanks sir..!.
Let me add to OriginalGriff's and Orcun's wise answers, that ... if font-scaling in response to form re-size is NOT an issue ... then you can exploit the Anchor or Dock properties of Controls so their size will change as the Form size changes.

You can also, by use of Margin, and Padding properties, control the spacing between a Control and its "container," and the distances between Controls, but please note that Dock will over-ride Margin and Padding property settings.

best, Bill
 
Share this answer
 
Comments
Dnyanesh Wahiley 21-Jan-12 0:49am    
see sir! there is fix form of 784,517 size! now what i want when i click on Maximize button! that form will be risized by 784,593! the first thing is that i just want to add user defined button for Maximize on the right side top of the form! i m not talking about predifined maximize or minimize system properties button! and after that what i want, suppose just take an example of this codeproject web page, when i click on maximize button on this page so in that case every images, advertisements etc.. containts of this page automatically will be resized! and when i click restore button then again it would be fix autosize with the page!.
Dnyanesh Wahiley 21-Jan-12 0:52am    
and my question was how can i add Maximize button on the form! and what will be solution on that to fill the requirment!
Thanks sir..!.
About the Button: let me ask you:

1. is the reason you want a customized Button to switch between two sizes because you are using a Form whose 'FormBorderStyle property is set to 'none:

Or:

You are using a Form whose 'FormBorderStyle property is set to 'FixedToolWindow and its 'Text property is not set: in which case, Maximize and Minimize Buttons will not appear in the TitleBar: whether or not you have them "on" in the design-time UI.

Or:

You just do not wish the standard WinForms Window TitleBar adornments to appear ?

2. Do you realize that by using the design-time MaximumSize and MinimumSize design-time Properties of a WinForm you can control the resizing triggered by using the standard TitleBar adornments ?

3. Do you realize you could, via code, use the standard adornments, and by creating an EventHandler for the Form SizeChanged Event, you could detect and change the ultimate size setting : note: I would NOT recommend this approach for several reasons, including the need to prevent recursion.

... okay ... now: let's assume, for whatever reason, the standard Minimize/Maximize thing is not used ...

4. is there a reason why you don't wish to have two buttons, one to Minimize, and one to Maximize: note: I am not saying that you should have two buttons.

5. is it an absolute requirement that your (assume single) Button-whatever looks exactly like the standard one ?

~

Whatever you choose to use as your Custom Control to switch back and forth between two Window Sizes ... you could use a Button, a Label, a PictureBox, maybe even, perhaps, an Icon:

You are going to end up with some code that may work like this example:

... edit Jan. 22nd. changed code to use a boolean flag to switch states ...
// you'll need to set proper values for the 'original' character in the Button
// and the Form Size somewhere: either at Design-Time ... 
// or, in code, in an EventHandler like: Form Load, or Form Shown

private Size MinSize = new Size(784, 517);
private Size MaxSize = new Size(784, 593);
private bool IsSizeMax = true;

private void CustomMaxMinButton_Click_1(object sender, EventArgs e)
{
    // negate the boolean value here
    IsSizeMax = ! IsSizeMax;

    if (IsSizeMax)
    {
        // using 0xA3 to represent minimize
        CustomMaxMinButton.Text = "£";
        this.Size = MaxSize;
    }
    else
    {
        // using 0xB3 to represent maximize
        CustomMaxMinButton.Text = "³";
        this.Size = MinSize;
    }
}
In this example, I took the "easy way out," and just used a Button which:

1. has AutoSize set to 'false

2. has the Font set to the Symbol font, at 12 points size or so.

3. has its Anchor property set to Top and Right: that's really not a concern here if you make the Form not re-sizable is it ?

4. I used this in a Form with its FormBorderStyle set to 'FixedToolWindow, and "empty" Text: I left the 'ControlBox adornment visible, so the user has a the standard 'Close Button available.

Since this is not a "real pretty" solution: if I wanted to make it better looking, I'd probably be swapping two graphic images in and out of a PictureBox or even a Button's 'BackGroundImage Property ... rather than doing what's shown here.
 
Share this answer
 
v4
Comments
Dnyanesh Wahiley 21-Jan-12 12:14pm    
Thank you very much sir..! its a great hint for me as well as new basic functnality of winform to get learn!
BillWoodruff 21-Jan-12 20:44pm    
Glad you find this helpful. I've made a minor edit to the code to use a boolean variable to control switching between the 2 Size states: this is much better practice than in the first example, which tested which character was in the Text property of the Button. And, imho, "cleaner" code.
That is not necessarily easy to do, particularly if you expect the controls and so forth to resize in a nice way so it all looks good. Winforms is not really very good at that kind of thing - fonts do not scale automatically when buttons grow and shrink, and so forth. If you really need that kind of feature, you need to move to WPF - otherwise pick a useful size and stick with it, or go to a plan like VS with dockable control holders surrounding a central area the central area expands and contracts, the controls and their holders remain the same size.
 
Share this answer
 
Comments
Dnyanesh Wahiley 21-Jan-12 12:12pm    
Thank you sir for ur Great guidence..! it is totaly helpful for me!

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