Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Fullscreen the form in VB.NET using a class

0.00/5 (No votes)
26 Jun 2010 1  
In some application we need to fullscreen the App .Here is simple class that can fullscreen any App. Just create a variable of this class type and call the function using the class variable.

Introduction

Fullscreen the form in VB.NET using a class

In some application we need to fullscreen the App .Here is simple class that can fullscreen any App. Just create a variable of this class type and call the function using the class variable.


Using the code

'''
''' It will return current resolution parameters. 
''' It can make a form FULLSCREEN ... 
''' 
'''IPStudents.Info - Its all about creativity and ideas. 
'''Author  : Yash Bharadwaj and Chander Prakash 
'''Copyright :  Free to use.Don't remove this Sticker.
'''Usage: Just call function fullscreen with form name as parameter.
'''It can detect client resolution as width-x and height-y
'''It can maximize form as fullscreen.
'''You can make form Topmost as optional 
'''<author>Yash Bharadwaj</author>
'''<remarks></remarks>




Public Class FullscreenClass



Public 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 



'You also need an alias to the API function called GetSystemMetrics, like this : 
 Private Declare Function GetSystemMetrics Lib user32.dll Alias GetSystemMetrics (ByVal Which As Integer) As Integer


'Following this you need to declare 4 constants : 
    Private Const SM_CXSCREEN As Integer = 0
    Private Const SM_CYSCREEN As Integer = 1
    Public Shared HWND_TOP As IntPtr = IntPtr.Zero
    Public Const SWP_SHOWWINDOW As Integer = 64


'Then 2 public properties : 

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(ByVal frm As Form, ByVal boolTopOptional As Boolean)

        frm.WindowState = FormWindowState.Maximized
        frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.TopMost = boolTopOptional
        SetWindowPos(frm.Handle, HWND_TOP, 0,0, ScreenX, ScreenY, SWP_SHOWWINDOW)

End Sub

End Class      
--------------------------------------------------------------------------------- Updated Making fullscreen using Screen class
Public Class classFullScreen
    Dim varScreen As Screen
    Dim intWidth As Integer = Screen.PrimaryScreen.Bounds.Width
    Dim intHeight As Integer = Screen.PrimaryScreen.Bounds.Height
    Dim intTop As Integer = 0
    Dim intLeft As Integer = 0
    Dim intX As Integer = 0
    Dim intY As Integer = 0

    Public Function FullscreenTheForm(ByVal frm As Form)
        frm.Top = intTop
        frm.Left = intLeft
        frm.Width = intWidth + 40
        frm.Height = intHeight
        frm.FormBorderStyle = FormBorderStyle.None


        Return 0
    End Function
End Class
Now problem is -> The bottom window bar is above on form.I'm trying to resolve this issue also. Thank you mav and robert for your comments.

Points of Interest

CSS Editor.in - Wait less code more 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here