我們有一個簡單的用戶控件,在我們的表單中使用它時可以正常工作,但是當我們嘗試通過此方法將其託管到StatusStrip中時,從不會調用OnPaint事件。 MSDN文檔指出這「應該」的工作,但我們什麼也看不到,確認OnPaint事件不會被調用:託管UserControl的StatusStrip無法調用UserControls OnPaint事件
public partial class SimpleUserControl : UserControl
{
public SimpleUserControl()
{
InitializeComponent();
// Set the styles for drawing
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.DoubleBuffer |
ControlStyles.SupportsTransparentBackColor,
true);
}
[System.ComponentModel.EditorBrowsableAttribute()]
protected override void OnPaint(PaintEventArgs e)
{
Rectangle _rc = new Rectangle(0, 0, this.Width, this.Height);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
e.Graphics.DrawArc(new Pen(Color.Red), _rc, 180, 180);
}
}
public Form1()
{
InitializeComponent();
SimpleUserControl suc = new SimpleUserControl();
suc.Size = new Size(30, 20);
ToolStripControlHost tsch = new ToolStripControlHost(suc);
statusStrip1.Items.Add(tsch);
}
得分。只是我喜歡SO的很多原因之一。我必須等待檢查,因爲現在有一段時間才能接受...... – Gio