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 !

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Carlos Delgado
  • 2,930
  • 4
  • 23
  • 49
  • 3
    What about `this.FormBorderStyle = FormBorderStyle.None;` ? – Bauss Aug 17 '15 at 07:31
  • 1
    this.FormBorderStyle = FormBorderStyle.None; //when i trigger the maximize state still showing in fullscreen mode :\ – Carlos Delgado Aug 17 '15 at 07: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 '15 at 07:55
  • https://msdn.microsoft.com/en-us/library/windows/desktop/ms632626%28v=vs.85%29.aspx – Hans Passant Aug 17 '15 at 08:15

6 Answers6

10

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 !

Carlos Delgado
  • 2,930
  • 4
  • 23
  • 49
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;
}
TaW
  • 53,122
  • 8
  • 69
  • 111
NASSER
  • 5,900
  • 7
  • 38
  • 57
  • 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 ! – Carlos Delgado Aug 17 '15 at 08:15
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

Community
  • 1
  • 1
H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
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);
    } 
    ...
  }
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
1

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

Guesso
  • 11
  • 2
-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

Reza ArabQaeni
  • 4,848
  • 27
  • 46