开发者

Can a windows form display the min and max buttons without the close button?

Is there any way (in C开发者_开发技巧#) to display a form with just the minimise and maximise buttons? Without the close button?

The only way of removing the close button (that I'm aware of) is:

form.ControlBox = false;

But this also gets rid of both the other buttons.


I wrote a function to do this once

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
        if (EnableMenuItem(GetSystemMenu(this.Handle, 0), SC_CLOSE, MF_GRAYED) == -1)
            throw new Win32Exception("The message box did not exist to gray out its X");
    }
    private const int SC_CLOSE = 0xF060;
    private const int MF_GRAYED = 0x1;
    [DllImport("USER32")]
    internal static extern int EnableMenuItem(IntPtr WindowHandle, int uIDEnableItem, int uEnable);
    [DllImport("USER32")]
    internal static extern IntPtr GetSystemMenu(IntPtr WindowHandle, int bReset);
}

Note alt-f4 still works and right click "close this window" when you are looking at it from the task bar. (tested in windows 7)


There's an article here showing how to do that. It requires using the unmanaged User32.dll

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜