Recently I had to write a Windows application that required the main form to run in full-screen mode. This means no title bar and with the window appearance above everything else, i.e. Start Button, taskbar, system tray and all other apps.
2009/08/29 Update – Complete application example & source now available for download from the Digital Formula Downloads page!
This requires an API call to the SetWindowPos function which you need to create an alias to before you can call it. The first part of the code, which should be placed in the declarations part of the form, looks like this :
You also need an alias to the API function called GetSystemMetrics, like this :
Following this you need to declare 4 constants :
Then 2 public properties :
After this you need to write a simple sub routine to use the constants you declared above and that calls the SetWindowPos API function. The function’s code looks like this :
Beyond that it’s just a case of calling the FullScreen sub routine whenever you want the application to show in full-screen mode.
Thanks, I’ve been looking all over for this
No problem, thanks for the comment.
Perfect.. bless u vb guru’s…
i love google!
good code man, but u dident make for restore mode
This is Maximize mode not Full-screen mode.
As far as I’m aware this IS full-screen mode. There are no titlebars and the Windows taskbar doesn’t show up at all. If anyone has further comments about this article please leave your email address so I can respond – thanks.
- Chris
How do you do to return to normal mode??
I’ve had a couple of requests for the method to change back to normal/restore mode for the application window. The method below will do this for you.
Public Sub NormalMode()
‘ restore the window size back to default
Me.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
Me.FormBorderStyle = FormBorderStyle.SizableToolWindow
‘ change the window so it’s not the on top
Me.TopMost = False
End Sub
Note that this method is basically the reverse of the FullScreen() method described above but without the use of the SetWindowPos call.
Please ask if you have any questions about the above code.
Thanks Chris, It works fine.. but i don’t want the form to be on the topmost, Bcz I am writing a program that plays Microsoft Character agents.. i want the agent to be on the top.. Is there a way to solve this??
thank you
Mahroof
Yeah, I got it.. It was there in ur last comment
me.topmost = false
Thanks
Now, if only someone made a small program that would make other applications run in full screen non-natively…
Thanx, both the fullscreen() and normalmode() work out perfectly!
very thanx fullscreen perfect !
Thanks for your helpful code. It works well if my application on the primary monitor. However, when I moved the application on the extent monitor, the application disappeared. How can I get the screenX, ScreenY for the extent monitor?
Yeash! I solved the problem.
Hey.. for long days i was looking for this code.. but i dont know how to use it..
can i get already u written project?
anybody. plz send me. if you have
plz mail me jinuem@gmail.com
jinuem: I have created a tiny VB.NET 3.5 application that shows exactly how to use the code explained in this article. You can download it by browsing to the Digital Formula Downloads page. Hope that helps.
thanks alot.. its very usefull
jinuem: Great, I’m glad the source could help you out.
Thanks for this, But, How do you do a fullscreen in Dual Monitor?
KK: Do you mean an application that is full-screen across both monitors? Or full-screen only on the 2nd monitor?
Hi Chris.. sorry for the late reply.. it should be full-screen across both monitors.
Hi Chris..
Your code works perfectly.. the reason it gave me some problems was because i was not set to “Horizontal span” – My Bad
Thank you for this code.
ok.. no i have a problem… teacher doesn’t want a “HORIZONTAL VIEW” and that she’s sticking with the “DUALVIEW”
your code…
1. in Horizontal Span – it treats it like a single monitor only.
2. in DUALVIEW – it treat 1 monitor as a single monitor and the 2nd monitor another monitor which in this case is not showing anything.
I’m not sure I understand what you mean. On my 2nd monitor the application still displays full-screen just fine. Do you want to have an application that is full-screen across *both* monitors?
Thank you for your code.
I have learnt to develop a full screen web browser. If a page try to open another window, how could I do to bring or show this window back to my browser window?
Thanks.
john: The sample application contains code for a button to return the application from full-screen mode to window mode. You could use this although I’m not sure if this is exactly what you want. Can you explain more?
Thank you for your answer, Chris.
My problem is:
Most web pages have some links inside. Some linked pages are set to be shown in _self page, in this way, the new web page will not open a new window. Some other pages will show in _blank page, which will open a new window for the new page. The first sort of pages will be good for my full screen web browser, the second ones cause some problems. They will open another window, which will not stay in my full screen window any more. My question is how we could prevent those pages from opening another window. Any pages have to be shown in _self window.
john: Ok, I see what you mean. _blank is an HTML standard identifier and unless you write code to specifically block it I don’t think you’ll be able to it them opening in a new window. If you really wanted to start hacking web page’s code to pieces you could load the page source into a string (or StringBuilder even) and replace all occurrences of _blank with _top or _self … you’d be changing how the designer of the web page wanted the site/page to behave though. Are you using one of the .NET web browser controls or have you written your own to handle the entire HTTP protocol conversation?
Chris,
Thanks a lot.
I use vb webbrowser control. If I could not make those _blank link to go back to _self, my whole project will be failed. You suggest about StringBuilder is a very good idea, however, I have not found a way to do it.
john: Well, it would be a case of getting the source of the page you’re viewing, assigning it to a StringBuilder object, then using StringBuilder.Replace (http://msdn.microsoft.com/en-us/library/3h5afh4w.aspx) to replace all occurrences of _blank with _self. You’d then need to RELOAD the content of your web browser control using the modified source you’ve got.
If you haven’t used StringBuilder before note that you have to create a new instance of StringBuilder before you do anything with it otherwise you’ll get null reference exceptions.
Here are some links that may help you (I’m pasting these here as I’ve never explicitly done what you’re asking and don’t have time to work it out for you right now, sorry).
http://bytes.com/topic/visual-basic-net/answers/462389-view-source-webbrowser-2005-a
http://support.microsoft.com/kb/311288/en-us
Chris,
Thank you very much.
Your links are very useful.
john: No problem. I’m interested to hear how it turns out, if you are interested in sharing.
It is a bad practice.
I recorded the downloaded web file in a file, and then use replace method in msdn to replace those _blank to _self. This part is OK, but after reload this web page, I find that we go to a wrong direction. The page is reloaded from my computer, not from its own server, it looks OK, but not.
I am trying another direction now. I think when those _blank pages clicked, there will be new pages opened. I should get their name, url, hwnd; and then reload page by using url to my browser, at the same time, send a message to close the opened web page.
I do not familiar with API programming. I am learning it now. Tell you what is going on later.
Thank you again for your help.
Hi, Chris,
Someone help me to find this?
http://msdn.microsoft.com/en-us/library/aa770041(VS.85).aspx#Controlling_New_Windows
I do not understand it. Could you help me?
john: I’m not 100% sure having never done it before but I think that’s C or C++ … I can’t help with that, sorry.
Thx dude i’ve been looking for this all those other sites have no true fullscreen examples but you did it thx again
Thanks, you did a wonderful job.
Hey, wonderful, but can I ask you how to do a fullscreen mode like the one that appear clicking on the square button next to the red “X” on top-right on the application? I mean the “X” that close the windows. Sorry for bad English, I’m italian :S
[...] I posted a quick update to an article I wrote back in 2007 entitled How to make a full-screen Windows app using VB.NET. Aside from 1 or 2 people saying “Oh man why don’t you be a man and write it using C#?” I [...]