Click here to Skip to main content
15,881,687 members
Articles / Desktop Programming / Win32

Fullscreen the form in VB.NET using a class

,
Rate me:
Please Sign up or sign in to vote.
3.57/5 (6 votes)
26 Jun 2010GPL3 79.3K   34   11
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

VB
'''<summary>
''' It will return current resolution parameters. 
''' It can make a form FULLSCREEN ... 
'''</summary> 
'''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
VB
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, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer
India India
IPStudents.Info - Its all about creativity and ideas.

Written By
Software Developer Speedovation
India India
CssEditor.In - Wait less code more.

Comments and Discussions

 
PraiseThanks!!! Pin
Member 120485346-May-20 15:38
Member 120485346-May-20 15:38 
GeneralSorry.. Pin
DavesChillaxin31-May-12 16:57
DavesChillaxin31-May-12 16:57 
Generalanother solution in C# Pin
RubyPdf10-Jan-09 4:07
RubyPdf10-Jan-09 4:07 
QuestionMe.TopMost ?? Pin
netiger200222-Apr-08 15:31
netiger200222-Apr-08 15:31 
GeneralNo need for GetSystemMetrics Pin
mav.northwind8-Apr-08 2:38
mav.northwind8-Apr-08 2:38 
GeneralRe: No need for GetSystemMetrics Pin
chanderp8-Apr-08 2:49
chanderp8-Apr-08 2:49 
AnswerRe: No need for GetSystemMetrics Pin
Yash Bharadwaj12-Apr-08 20:38
Yash Bharadwaj12-Apr-08 20:38 
QuestionWhat is SetWindowPos for? Pin
Robert Rohde8-Apr-08 2:08
Robert Rohde8-Apr-08 2:08 
AnswerRe: What is SetWindowPos for? Pin
chanderp8-Apr-08 2:36
chanderp8-Apr-08 2:36 
GeneralRe: What is SetWindowPos for? Pin
Robert Rohde10-Apr-08 0:04
Robert Rohde10-Apr-08 0:04 
GeneralRe: What is SetWindowPos for? Pin
a_pess25-Oct-08 3:44
a_pess25-Oct-08 3:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.