We have a simple user control which works fine when we use it in our form, however when we try to host it into our StatusStrip via this method the OnPaint event is never called. MSDN Documentation states this 'should' work, but we see nothing and confirmed that the OnPaint event never gets called.:
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);
}
The ToolStripControlHost has an odd quirk where it needs the MinimumSize set for the control it is hosting:
Try adding this: