Cancel A WinForm Minimize?

旧街凉风 提交于 2019-12-01 05:44:18

You could probably catch them changing it in the SizeChanged event and check the WindowState, if its been set to Minimized then set it back Normal. Not the most elegant solution but should work.

eg.

private void myForm_SizeChanged(object sender, System.EventArgs e)
{
   if (myForm.WindowState == FormWindowState.Minimized)
   {
       myForm.WindowState = FormWindowState.Normal;
   }
}
Jay Riggs

Override WndProc on your form, listen for minimize messages and cancel.

Add this code to your form:

private const int WM_SYSCOMMAND = 0x0112; 
private const int SC_MINIMIZE = 0xf020; 

 protected override void WndProc(ref Message m) 
{ 
    if (m.Msg == WM_SYSCOMMAND) 
    { 
        if (m.WParam.ToInt32() == SC_MINIMIZE) 
        { 
            m.Result = IntPtr.Zero; 
            return; 
        } 
    } 
    base.WndProc(ref m); 
} 

I modified Rob's code found in this SO thread:
How to disable the minimize button in C#?

Works great: no flickering, no nothing when the user attempts to minimize.

If it's suitable for you, just hide it from the taskbar: ShowInTaskbar=false

you can simply remove the minimize button from the window:

add the code below to the private void InitializeComponent() method of the Form class:

            this.MinimizeBox = false;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!