日期:2014-05-18  浏览次数:20646 次

麻烦大家发下C#让winform全屏运行的代码
百度了,看到有说调用API的,还有设置form.size的。对于API这个我不怎么懂,有高手发下带注释的代码吗?

------解决方案--------------------
C# code
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace GlobalTechnologyInc.SnmpProject.CustomClass
{
    /// <summary>
    /// Selected Win AI Function Calls
    /// </summary>

    class WindowsFullScreenApi
    {
        [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
        public static extern int GetSystemMetrics(int which);

        [DllImport("user32.dll")]
        public static extern void
            SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
                         int X, int Y, int width, int height, uint flags);

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

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

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

        public static void SetWinFullScreen(IntPtr hwnd)
        {
            SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
        }
    }
}