我用ContainerControl作为我的基础创建了一个简单的自定义面板。我已经添加了自定义属性来创建边框和渐变背景。如果我重写OnPaint和OnPaintBackground父级的所有子控件都继承渐变和边框样式。作为一项解决方案,我使用父母的BackgroundImage属性,它工作正常,但有一些随机怪癖。必须有更好的方法来解决这个问题,但我没有找到解决办法。有没有通过Interop或其他C#方法来解决这个问题的窗口API函数?如果是这样,请提供一个例子。孩子们继承父母的外貌
编辑!这里是被复制的样式(例如难看,但使点):
EDIT 2!这里是没有所有的性能的简单的硬编码一个ContainerControl,设计师属性等
public class Container : ContainerControl
{
protected override void OnPaintBackground(PaintEventArgs e)
{
using (var brush = new LinearGradientBrush(e.ClipRectangle, Color.Red, Color.Blue, LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(brush, e.ClipRectangle);
}
}
}
有趣的是,我不认为这会发生。你可以发布你的'OnPaint()'和'OnPaintBackground()'覆盖吗? – 2012-08-21 19:12:26
发布图片。 – 2012-08-21 19:15:25
'label2'是标准'Label'控件还是另一个自定义控件? – 2012-08-21 19:19:54