none
How to make a form full-screen in C# 2005?

    Question

  • Hi,

    I am trying to make one of my application forms full-screen - no borders, no task bar, etc.   How can I do this?

    Thanks!

    -- stockcrack

    Monday, May 01, 2006 5:15 PM

Answers

  • What you are trying to do is a three part thing, first, hiding the taskbar:

    In order to show and hide the taskbar you can use this:

                [DllImport("user32.dll")]
                private static extern int FindWindow(string className, string windowText);
                [DllImport("user32.dll")]
                private static extern int ShowWindow(int hwnd, int command);

                private const int SW_HIDE = 0;
                private const int SW_SHOW = 1;

    and then to use it:

                int hwnd = FindWindow("Shell_TrayWnd","");
                ShowWindow(hwnd,SW_HIDE);

    Note that you should be sure to reshow the taskbar when your application closes.

    Second, to make your window full screen, set your form’s WindowState property to Maximized and finally to get rid of the form’s title bar you need to set your form’s WindowState property to Maximized.

    Monday, May 01, 2006 6:33 PM

All replies

  • What you are trying to do is a three part thing, first, hiding the taskbar:

    In order to show and hide the taskbar you can use this:

                [DllImport("user32.dll")]
                private static extern int FindWindow(string className, string windowText);
                [DllImport("user32.dll")]
                private static extern int ShowWindow(int hwnd, int command);

                private const int SW_HIDE = 0;
                private const int SW_SHOW = 1;

    and then to use it:

                int hwnd = FindWindow("Shell_TrayWnd","");
                ShowWindow(hwnd,SW_HIDE);

    Note that you should be sure to reshow the taskbar when your application closes.

    Second, to make your window full screen, set your form’s WindowState property to Maximized and finally to get rid of the form’s title bar you need to set your form’s WindowState property to Maximized.

    Monday, May 01, 2006 6:33 PM
  • Hi,

    Could you manage to finish your task...

    regards,
    Bhanu.
    Thursday, May 04, 2006 9:04 PM
  • That is not qute solution.

    For full solution, please look here:

    How to make Windows Form app truly Full Screen (and to hide Taskbar) in C#?

    Most important piece of code is:

    public class WinApi
    {
    [DllImport(”user32.dll”, EntryPoint = “GetSystemMetrics”)]
    public static extern int GetSystemMetrics(int which);

    [DllImport(”user32.dll”)]
    public static extern void
    SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
    int X, int Y, int width, int height, uint flags);

    private const int SM_CXSCREEN = 0;
    private const int SM_CYSCREEN = 1;
    private static IntPtr HWND_TOP = IntPtr.Zero;
    private const int SWP_SHOWWINDOW = 64; // 0×0040

    public static int ScreenX
    {
    get { return GetSystemMetrics(SM_CXSCREEN);}
    }

    public static int ScreenY
    {
    get { return GetSystemMetrics(SM_CYSCREEN);}
    }

    public static void SetWinFullScreen(IntPtr hwnd)
    {
    SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
    }
    }

    --

    Regards,

    Dejan Vesić

    MCP & MCAD for .Net technologies

    Home: http://www.vesic.org/english/

    Blog: http://www.vesic.org/english/blog/

    Sunday, December 03, 2006 4:56 PM
  • I am wondering that will this solution work on Vista?

    Tuesday, January 01, 2008 1:02 PM
  •  

    my apologies I should have checked. I does work on vista Smile.
    Tuesday, January 01, 2008 1:15 PM
  • Hi,

    and what if you want a full screen on the 2nd screen? (in case you use multi screen extended desktop) ?

    Thanks,
    Redax
    • Proposed as answer by jr78 Tuesday, February 17, 2009 5:20 PM
    Sunday, May 11, 2008 5:26 PM
  • I got this to work for multiple monitor setup assuming the taskbar is on the primary monitor using the snippets below.

    [DllImport("user32.dll")]  
    private static extern int FindWindow(string lpszClassName, string lpszWindowName);  
    [DllImport("user32.dll")]  
    private static extern int ShowWindow(int hWnd, int nCmdShow);  
    private const int SW_HIDE = 0;  
    private const int SW_SHOW = 1;  
     // get the screen the form is on currently
    Screen currentScreen = Screen.FromRectangle(this.RectangleToScreen(ClientRectangle));  
     
    // code to maximize form fullscreen mode  
    if (currentScreen.Primary)  
    {  
      int hWnd = FindWindow("Shell_TrayWnd""");  
      ShowWindow(hWnd, SW_HIDE);  
      this.FormBorderStyle = FormBorderStyle.None;  
      this.Location = new Point(0, 0);  
      this.WindowState = FormWindowState.Maximized;  
    }  
    else 
    {  
      this.FormBorderStyle = FormBorderStyle.None;  
      this.Location = new Point(currentScreen.Bounds.X, currentScreen.Bounds.Y);  
      this.WindowState = FormWindowState.Maximized;  
    }  
     
    //code to exit fullscreen  
    this.FormBorderStyle = FormBorderStyle.Sizable;  
    if (currentScreen.Primary)  
    {  
       //show the hidden task bar  
       int hwnd = FindWindow("Shell_TrayWnd""");  
       ShowWindow(hwnd, SW_SHOW);  
    }  
    this.WindowState = FormWindowState.Maximized;  
     
    Tuesday, February 17, 2009 5:32 PM
  •  

    this.Bounds = Screen.PrimaryScreen.Bounds;
    this.TopMost = true;
    

    and set the FormBorderStyle to None.

     

    That will set the form to fullscreen, and it will also cover the taskbar

    ** For multi screen:

    this.Bounds = Screen.AllScreens[Screen.AllScreens.Length-1].Bounds;

    • Proposed as answer by OYoussef Wednesday, August 25, 2010 2:45 PM
    Wednesday, August 25, 2010 2:44 PM
  • That is not qute solution.

    For full solution, please look here:

    How to make Windows Form app truly Full Screen (and to hide Taskbar) in C#?

    Most important piece of code is:

    public class WinApi
    {
    [DllImport(”user32.dll”, EntryPoint = “GetSystemMetrics”)]
    public static extern int GetSystemMetrics(int which);

    [DllImport(”user32.dll”)]
    public static extern void
    SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
    int X, int Y, int width, int height, uint flags);

    private const int SM_CXSCREEN = 0;
    private const int SM_CYSCREEN = 1;
    private static IntPtr HWND_TOP = IntPtr.Zero;
    private const int SWP_SHOWWINDOW = 64; // 0×0040

    public static int ScreenX
    {
    get { return GetSystemMetrics(SM_CXSCREEN);}
    }

    public static int ScreenY
    {
    get { return GetSystemMetrics(SM_CYSCREEN);}
    }

    public static void SetWinFullScreen(IntPtr hwnd)
    {
    SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
    }
    }

    --

    Regards,

    Dejan Vesić

     

    MCP & MCAD for .Net technologies

    Home: http://www.vesic.org/english/

    Blog: http://www.vesic.org/english/blog/


    The solution works for me, Thanks a lot! I've got the same problem.
    Friday, January 14, 2011 9:39 AM