How do I make a WinForms app go Full Screen

前端 未结 9 1366
你的背包
你的背包 2020-11-22 11:20

I have a WinForms app that I am trying to make full screen (somewhat like what VS does in full screen mode).

Currently I am setting FormBorderStyle to <

相关标签:
9条回答
  • 2020-11-22 12:09

    You can use the following code to fit your system screen and task bar is visible.

        private void Form1_Load(object sender, EventArgs e)
        {   
            // hide max,min and close button at top right of Window
            this.FormBorderStyle = FormBorderStyle.None;
            // fill the screen
            this.Bounds = Screen.PrimaryScreen.Bounds;
        }
    

    No need to use:

        this.TopMost = true;
    

    That line interferes with alt+tab to switch to other application. ("TopMost" means the window stays on top of other windows, unless they are also marked "TopMost".)

    0 讨论(0)
  • 2020-11-22 12:13

    You need to set your window to be topmost.

    0 讨论(0)
  • 2020-11-22 12:15

    I recently made an Mediaplayer application and I used API-calls to make sure the taskbar was hidden when the program was running fullscreen and then restored the taskbar when the program was not in fullscreen or not had focus or was exited.

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    
    Sub HideTrayBar()
        Try
    
    
            Dim tWnd As Integer = 0
            Dim bWnd As Integer = 0
            tWnd = FindWindow("Shell_TrayWnd", vbNullString)
            bWnd = FindWindowEx(tWnd, bWnd, "BUTTON", vbNullString)
            ShowWindow(tWnd, 0)
            ShowWindow(bWnd, 0)
        Catch ex As Exception
            'Error hiding the taskbar, do what you want here..
        End Try
    End Sub
    Sub ShowTraybar()
        Try
            Dim tWnd As Integer = 0
            Dim bWnd As Integer = 0
            tWnd = FindWindow("Shell_TrayWnd", vbNullString)
            bWnd = FindWindowEx(tWnd, bWnd, "BUTTON", vbNullString)
            ShowWindow(bWnd, 1)
            ShowWindow(tWnd, 1)
        Catch ex As Exception
        'Error showing the taskbar, do what you want here..     
                   End Try
    
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题