在其他计算机上运行应用程序时,自定义控件不会出现

本文关键字:自定义控件 计算机 其他 运行 应用程序 | 更新日期: 2023-09-27 18:26:37

我设计了一个单选按钮自定义控件。它在我的电脑上运行良好,但当我将应用程序移植到另一台机器上时,它不会出现。

任何人都知道为什么?

这是我控制的一部分:

public class CustomCheckBox:UserControl
{
    public CustomCheckBox()
    {
     // Height+=50;
      count++;
      index = count;
      Height = 50;
      Width = 100;
      Region r = new Region(new Rectangle( 0, 0, Width, Height));
      this.Region = r;
      this.SetStyle(ControlStyles.ResizeRedraw, true);

    }
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
            // cp.Style &= ~0x02000000;
            return cp;
        }
    } 
    protected override void OnMouseLeave(EventArgs e)
    {
        paintState = 0;            
        base.OnMouseLeave(e);
        this.Invalidate();
    }
  ...

在其他计算机上运行应用程序时,自定义控件不会出现

正如Hans Passant在上面评论的那样,我删除了WS_EX_COMPOSITED样式标志,该标志用于应用绘图优化来消除外观上的闪烁,而我在构造函数中使用了这种优化,效果很好。

      this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
      this.SetStyle(ControlStyles.CacheText, true);
      this.SetStyle(ControlStyles.ContainerControl, false);
      this.SetStyle(ControlStyles.ResizeRedraw, false);
      this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
      this.SetStyle(ControlStyles.FixedHeight, true);
      this.SetStyle(ControlStyles.FixedWidth, true);