简体   繁体   中英

Windows Forms dialog icon without control box

I'm wondering is there a way to have icon in upper left corner of my custom dialog while control box, minimize box and maximize box are disabled? I don't need to have any functionality when icon is clicked (about, close, move, etc..) . I just want it for nicer look.

No control box => No icon...

When ControlBox is disabled, form windowstyle WS_SYSMENU flag is (somehow in a far out manner) dropped and so it becomes impossible for Windows to show an icon. Actually I haven't found the final explanation on why (&how) the upper-right corner icons continue to exist w/o WS_SYSMENU... but found one more nice solution that fits your needs)

    private const int GWL_STYLE = -16;
    private const int WS_CLIPSIBLINGS = 1 << 26;

    [DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")]
    public static extern IntPtr SetWindowLongPtr32(HandleRef hWnd, int nIndex, HandleRef dwNewLong);
    [DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "GetWindowLong")]
    public static extern IntPtr GetWindowLong32(HandleRef hWnd, int nIndex);

    protected override void OnLoad(EventArgs e) {
        int style = (int)((long)GetWindowLong32(new HandleRef(this, this.Handle), GWL_STYLE));
        SetWindowLongPtr32(new HandleRef(this, this.Handle), GWL_STYLE, new HandleRef(null, (IntPtr)(style & ~WS_CLIPSIBLINGS)));

        base.OnLoad(e);
    }

you can set ControlBox property to false. Control Box , maximize, minimize buttons will not show in the dialog box.

Form1.ControlBox = false;

OR else you can set like this, if you not willing to disable whole control box. you can set ShowIcon property to true.

Form1.MaximizeBox = false;
Form1.MinimizeBox = false;
Form1.ShowIcon=true; 

You can always add an Image control in the upper left corner and assign the icon to it. Would that help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM