开发者

Windows Forms: Enable/Disable WS_CLIPCHILDREN

How do I turn on/off the WS_CLIPCHILDREN window style in a Windows Forms parent control?

I would like to display some text on top of the child control after it has painted. In my parent control, this is what I have:

class Parent : public Control {
    void Parent::OnPaint(PaintEventArgs ^e){
        Control::OnPaint(e);

        // parent draws here
        // some drawing should happen over the child windows
        // in other words, do not clip child window regions
    }
};

On chec开发者_StackOverflow中文版king with Spy++ I find that the parent has the WS_CLIPCHILDREN window style enabled by default. What is the Windows Forms way to turn this off?

Note: Sample code is in C++/CLI but I have tagged this C# for visibility... language is immaterial here. Feel free to translate the code to C#.


You might be able to do this by overriding the CreateParams property of your parent control:

protected override CreateParams CreateParams {
    get {
        new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();

        // Modify the existing style.
        CreateParams cp = base.CreateParams;
        // Remove the WS_CLIPCHILDREN flag.
        cp.Style &= ~0x02000000; // WS_CLIPCHILDREN value.

        return cp;
    }
}


You can try removing the style directly using P/Invoke using the SetWindowLong function. Use Form.Handle property as the window handle.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜