Disable Close Button In Title Bar of a WPF Window (C#) -
i'd know how disable (not remove/hide) close button in wpf window. know how hide makes window's title bar this:
but want disable meaning should this:
i'm scripting in c# , using wpf (windows presentation foundation).
try this:
public partial class mainwindow : window { [dllimport("user32.dll")] static extern intptr getsystemmenu(intptr hwnd, bool brevert); [dllimport("user32.dll")] static extern bool enablemenuitem(intptr hmenu, uint uidenableitem, uint uenable); const uint mf_bycommand = 0x00000000; const uint mf_grayed = 0x00000001; const uint mf_enabled = 0x00000000; const uint sc_close = 0xf060; const int wm_showwindow = 0x00000018; const int wm_close = 0x10; public mainwindow() { initializecomponent(); } private void window_loaded(object sender, routedeventargs e) { } protected override void onsourceinitialized(eventargs e) { base.onsourceinitialized(e); hwndsource hwndsource = presentationsource.fromvisual(this) hwndsource; if (hwndsource != null) { hwndsource.addhook(new hwndsourcehook(this.hwndsourcehook)); } } intptr hwndsourcehook(intptr hwnd, int msg, intptr wparam, intptr lparam, ref bool handled) { if (msg == wm_showwindow) { intptr hmenu = getsystemmenu(hwnd, false); if (hmenu != intptr.zero) { enablemenuitem(hmenu, sc_close, mf_bycommand | mf_grayed); } } else if (msg == wm_close) { handled = true; } return intptr.zero; } }
(taken here: http://blogs.microsoft.co.il/blogs/tamir/archive/2007/09/26/never-ever-close-me-how-to-disable-close-button-in-wpf.aspx)
make sure set resizemode
noresize
.
Comments
Post a Comment