views:

577

answers:

3

I have a .net windows application that needs to run in full screen. When the application starts however the taskbar is shown on top of the main form and it only disappears when activating the form by clicking on it or using ALT-TAB. The form's current properties are as follow:

  • WindowsState=Normal
  • TopMost=Normal
  • Size=1024,768 (this is the screen resolution of the machines it's going to be running on)
  • FormBorderStyle = None

I've tried adding the followings on form load but none worked for me:

  • this.Focus(); (after giving the focus this.Focus property is always false)
  • this.BringToFront();
  • this.TopMost = true; (this however would not be ideal in my scenario)
  • this.Bounds = Screen.PrimaryScreen.Bounds;
  • this.Bounds = Screen.PrimaryScreen.Bounds;

Is there a way to do it within .NET or would I have to invoke native windows methods and if so a code snippet would very much be appreciated.

many thanks

+1  A: 

Use:

  • FormBorderStyle = None
  • WindowsState = Maximized

And then is form placed over the taskbar.

TcKs
I was a day late and a dollar short I guess.
Adkins
same as above comment
myquestionoftheday
Send printscreen, how it looks. This is standard way, which I successfuly use for this task. I think there will be some other problem.
TcKs
sorry but I can't send screen grabs for customer reasons. It basically is a form with no borders that takes the whole screen size but when it first starts is shown behind the taskbar, until you then click on the form which activates it and brings it on top of the taskbar. thanks
myquestionoftheday
A: 

I believe that it can be done by simply setting your FormBorderStyle Property to None and the WindowState to Maximized. If you are using Visual Studio both of those can be found in the IDE so there is no need to do so programmatically. Make sure to include some way of closing/exiting the program before doing this cause this will remove that oh so helpful X in the upper right corner.

EDIT:

Try this instead. It is a snippet that I have kept for a long time. I can't even remember who to credit for it, but it works.

/*
 * A function to put a System.Windows.Forms.Form in fullscreen mode
 * Author: Danny Battison
 * Contact: [email protected]
 */

        // a struct containing important information about the state to restore to
        struct clientRect
        {
            public Point location;
            public int width;
            public int height;
        };
        // this should be in the scope your class
        clientRect restore;
                bool fullscreen = false;

        /// <summary>
        /// Makes the form either fullscreen, or restores it to it's original size/location
        /// </summary>
        void Fullscreen()
        {
            if (fullscreen == false)
            {
                this.restore.location = this.Location;
                this.restore.width = this.Width;
                this.restore.height = this.Height;
                this.TopMost = true;
                this.Location = new Point(0,0);
                this.FormBorderStyle = FormBorderStyle.None;
                this.Width = Screen.PrimaryScreen.Bounds.Width;
                this.Height = Screen.PrimaryScreen.Bounds.Height;
            }
            else
            {
                this.TopMost = false;
                this.Location = this.restore.location;
                this.Width = this.restore.width;
                this.Height = this.restore.height;
                                // these are the two variables you may wish to change, depending
                                // on the design of your form (WindowState and FormBorderStyle)
                this.WindowState = FormWindowState.Normal;
                this.FormBorderStyle = FormBorderStyle.Sizable;
            }
        }
Adkins
sorry, I should have said it before, FormBorderStyle is already set to None but setting the WindowState to Maximized did not solve the problem. Thanks for your answer anyway
myquestionoftheday
"this.TopMost" puts your frame on top (duh) but that includes on top of the taskbar and everything.
Adkins
yes, by using your snippet the screen is finally on top of the taskbar however, as I mention in my original question, using setting TopMost to true is not desirable in my app and without it the snippet does not work any longer.
myquestionoftheday
A: 

it's working now. My simple fix it turned out to be calling the form's Activate() method, so no need to use TopMost (which is what I was aiming at). Thanks to all for your help

myquestionoftheday