How to hide close button in WPF window? -


i'm writing modal dialog in wpf. how set wpf window not have close button? i'd still windowstate have normal title bar.

i found resizemode, windowstate, , windowstyle, none of properties allow me hide close button show title bar, in modal dialogs.

wpf doesn't have built-in property hide title bar's close button, can few lines of p/invoke.

first, add these declarations window class:

private const int gwl_style = -16; private const int ws_sysmenu = 0x80000; [dllimport("user32.dll", setlasterror = true)] private static extern int getwindowlong(intptr hwnd, int nindex); [dllimport("user32.dll")] private static extern int setwindowlong(intptr hwnd, int nindex, int dwnewlong); 

then put code in window's loaded event:

var hwnd = new windowinterophelper(this).handle; setwindowlong(hwnd, gwl_style, getwindowlong(hwnd, gwl_style) & ~ws_sysmenu); 

and there go: no more close button. won't have window icon on left side of title bar, means no system menu, when right-click title bar -- go together.

note alt+f4 still close window. if don't want allow window close before background thread done, override onclosing , set cancel true, gabe suggested.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -