How to draw an image over a tabcontrol using c#?
I have to draw image in a tabcontrol using C#. I got few hints to change DrawMode to OwnerDrawFixed, and SizeMode to Fixed. After that write handler for DrawItem event as:
this.tabControl1.DrawI开发者_高级运维tem +=
new System.Windows.Forms.DrawItemEventHandler(this.OnDrawItem);
private void OnDrawItem(object sender, DrawItemEventArgs e)
{
Graphics g = Graphics.FromHwnd(tabPage1.Handle);/*e.Graphics;*/
DrawArrowImage(g);
}
Now this DrawImage() function start a timer which will keep redrawing an arrow image at next points to resemble the moving arrow. Now here I have few issues:
- OnDrawItem is not being called as I run the application (alike OnPaint()). How can I do it?
- As calling Invalidate() cause invoking paint event and the it calls OnPaint(), is there any way to invoke 'DrawItem' event so that inturn OnDrawItem() can be called?
thanks, RPS
You are doing it wrong, the DrawItem event is only meant to custom draw the tab, not the tab page. Simply implement the Paint event of the tab page. Be sure to use the e.Graphics that is handed to you to do the drawing.
...
this.tabPage1.Paint += this.OnDrawPage;
...
private void OnDrawPage(object sender, PaintEventArgs e)
{
DrawArrowImage(e.Graphics);
}
精彩评论