Center an image on a tab page

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

Hi,

I have a tab control containing few tab pages. On each tab
pages, I put an image on the tab page's title bar (the
area on top of a tab page, ie where tooltip will appear).

If i put both an image and a text, they both will be
centered nicely. However, if I put only image without the
text, the image will position itself more to the left and
it is not centered.

Is it possible to have the image to be on the center?
Thank you.


regards,
Sean
 
Sean,

There is a way to center the image. you have to add Paint Event of tab page
and get the graphics pointer

Graphics g = e.Graphics.
g.DrawImage(TestImage, new Rectangle(xDraw, yDraw, TestImageWidth,
TestImageHeight));

xDraw, and yDraw will get you the offset to center the image.

Shak.
 
Hi Shak,

Thank you for your reply.

It worked. Unfortunately, the yDraw actually starts from
the tabpage, but not the square area that usually contains
the text/title for the tabpage.

I want the image to be centered on the square where the
title/text shown.

Thank you.


regards,
Sean
 
Ok...

Instead of adding paint event in tabpage, do the following

1.Set DrawMode Property of TabControl to OwnerDrawnFixed
2.add DrawItem event of Tabcontrol.
3. Get the graphics pointer and center the image.

Shak.
 
Hi Shak,

Thank you so much for your last post.
It works! However, there is a white line between the title
bar and the tabpage even for the selectedPage. This line
wasn't there when I had the DrawMode as Normal.

Is there a way to get rid of the white line between the
title bar and the tabpage for the selectedPage?

Thank you once again.


regards,
Sean
 
Back
Top