フォームで使用すると問題なく動作する単純なユーザー コントロールがありますが、このメソッドを介して StatusStrip にホストしようとすると、OnPaint イベントは呼び出されません。MSDN のドキュメントには、これは機能するはずであると記載されていますが、何も表示されず、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);
}