9

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 !

4
  • 3
    What about this.FormBorderStyle = FormBorderStyle.None; ?
    – Bauss
    Aug 17, 2015 at 7:31
  • 1
    this.FormBorderStyle = FormBorderStyle.None; //when i trigger the maximize state still showing in fullscreen mode :\ Aug 17, 2015 at 7:53
  • Isn't there is a Windows setting somewhere for taskbar to be always on top. Without it set maximized window will always use desktop working area (including taskbar).
    – Sinatr
    Aug 17, 2015 at 7:55

6 Answers 6

11

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 !

6

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;
}
1
  • thanks for your answer , it help me to understand a little more what i'm doing ;) , I give the final answer to solve this , but i'll accept your answer ! Aug 17, 2015 at 8:15
2

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);
    } 
    ...
  }
1
  • this one doesnt work for me, it never pass that If-then
    – Jhollman
    Aug 6, 2021 at 18:46
2

Remove the border

this.FormBorderStyle = FormBorderStyle.None;

I think this goes work by clicking the maximize button

// Add following namespaces
using System.Windows.Forms;
using System.Drawing;

// Retrieve the working rectangle from the Screen class using the PrimaryScreen and the 
// WorkingArea properties.
Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;

// Set the size of the form slightly less than size of working rectangle. 
this.Size = new Size(workingRectangle.Width, workingRectangle.Height);

Sources: MSDN system.windows.forms.screen.primaryscreen and Remove the title bar in Windows Forms

1

hi you can to do this only with 2 instructions: this.MaximumSize = Screen.PrimaryScreen.WorkingArea.Size; this.WindowState = FormWindowState.Maximized;

1
  • Your answer will only put the windows to a maximized state which is not what the question is about. Jul 18, 2017 at 15:49
-2
this.Text = string.Empty;
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;

this.Left = this.Top = 0;
this.Height = Screen.GetWorkingArea(this).Height;
this.Width = Screen.GetWorkingArea(this).Width;

GetWorkingArea: Gets the working area of the display. The working area is the desktop area of the display, excluding taskbars, docked windows, and docked tool bars.MSDN

2
  • @Luïs, Try run the code, That's work perfectly, Why you think that's not work? Aug 17, 2015 at 8:48
  • Oke, I have test it and it work. I didn't know that. sorry for my mistake. Aug 17, 2015 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.