how to make a form fill the entire screen

Yeung

Member
Joined
Jun 15, 2007
Messages
22
Programming Experience
Beginner
Anybody know how to make a form fill the whole screen, and the user cannot switch to another task either by pressing alt+tab or selecting another task in the task bar (since the form fills the whole screen).

The only way to switch back is by closing the form.
 
To make it fullscreen:
VB.NET:
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized
 
You can set the form to Maximized in the WindowState Property and also set the FormBorderStyle Property to None. This will generate a form that takes up the entire page.

Now for the second part of not allowing a alt-tab and what not. You will have to capture keystrokes using Windows APIs. This will allow you to capture most all keystrokes except for Control-Alt-Delete Which is controlled by the OS. This will lead you to another problem where a user 'could' use Control-Alt-Delete to get to the Task Manager and then Kill your Task. That would mean that you will have to capture a ProcessStartTrace WMI Event on the Task Manager Process and Kill it whenever it pops up.

The Keyboard Hook Code can be found here

For the part regarding killing Task Manager you will add a ManagementEventWatcher. It is similar to a Timer control where it won't be displayed on the form, but rather below the form in the IDE. Make sure the InitializeComponent Routine has the following code in it

VB.NET:
Me.ManagementEventWatcher1.Query = New System.Management.EventQuery("SELECT * FROM Win32_ProcessStartTrace")
        Me.ManagementEventWatcher1.Scope = New System.Management.ManagementScope("\\.\root\CIMV2")

You should be able to add all the above from within the IDE and not have to manually add it.

Then finally killing Task Manager

VB.NET:
    'Kills any instances of Taskmgr.exe.  This app will pop-up on top during Ctrl-Alt-Delete
    Private Sub ManagementEventWatcher1_EventArrived(ByVal sender As Object, ByVal e As System.Management.EventArrivedEventArgs) Handles ManagementEventWatcher1.EventArrived
        For Each ObjItem As Process In Process.GetProcessesByName("taskmgr")
            ObjItem.Kill()
        Next
    End Sub

The code above was written for 2003 so there may be different ways to accomplish the same in 2005, I just never had to revisit it.

Finally a word of caution. When building the app make sure you develop with either the keyboard hooking disabled or the WindowState Property set to Normal. That way if you make a mistake you won't have to restart your computer. I've done it a few times.

Rob
 
Back
Top