I have a window with WindowStyle="none" and WindowState=Maximized" and now I'd like in my contextmenu set the MenuItem to switch the application to the other desktop.
whats the simplest way to do that?
I have a window with WindowStyle="none" and WindowState=Maximized" and now I'd like in my contextmenu set the MenuItem to switch the application to the other desktop.
whats the simplest way to do that?
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;
This will move a maximised window to the next monitor. I didn't test it though as I have only one monitor. Moving a window that is not maximised is harder because the size of the new monitor is not necessarily the same as the size of the old monitor. You could leave out setting the WindowState and center the window on the screen, or get the x position of the window on the current monitor and add it to the new x position. When using the latter you need to check if the new position is still inside the monitor.
Also note that this only works if your monitors are set up next to each other. This will not work when monitors are stacked.
I've solve the problem
when click the maximized window with the MouseLeftButtonDown then minimized this and now can i drag this to the other screen. The MouseLeftButtonUp Methode maximized the window
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 : )