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 ...
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)
{
IsSizeMax = ! IsSizeMax;
if (IsSizeMax)
{
CustomMaxMinButton.Text = "£";
this.Size = MaxSize;
}
else
{
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.