先看效果
- 无边框
设置WindowStyle=“None”,窗口无关闭及缩放按钮,但还有黑边;设置AllowsTransparency=“True”,黑边没有了。 - 全屏,遮住任务栏
this.WindowState = System.Windows.WindowState.Normal;
this.WindowStyle = System.Windows.WindowStyle.None;
this.ResizeMode = System.Windows.ResizeMode.NoResize;
//this.Topmost = true;
//设置全屏
this.Left = 0.0;
this.Top = 0.0;
this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
- 拖动
//xaml
MouseMove="Move_MouseMove"
//cs
private void Move_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
- 另一种拖动方式
不能拖动太快
System.Drawing.Point MouseCursor_Point;
System.Drawing.Point MouseCursor_Point_Aux;
double mTop = 0;
double mLeft = 0;
private void Button_MouseMove(object sender, MouseEventArgs e)
{
if (e.RightButton == MouseButtonState.Pressed)
{
if (rightMouseDown)
{
MouseCursor_Point_Aux = System.Windows.Forms.Cursor.Position;
this.Left = this.mLeft + MouseCursor_Point_Aux.X - MouseCursor_Point.X;
this.Top = this.mLeft + MouseCursor_Point_Aux.Y - MouseCursor_Point.Y;
Console.WriteLine($"({this.Left},{this.Top})");
}
else
{
rightMouseDown = true;
mTop = this.Top;
mLeft = this.Left;
MouseCursor_Point = System.Windows.Forms.Cursor.Position;
}
}
else
{
rightMouseDown = false;
}
}
或者,这种需要慢点拖,否则会有问题
System.Drawing.Point MouseCursor_Point;
System.Drawing.Point MouseCursor_Point_Aux;
private void Button_MouseMove(object sender, MouseEventArgs e)
{
if (e.RightButton == MouseButtonState.Pressed)
{
MouseCursor_Point_Aux = System.Windows.Forms.Cursor.Position;
this.Left += MouseCursor_Point_Aux.X - MouseCursor_Point.X;
this.Top += MouseCursor_Point_Aux.Y - MouseCursor_Point.Y;
}
MouseCursor_Point = System.Windows.Forms.Cursor.Position;
}