解决方法
我阅读了您对我的回复的评论,并为您提供了更完整的解决方案.我跑得很快,似乎有你想要的行为.而不是从Form派生你的
winforms,而是派生自这个类:
using System; using System.Windows.Forms; using System.ComponentModel; namespace NoMinimizeTest { public class MinimizeControlForm : Form { private const int WM_SYSCOMMAND = 0x0112; private const int SC_MINIMIZE = 0xf020; protected MinimizeControlForm() { AllowMinimize = true; } protected override void WndProc(ref Message m) { if (!AllowMinimize) { if (m.Msg == WM_SYSCOMMAND) { if (m.WParam.ToInt32() == SC_MINIMIZE) { m.Result = IntPtr.Zero; return; } } } base.WndProc(ref m); } [browsable(true)] [Category("Behavior")] [Description("Specifies whether to allow the window to minimize when the minimize button and command are enabled.")] [DefaultValue(true)] public bool AllowMinimize { get; set; } } }
如果您希望能够在发送点击时决定是否允许最小化,则可以执行更多操作,例如:
using System; using System.Windows.Forms; using System.ComponentModel; namespace NoMinimizeTest { public class MinimizeControlForm : Form { private const int WM_SYSCOMMAND = 0x0112; private const int SC_MINIMIZE = 0xf020; protected MinimizeControlForm() { } protected override void WndProc(ref Message m) { if (m.Msg == WM_SYSCOMMAND) { if (m.WParam.ToInt32() == SC_MINIMIZE && !CheckMinimizingallowed()) { m.Result = IntPtr.Zero; return; } } base.WndProc(ref m); } private bool CheckMinimizingallowed() { CancelEventArgs args = new CancelEventArgs(false); OnMinimizing(args); return !args.Cancel; } [browsable(true)] [Category("Behavior")] [Description("Allows a listener to prevent a window from being minimized.")] public event CancelEventHandler Minimizing; protected virtual void OnMinimizing(CancelEventArgs e) { if (Minimizing != null) Minimizing(this,e); } } }
有关此窗口通知的更多信息,请参阅MSDN article about it.
原文地址:https://www.jb51.cc/csharp/98692.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。