我简单试了一下,好像没有问题
====
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class ucA : UserControl
{
public ucA()
{
InitializeComponent();
this.Paint += UcA_Paint;
}
private void UcA_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString("this is ucA paint",
this.Font,
new SolidBrush(Color.Red),
new Point(0, 0));
}
}
public class ucB : ucA
{
public ucB()
{
this.Paint += UcB_Paint;
}
private void UcB_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString("this is ucB paint",
this.Font,
new SolidBrush(Color.Green),
new Point(0, 20));
}
}
public class ucC : ucB
{
public ucC()
{
this.Paint += UcC_Paint;
}
private void UcC_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString("this is ucB paint",
this.Font,
new SolidBrush(Color.Blue),
new Point(0, 40));
}
}
}
【 在 moneybox 的大作中提到: 】
: 刚看错你打的字了,实际上,在我目前调试看来,控件被add到panel上,并没有抛出paint事件!
--
FROM 59.109.156.*