Results 1 to 6 of 6

Thread: [RESOLVED] Fullscreen, can't show msgbox / forms!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Resolved [RESOLVED] Fullscreen, can't show msgbox / forms!

    Hello guys! I've a really nice fullscreen code I found on the internet, the only problem I found was that you can't make msgbox show or open another form! Which is really bothering me making panels.visible = true/false to make a cheap way of "Forms"



    Form1.
    Code:
    Private Sub TryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Call normalScreen()
        End Sub
    Module.
    Code:
    Module Module1
        Private Declare Function SetWindowPos Lib "user32.dll" Alias "SetWindowPos" (ByVal hWnd As IntPtr, ByVal hWndIntertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
        Private Declare Function GetSystemMetrics Lib "user32.dll" Alias "GetSystemMetrics" (ByVal Which As Integer) As Integer
        Private Const SM_CXSCREEN As Integer = 0
        Private Const SM_CYSCREEN As Integer = 1
        Private HWND_TOP As IntPtr = IntPtr.Zero
        Private Const SWP_SHOWWINDOW As Integer = 64
        Public ReadOnly Property ScreenX() As Integer
            Get
                Return GetSystemMetrics(SM_CXSCREEN)
            End Get
        End Property
    
        Public ReadOnly Property ScreenY() As Integer
            Get
                Return GetSystemMetrics(SM_CYSCREEN)
            End Get
        End Property
        Public Sub FullScreen()
            Form1.WindowState = FormWindowState.Maximized
            Form1.FormBorderStyle = FormBorderStyle.None
            Form1.TopMost = True
            SetWindowPos(Form1.Handle, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW)
        End Sub
        Public Sub normalScreen()
            Form1.WindowState = FormWindowState.Maximized
            Form1.FormBorderStyle = FormBorderStyle.FixedDialog
            Form1.TopMost = True
            SetWindowPos(Form1.Handle, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW)
        End Sub
    
        Public Sub NormalMode()
            ' restore the window size back to default
            Form1.WindowState = FormWindowState.Normal
            ' change the form’s border style so the border is visible
            ' note that SizableToolWindow is just what I’ve used – there are other options available if you have code auto-completion enabled
            Form1.FormBorderStyle = FormBorderStyle.FixedSingle
            ' change the window so it’s not the on top
            Form1.TopMost = True
        End Sub
    End Module

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: Fullscreen, can't show msgbox / forms!

    I recognize the code from Code Project site http://www.codeproject.com/KB/vb/vb....creenForm.aspx.

    One word of advice when grabbing code off Code Project is to first read the message section of the article as many times there are known issues and/or better methods to accomplish the task the article was for.

    Not knowing if you got this from Code Project but there was a comment as follows which does the full screen including task bar.
    Code:
        Public Sub MakeFullScreen()
            Me.SetVisibleCore(False)
            Me.FormBorderStyle = FormBorderStyle.None
            Me.WindowState = FormWindowState.Maximized
            Me.SetVisibleCore(True)
        End Sub
    If you like the original code and using VS2008 or higher than the following extensions will do the trick.

    Code:
    Module FormExtensions
        Private Declare Function SetWindowPos Lib "user32.dll" Alias "SetWindowPos" (ByVal hWnd As IntPtr, ByVal hWndIntertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
        Private HWND_TOP As IntPtr = IntPtr.Zero
        Private Const SWP_SHOWWINDOW As Integer = 64
    
        ''' <summary>
        ''' Place form into full screen
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="TaskBar">True to hide Windows TaskBar</param>
        ''' <remarks></remarks>
        <System.Runtime.CompilerServices.Extension()> _
        Public Sub FullScreen(ByVal sender As Form, ByVal TaskBar As Boolean)
    
            sender.WindowState = FormWindowState.Maximized
            sender.FormBorderStyle = FormBorderStyle.None
            sender.TopMost = True
    
            If TaskBar Then
    
                SetWindowPos(sender.Handle, HWND_TOP, 0, 0, _
                             Screen.PrimaryScreen.Bounds.Width, _
                             Screen.PrimaryScreen.Bounds.Height, _
                             SWP_SHOWWINDOW _
                )
    
            End If
    
        End Sub
        ''' <summary>
        ''' Maximize window
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <remarks></remarks>
        <System.Runtime.CompilerServices.Extension()> _
        Public Sub normalScreen(ByVal sender As Form)
            sender.WindowState = FormWindowState.Maximized
            sender.FormBorderStyle = FormBorderStyle.FixedDialog
            sender.TopMost = True
    
            'SetWindowPos(sender.Handle, HWND_TOP, 0, 0, 
            '             ScreenX, ScreenY, SWP_SHOWWINDOW)
        End Sub
        ''' <summary>
        ''' Restore to original size/position
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <remarks></remarks>
        <System.Runtime.CompilerServices.Extension()> _
        Public Sub NormalMode(ByVal sender As Form)
            sender.WindowState = FormWindowState.Normal
            sender.FormBorderStyle = FormBorderStyle.FixedSingle
            sender.TopMost = True
        End Sub
        'Private Function ScreenX() As Integer
        '    Return Screen.PrimaryScreen.Bounds.Width
        'End Function
        'Private Function ScreenY() As Integer
        '    Return Screen.PrimaryScreen.Bounds.Height
        'End Function
    End Module
    Usage
    Code:
    Me.FullScreen(True)
    or
    Code:
    FullScreen(True)

    Then to restore
    Code:
    NormalMode()
    Code:
    Me.NormalMode()
    In regards to a messagebox aka MsgBox, that should work fine. For a child form try something like the following when TopMost has been set.

    Code:
            Dim f As New frmChildForm
            Dim TopMostSetting As Boolean = Me.TopMost
    
            Try
                Me.TopMost = False
                f.ShowDialog()
            Finally
                f.Dispose()
                Me.TopMost = TopMostSetting
            End Try
    The taskbar if covered will still be covered.

    See attached project for the above code and examples. Hope this helps you out.
    Last edited by kareninstructor; Jul 9th, 2011 at 10:07 PM.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Re: Fullscreen, can't show msgbox / forms!

    Kevininstructor, Thank you so much! I'll check this code, and bring an update if this solved my problem or not (probably it will).

    This is the link, where I grabbed it!
    http://digitalformula.net/technical/...p-using-vbnet/

    Yet again, Thank you so much!

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: Fullscreen, can't show msgbox / forms!

    Quote Originally Posted by macbrutal View Post
    Kevininstructor, Thank you so much! I'll check this code, and bring an update if this solved my problem or not (probably it will).

    This is the link, where I grabbed it!
    http://digitalformula.net/technical/...p-using-vbnet/

    Yet again, Thank you so much!
    Yes let us know how things go.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Re: Fullscreen, can't show msgbox / forms!

    Worked absolutely fine! Alltho, I couldn't open your file you attached (maybe it's because I'm using 2005?)

    I used
    Code:
    Public Sub MakeFullScreen()
            Me.SetVisibleCore(False)
            Me.FormBorderStyle = FormBorderStyle.None
            Me.WindowState = FormWindowState.Maximized
            Me.SetVisibleCore(True)
        End Sub
    And
    Code:
           Dim f As New frmChildForm
            Dim TopMostSetting As Boolean = Me.TopMost
    
            Try
                Me.TopMost = False
                f.ShowDialog()
            Finally
                f.Dispose()
                Me.TopMost = TopMostSetting
            End Try
    Thank you so much!

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: Fullscreen, can't show msgbox / forms!

    Quote Originally Posted by macbrutal View Post
    Worked absolutely fine! Alltho, I couldn't open your file you attached (maybe it's because I'm using 2005?)

    I used
    Code:
    Public Sub MakeFullScreen()
            Me.SetVisibleCore(False)
            Me.FormBorderStyle = FormBorderStyle.None
            Me.WindowState = FormWindowState.Maximized
            Me.SetVisibleCore(True)
        End Sub
    And
    Code:
           Dim f As New frmChildForm
            Dim TopMostSetting As Boolean = Me.TopMost
    
            Try
                Me.TopMost = False
                f.ShowDialog()
            Finally
                f.Dispose()
                Me.TopMost = TopMostSetting
            End Try
    Thank you so much!
    Yep I am using VS2008 but it doesn't matter as you appear to be fine now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width