栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

wpfbutton按钮禁用

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

wpfbutton按钮禁用

尝试这个:

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) as 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;

}

}

确保将ResizeMode设置为NoResize.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/955215.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号