I have the following trouble and i don't find a solution.
I want to implement a Winform without top bar and if is possible, without borders. I tried several things without success, the following would do the trick perfectly :
this.Text = string.Empty;
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
producing the following result :
The little problem is when me or the user trigger the maximize state , because will make the form enter in a FULLSCREEN mode ! and i don't know how to prevent this:
See? You can't see the windows taskbar ! I'm using
WindowState = FormWindowState.Maximized; // Makes a fullscreen that i dont want !
Appreciate your help !
By dragging either the right edge, bottom edge, or the corner, you can resize the form. The second way you can resize the form while the designer is open, is through the properties pane. Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it.
Well ! Thanks to all your answers I finally solved with the following two methods
private void MaximizeWindow()
{
var rectangle = Screen.FromControl(this).Bounds;
this.FormBorderStyle = FormBorderStyle.None;
Size = new Size(rectangle.Width, rectangle.Height);
Location = new Point(0, 0);
Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;
this.Size = new Size(workingRectangle.Width, workingRectangle.Height);
}
private void ResizableWindow()
{
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
}
Thanks to X-TECH and Luïs , this was solved !
Try this to set size dynamically, it may helps you.
Do not use WindowState = FormWindowState.Maximized;
Try this code on loading form
var rectangle = ScreenRectangle();
Size = new Size(rectangle.Width - 100, rectangle.Height - 100);
Location = new Point(50, 50);
// here 100 is pixel used to reserve from edges,
// you can set lower value according to your requirements
For full size
var rectangle = ScreenRectangle();
Size = new Size(rectangle.Width, rectangle.Height);
Location = new Point(0, 0);
Screen Rectangle Method is:
public Rectangle ScreenRectangle()
{
return Screen.FromControl(this).Bounds;
}
If you want to take control over form maximization, do it like that:
public class MyForm {
protected override void WndProc(ref Message m) {
const int WM_SYSCOMMAND = 0x0112;
const int SC_MAXIMIZE = 0xF030;
// When form is going to be maximized
if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MAXIMIZE)) {
m.Msg = 0; // <- we don't want a standard maximization
//TODO: tell Windows here what to do when user want to maximize the form
// Just a sample (pseudo maximization)
Location = new Point(0, 0);
Size = new Size(Screen.GetWorkingArea(this).Width,
Screen.GetWorkingArea(this).Height);
}
base.WndProc(ref m);
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With