我有一个WindowStyle =“none”和WindowState = Maximized的窗口,现在我想在我的contextmenu中设置MenuItem将应用程序切换到另一个桌面。什么是一键更改桌面的最简单的方法
什么最简单的方法呢?
我有一个WindowStyle =“none”和WindowState = Maximized的窗口,现在我想在我的contextmenu中设置MenuItem将应用程序切换到另一个桌面。什么是一键更改桌面的最简单的方法
什么最简单的方法呢?
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Interop;
Screen screen = Screen.FromHandle(new WindowInteropHelper(this).Handle);
int i;
for (i = 0; i < Screen.AllScreens.Length; i++)
{
if (Screen.AllScreens[i] == screen) break;
}
i++; i = i % Screen.AllScreens.Length;
this.WindowState = WindowState.Normal;
int x = 0;
for (int j = 0; j < i; j++)
{
x += Screen.AllScreens[j].Bounds.Width;
}
this.Left = x + 1;
this.WindowState = WindowState.Maximized;
这将最大化的窗口移动到下一个监视器。我没有,虽然测试它,因为我只有一个显示器。移动的窗口中没有最大化是很难的,因为新显示器的尺寸不一定与旧显示器的尺寸相同,您可以不设置WindowState并将wi ndow在屏幕上,或者获取当前监视器上窗口的x位置并将其添加到新的x位置。使用后者时,您需要检查新位置是否仍在显示器内。
另外请注意,这只有在您的显示器设置为彼此相邻时才有效。监视器堆叠时这不起作用。
我已经在与的MouseLeftButtonDown点击最大化的窗口最小化,然后这个解决问题
,现在我可以拖动这个到其他屏幕。所述的MouseLeftButtonUp了Methode窗口最大化
private void win_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
click = new Point(e.GetPosition(this).X, e.GetPosition(this).Y);
win.WindowState = WindowState.Normal;
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{
this.Left += e.GetPosition(this).X - click.X;
this.Top += e.GetPosition(this).Y - click.Y;
}
private void win_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
win.WindowState = WindowState.Maximized;
}
THX @所有:)
THX,但不能在这里解决宽度:X + = Screen.AllScreens [j]的.WorkingArea.Width; – 2009-08-08 20:05:03
您需要将System.Windows.Forms和System.Drawing添加到您的程序集引用。 – Ruud 2009-08-08 20:05:35
我忘记了绘图...但现在是问题,这是短暂的闪烁,但不改变桌面 – 2009-08-08 20:10:31