Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Full-Screen Application

Yesterday 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 reckon it’s a good idea to do that anyway. Thanks Scott for the suggestion. ;) And thanks Phil for pointing me in the right direction with the DLL import stuff. :)

So, without any mucking about here’s the exact same complete application example only this time in C#. You can download the application’s source on the Digital Formula Downloads page or, alternatively, from the application source’s direct link. For those that want to see the main form’s complete source before they download, it can be found at the end of this article.

Please feel to ask any questions necessary. Thanks!

Form1’s complete source:

[code lang=”csharp”] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices;

namespace Play { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

[DllImport (“user32.dll”)] private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndIntertAfter, int X, int Y, int cx, int cy, int uFlags); [DllImport(“user32.dll”)] private static extern int GetSystemMetrics(int Which);

private const int SM_CXSCREEN = 0; private const int SM_CYSCREEN = 1; private IntPtr HWND_TOP = IntPtr.Zero; private const int SWP_SHOWWINDOW = 64;

public int ScreenX { get { return GetSystemMetrics(SM_CXSCREEN); } }

public int ScreenY { get { return GetSystemMetrics(SM_CYSCREEN); } }

private void FullScreen() { this.WindowState = FormWindowState.Maximized; this.FormBorderStyle = FormBorderStyle.None; this.TopMost = true; SetWindowPos(this.Handle, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW); }

private void Restore() { this.WindowState = FormWindowState.Normal; this.FormBorderStyle = FormBorderStyle.SizableToolWindow; this.TopMost = false; }

private void button1_Click(object sender, EventArgs e) { FullScreen(); }

private void cmdRestore_Click(object sender, EventArgs e) { Restore(); }

private void cmdExit_Click(object sender, EventArgs e) { Application.Exit(); } } } [/code]

출처 : http://digitalformula.net/development/c-full-screen-application-complete-application-example/

Leave a Reply

Your email address will not be published. Required fields are marked *