c# - How to remove border from a maximized WPF window? -
i want run wpf application in fullscreen mode. used following code this project:
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 { { return getsystemmetrics(sm_cxscreen);} } public static int screeny { { return getsystemmetrics(sm_cyscreen);} } public static void setwinfullscreen(intptr hwnd) { setwindowpos(hwnd, hwnd_top, 0, 0, screenx, screeny, swp_showwindow); } }
in main .cs file wrote following code:
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; } } }
the problem when switch fullscreen, border around window shown in screenshot below:
how remove border? issue thin dotted border around window after restore original state. how remove also?
create new wpf-application , use following code mainwindow
xaml
<window x:class="wpfapplication1.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525" keydown="keyhandler_f" allowstransparency="true" windowstyle="none" > <grid> <grid.rowdefinitions> <rowdefinition height="200" /> <rowdefinition height="*" /> </grid.rowdefinitions> <textblock grid.row="0" verticalalignment="center" horizontalalignment="center"> press <run fontsize="60" foreground="red">f</run> toggle between fullscreen , window-screen </textblock> <textblock grid.row="1" margin="10" textwrapping="wrap">you need create own title-bar , minimize/ maximize/ close buttons on window seen in microsoft visual studio 2013. alternatively can create new window when switching fullscreen</textblock> </grid> </window>
code behind
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; namespace wpfapplication1 { /// <summary> /// interaction logic mainwindow.xaml /// </summary> public partial class mainwindow : window { public mainwindow() { initializecomponent(); } private void button_click(object sender, routedeventargs e) { this.togglewindow(); } private void keyhandler_f(object sender, keyeventargs e) { if(e.key == key.f) { this.togglewindow(); } } private void togglewindow() { switch (this.windowstate) { case (windowstate.maximized): { this.windowstate = windowstate.normal; } break; default: { this.windowstate = windowstate.maximized; } break; } } } }
the window behave this:
both screenshots of entire screen
Comments
Post a Comment