代码之家  ›  专栏  ›  技术社区  ›  Agnel Kurian

Windows窗体:启用/禁用WS-ClipChildren

  •  1
  • Agnel Kurian  · 技术社区  · 15 年前

    如何在windows窗体父控件中打开/关闭ws_clipchildren窗口样式?

    我想在子控件绘制后在其顶部显示一些文本。在我父母的控制下,这就是我所拥有的:

    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
        }
    };
    

    在使用spy++进行检查时,我发现父对象默认启用了ws_clipchildren窗口样式。Windows窗体关闭此功能的方法是什么?

    注: 示例代码是在C++/CLI中,但我已经标记了这个C的可见性…语言在这里是无关紧要的。请随意将代码翻译成c。

    2 回复  |  直到 15 年前
        1
  •  1
  •   Mark    15 年前

    您可以通过重写 CreateParams 父控件的属性:

    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;
        }
    }
    
        2
  •  0
  •   logicnp    15 年前

    您可以尝试使用p/invoke使用setwindowlong函数直接删除样式。使用form.handle属性作为窗口句柄。

    推荐文章