Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to have an empty form window, but using the tool window style. However, calling Show() results in the following exception:

Win32Exception: The parameter is incorrect.

NativeErrorCode: 87

at System.Windows.Forms.Form.UpdateLayered() at System.Windows.Forms.Control.WmCreate(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Form.WmCreate(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Error code 87 is ERROR_INVALID_PARAMETER.

private class ToolForm : Form {
    public ToolForm() {
        AllowTransparency = true;
        BackColor = System.Drawing.Color.FromArgb(0, 0, 1);
        TransparencyKey = BackColor;
    }

    private const int WS_EX_TOOLWINDOW = 0x00000080;
    protected override CreateParams CreateParams {
        get {
            var cp = base.CreateParams;
            cp.ExStyle = WS_EX_TOOLWINDOW;
            return cp;
        }
    }
}

Edit:

This works:

public class ToolForm : Form {
    public ToolForm() {
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
        this.AllowTransparency = true;
        this.BackColor = Color.FromArgb(0, 0, 1);
        this.TransparencyKey = this.BackColor;
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
173 views
Welcome To Ask or Share your Answers For Others

1 Answer

First try using an OR-assignment instead of plain assignment:

cp.ExStyle |= WS_EX_TOOLWINDOW;

If that doesn't work, you can try additionally OR'ing some of these related styles:

cp.ExStyle |= ( int )(
  WS_EX_LAYERED |
  WS_EX_TRANSPARENT |
  WS_EX_NOACTIVATE |
  WS_EX_TOOLWINDOW );

The associated values are:

WS_EX_LAYERED = 0x00080000,
WS_EX_NOACTIVATE = 0x08000000,
WS_EX_TOOLWINDOW = 0x00000080,
WS_EX_TRANSPARENT = 0x00000020

The WS_EX_TRANSPARENT flag may possibly allow the transparency you want without requiring the TransparencyKey = BackColor; line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...