读书人

C# 全屏实现,该怎么处理

发布时间: 2012-05-28 17:59:33 作者: rapoo

C# 全屏实现
就和虚拟机一样的,全屏显示的时候只显示视图区域内容,当鼠标移动到某一位置时出现浮动菜单,可以退出全屏或者其他操作!

[解决办法]
http://msdn.microsoft.com/en-us/library/aa453694.aspx
[解决办法]
把窗体模式设置为没有标题栏的那种 然后最大化出来的就是全屏了
[解决办法]

探讨
引用:
把窗体模式设置为没有标题栏的那种 然后最大化出来的就是全屏了

C# codethis.FormBorderStyle= FormBorderStyle.None;this.WindowState= FormWindowState.Maximized;

你说的这样吧,菜单、状态栏工具栏什么的都在的
我想要的是虚拟机的那效果或者播放器全屏时的那效果!

[解决办法]
C# codethis.FormBorderStyle= FormBorderStyle.None;this.WindowState= FormWindowState.Maximized;

[解决办法]
老外的一个全屏,使用方法:
FormState formState = new FormState();
this.SetVisibleCore(false);
formState.Maximize(this);
this.SetVisibleCore(true);

C# code
using System;using System.Drawing;using System.Windows.Forms;using System.Runtime.InteropServices;namespace LC_Game{    /// <summary>    /// Selected Win AI Function Calls    /// </summary>        public class WinApi    {        [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);        }    }        /// <summary>    /// Class used to preserve / restore state of the form    /// </summary>    public class FormState    {        private FormWindowState winState;        private FormBorderStyle brdStyle;        private bool topMost;        private Rectangle bounds;        private bool IsMaximized = false;        public void Maximize(Form targetForm)        {            if (!IsMaximized)            {                IsMaximized = true;                Save(targetForm);                targetForm.WindowState = FormWindowState.Maximized;                targetForm.FormBorderStyle = FormBorderStyle.None;                targetForm.TopMost = true;                WinApi.SetWinFullScreen(targetForm.Handle);            }        }                public void Save(Form targetForm)        {            winState = targetForm.WindowState;            brdStyle = targetForm.FormBorderStyle;            topMost = targetForm.TopMost;            bounds = targetForm.Bounds;        }        public void Restore(Form targetForm)        {            targetForm.WindowState = winState;            targetForm.FormBorderStyle = brdStyle;            targetForm.TopMost = topMost;            targetForm.Bounds = bounds;            IsMaximized = false;        }    }}
[解决办法]
据说Visual C#初学者工具包中有个屏保程序
屏保程序肯定是要全屏的,楼主不妨参考下

单是无边框窗体最大化是无法实现的,
隐藏控件还要把桌面的任务栏给隐藏吧
------解决方案--------------------


已经隐藏了任务栏了,和改变刷新率一起用,就能达到类似游戏全屏的效果。
[解决办法]
锁屏吧?样式先设成NONE,然后获取当前系统分辨率,按分辨率来设置长、宽,再设置成ISTOP,就OK了。别说不成,魔兽都是这样弄的,只不过是把电脑分辨率设置为窗体长宽。
[解决办法]
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;

[解决办法]
把窗体的TopMost属性设置为True,然后根据你要显示的区域计算窗体的Top和Left属性的值。细节的部分要怎么处理我就不说了先。
[解决办法]

探讨
老外的一个全屏,使用方法:
FormState formState = new FormState();
this.SetVisibleCore(false);
formState.Maximize(this);
this.SetVisibleCore(true);

C# codeusing System;using System.Drawing;using System.Windows.Forms;using System.Runtime.InteropServices;namespace LC_Game
{///<summary>/// Selected Win AI Function Calls///</summary>publicclass WinApi
{
[DllImport("user32.dll", EntryPoint="GetSystemMetrics")]publicstaticexternint GetSystemMetrics(int which);

[DllImport("user32.dll")]publicstaticexternvoid
SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,int X,int Y,int width,int height,uint flags);privateconstint SM_CXSCREEN=0;privateconstint SM_CYSCREEN=1;privatestatic IntPtr HWND_TOP= IntPtr.Zero;privateconstint SWP_SHOWWINDOW=64;// 0x0040publicstaticint ScreenX
{get {return GetSystemMetrics(SM_CXSCREEN);}
}publicstaticint ScreenY
{get {return GetSystemMetrics(SM_CYSCREEN);}
}publicstaticvoid SetWinFullScreen(IntPtr hwnd)
{
SetWindowPos(hwnd, HWND_TOP,0,0, ScreenX, ScreenY, SWP_SHOWWINDOW);
}
}///<summary>/// Class used to preserve / restore state of the form///</summary>publicclass FormState
{private FormWindowState winState;private FormBorderStyle brdStyle;privatebool topMost;private Rectangle bounds;privatebool IsMaximized=false;publicvoid Maximize(Form targetForm)
{if (!IsMaximized)
{
IsMaximized=true;
Save(targetForm);
targetForm.WindowState= FormWindowState.Maximized;
targetForm.FormBorderStyle= FormBorderStyle.None;
targetForm.TopMost=true;
WinApi.SetWinFullScreen(targetForm.Handle);
}
}publicvoid Save(Form targetForm)
{
winState= targetForm.WindowState;
brdStyle= targetForm.FormBorderStyle;
topMost= targetForm.TopMost;
bounds= targetForm.Bounds;
}publicvoid Restore(Form targetForm)
{
targetForm.WindowState= winState;
targetForm.FormBorderStyle= brdStyle;
targetForm.TopMost= topMost;
targetForm.Bounds= bounds;
IsMaximized=false;
}
}
}

[解决办法]
探讨
C# codethis.FormBorderStyle= FormBorderStyle.None;this.WindowState= FormWindowState.Maximized;


[解决办法]
探讨
据说Visual C#初学者工具包中有个屏保程序
屏保程序肯定是要全屏的,楼主不妨参考下

单是无边框窗体最大化是无法实现的,
隐藏控件还要把桌面的任务栏给隐藏吧

读书人网 >C#

热点推荐