jod*_*die 2 .net c# multiple-monitors
我正在寻找关于以下问题的一些提示或解决方案.
我有一个.NET 2.0 WinForm对话框,它在双屏幕环境中运行.工作区域由.NET Framework设置以反映主屏幕.我想最大化窗体到两个屏幕但是在单击"最大化按钮"后,对话框最大化到"活动"屏幕(活动我指的是当前放置对话框的屏幕).
我对边界解决方案不感兴趣,这很有效,但是当点击最大化按钮时,它会强制对话框回到2个屏幕之一.
我会感激任何帮助或提示.
合并2个屏幕尺寸并将表单设置为该分辨率.就像是:
int height = 0;
int width = 0;
foreach (screen in System.Windows.Forms.Screen.AllScreens)
{
//take smallest height
height = (screen.Bounds.Height <= height) ? screen.Bounds.Height: height;
width += screen.Bounds.Width;
}
Form1.Size = new System.Drawing.Size(width, height);
Run Code Online (Sandbox Code Playgroud)
要覆盖最大化按钮,您可以通过WndProc检查最大化事件
const int WM_SYSCOMMAND= 0x0112;
const int SC_MAXIMIZE= 0xF030;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if((int)m.WParam==SC_MAXIMIZE)
{
MessageBox.Show("Maximized!!");
return;
}
}
base.WndProc (ref m);
}
Run Code Online (Sandbox Code Playgroud)
或注册到表单的Resize事件(您应该检查它是否调整大小或最大化)(MSDN)
小智 5
这可能会迟到,但这是一个简单的方法.它设置表单的大小来获取分辨率的大小.然后它放置表单,使其可见.
int screenLeft = SystemInformation.VirtualScreen.Left;
int screenTop = SystemInformation.VirtualScreen.Top;
int screenWidth = SystemInformation.VirtualScreen.Width;
int screenHeight = SystemInformation.VirtualScreen.Height;
this.Size = new System.Drawing.Size(screenWidth, screenHeight);
this.Location = new System.Drawing.Point(screenLeft, screenTop);
Run Code Online (Sandbox Code Playgroud)