C# 在其他计算机上运行应用程序时,自定义控件不显示
我设计了一个单选按钮自定义控件。它在我的计算机上运行良好,但当我将我的应用程序移植到另一台计算机上时,它不会出现 有人知道为什么吗 这是我控制的一部分:C# 在其他计算机上运行应用程序时,自定义控件不显示,c#,.net,user-controls,custom-controls,C#,.net,User Controls,Custom Controls,我设计了一个单选按钮自定义控件。它在我的计算机上运行良好,但当我将我的应用程序移植到另一台计算机上时,它不会出现 有人知道为什么吗 这是我控制的一部分: public class CustomCheckBox:UserControl { public CustomCheckBox() { // Height+=50; count++; index = count; Height = 50; Width = 100;
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();
}
...
如上所述解决的问题,我删除了WS_EX_COMPOSITED style标志,该标志用于应用图形优化以消除外观上的闪烁,相反,我在构造函数中使用了这种优化,效果很好
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);
WS_EX_COMPOSITED style标志仅在顶级窗口上有效,而在控件上无效。顺便说一句,这里需要署名。谢谢,你说得对。