C# 单击一下就可以更改桌面的最简单方法是什么
我有一个带有WindowStyle=“none”和WindowState=Maximized”的窗口,现在我想在我的上下文菜单中设置菜单项以将应用程序切换到其他桌面 最简单的方法是什么?C# 单击一下就可以更改桌面的最简单方法是什么,c#,wpf,xaml,C#,Wpf,Xaml,我有一个带有WindowStyle=“none”和WindowState=Maximized”的窗口,现在我想在我的上下文菜单中设置菜单项以将应用程序切换到其他桌面 最简单的方法是什么?使用System.Windows.Forms; using System.Windows.Forms; using System.Drawing; using System.Windows.Interop; Screen screen = Scre
使用System.Windows.Forms;
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;
使用系统图;
使用System.Windows.Interop;
Screen Screen=Screen.FromHandle(新的WindowInteropHelper(this.Handle));
int i;
对于(i=0;i
这将把一个最大化的窗口移动到下一个监视器。我没有测试它,因为我只有一个监视器。移动一个未最大化的窗口比较困难,因为新监视器的大小不一定与旧监视器的大小相同。您可以省去设置窗口状态,在屏幕上居中显示窗口,或者获取x p将窗口放置在当前监视器上,并将其添加到新的x位置。使用后者时,需要检查新位置是否仍在监视器内
另外请注意,这仅在监视器相邻设置时有效。当监视器堆叠时,这将不起作用。我已经解决了这个问题
当用MouseLeftButtonDown单击最大化窗口时,然后将其最小化,现在我可以将其拖动到另一个屏幕。MouseLeftButtonUp方法使窗口最大化
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@all:)thx,但无法解析此处的宽度:x+=Screen.AllScreens[j].WorkingArea.Width;您需要将System.Windows.Forms和System.Drawing添加到您的程序集引用中。我忘记了图形…但现在是问题所在,这是短闪烁,但不要更改桌面对不起,我无法帮助您,因为我无法自己测试它。代码应该可以让您开始开发自己的方法;您可以获得像这样的屏幕。我想这是因为我激活的屏幕有数字1和3,而2被禁用,坐标的计算是错误的