Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove borders winforms and WindowState Maximized without fullscreen

Tags:

c#

winforms

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 :

All work perfect ! But when i make it in maximized state

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 !

See? You can't see the windows taskbar ! I'm using

WindowState = FormWindowState.Maximized; // Makes a fullscreen that i dont want !

Appreciate your help !

like image 841
Carlos Delgado Avatar asked Aug 17 '15 07:08

Carlos Delgado


People also ask

How do I resize Winforms?

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.


3 Answers

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 !

Maximized state and the taskbar still there !

like image 187
Carlos Delgado Avatar answered Nov 11 '22 08:11

Carlos Delgado


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;
}
like image 6
NASSER Avatar answered Nov 11 '22 08:11

NASSER


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);
    } 
    ...
  }
like image 2
Dmitry Bychenko Avatar answered Nov 11 '22 10:11

Dmitry Bychenko