我想在全屏模式下运行WPF应用程序。对于我用下面的代码this project:如何从最大化的WPF窗口中删除边框?
class WinApi
{
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int which);
[DllImport("user32.dll")]
public static extern void
SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int X, int Y, int width, int height, uint flags);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private static IntPtr HWND_TOP = IntPtr.Zero;
private const int SWP_SHOWWINDOW = 64; // 0×0040
public static int ScreenX
{
get { return GetSystemMetrics(SM_CXSCREEN);}
}
public static int ScreenY
{
get { return GetSystemMetrics(SM_CYSCREEN);}
}
public static void SetWinFullScreen(IntPtr hwnd)
{
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
}
}
在主.cs文件我写了下面的代码:
private void window1_KeyUp(object sender, KeyEventArgs e)
{
if(e.Key == Key.F)
{
if(!isFullScreen)
{
height = mePlayer.Height;
width = mePlayer.Width;
this.BorderThickness = new Thickness(0.0);
this.Background = new SolidColorBrush(Colors.Black);
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
this.Topmost = true;
WinApi.SetWinFullScreen(new WindowInteropHelper(this).Handle);
isFullScreen = !isFullScreen;
}
else
{
this.Topmost = false;
this.Background = new SolidColorBrush(Colors.White);
this.WindowStyle = WindowStyle.SingleBorderWindow;
isFullScreen = !isFullScreen;
}
}
}
的问题是,当我切换到全屏,我避开这个边界如下面的截图所示的窗口:
如何删除边界?另一个问题是在恢复到原始状态后,窗口周围出现一个细小的虚线边框。如何删除呢?
你试过'拉伸= “UniformToFill”'在'MediaElement'? –
为什么不只是创建一个窗口'AllowsTransparency =“True”WindowStyle =“None”'调整到屏幕坐标并将其放在屏幕的左上角? – Benj
@Bahman_Aries我试着说你的话。我得到了和以前一样的结果。 –