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.DrawItem += 
    new System.Windows.Forms.DrawItemEventHandler(this.OnDrawItem);

private void OnDrawItem(object sender, DrawItemEventArgs e)
    Graphics g = Graphics.FromHwnd(tabPage1.Handle);/*e.Graphics;*/         


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:

  1. OnDrawItem is not being called as I run the application (alike OnPaint()). How can I do it?
  2. 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)

Need Your Help

What's the best field type and data usage to accelerate searches?

database performance search indexing

I have a question about equivalent search result, that can occur on different fields.

Custom URL with Paperclip and AWS S3

ruby-on-rails ruby-on-rails-4 paperclip ruby-on-rails-4.2 aws-sdk

We're using Paperclip with the aws-sdk gem to store and display images in our Rails app: