【发布时间】:2012-01-31 20:55:46
【问题描述】:
我使用 C#、VisualStudio 2010 并为 Windows 窗体应用程序创建了一个自定义用户控件。除了展示自己并允许自己被拖到别处之外,他们没有太多的行为。但是它们是圆形的,当它们在角落重叠时我无法正确显示它们。
这是我在屏幕上绘制它们的代码:
public void Circle_Paint(object sender, PaintEventArgs e)
{
var g = e.Graphics;
g.FillEllipse(brushForOuterCircle, 0, 0, Width, Height);
g.FillEllipse(brushForInnerCircle, lineWidth, lineWidth, Width - 2*lineWidth, Height - 2*lineWidth);
if(!textLocation.HasValue)
{
SizeF m = g.MeasureString(text, textFont);
textLocation = new PointF((float)((Width - m.Width)/2.0), (float)((Height - m.Height)/2.0));
}
g.DrawString(text, textFont, brushForText, textLocation.Value);
}
这是一个不正确显示的示例,AB 圆圈的东南部不显示,因为 CD 覆盖了该区域。
我应该如何防止这种情况,有没有办法告诉 UserControl “默认情况下你是透明的;我不绘制的任何部分都应该保持这样”?
【问题讨论】:
-
可能重复:Transparent User Control in .net 当然还有很多很多其他
-
我知道这个问题,但是在接受的答案中它说:“一个值得注意的不起作用是重叠控件。您只能看到父像素,而不是重叠的像素控制。这是可以修复的,但代码很丑。”所以如果我没有误解它,它就不会回答我的问题。是吗?
标签: c# .net winforms user-controls