Problems with the display of the tabs in my customized TabControl

  • Thread starter Thread starter Paiam Salavati
  • Start date Start date
P

Paiam Salavati

I want to change the the color of the tabs and the color of TabControl
itself in a TabControl. Therefore I wrote the following code in my
customized TabControl-class:

this.DrawMode = TabDrawMode.OwnerDrawFixed;

protected override void OnDrawItem(DrawItemEventArgs e)

{

e.Graphics.FillRectangle(new SolidBrush(Color.Gray), this.ClientRectangle);



for(int i = 0; i < this.TabCount; i++)

{


Rectangle currentPage = this.GetTabRect(i);

e.Graphics.FillRectangle(new SolidBrush(Color.Green), currentPage);

e.Graphics.DrawString(this.TabPages.Text, e.Font, new
SolidBrush(mTabFontColor), currentPage, StringFormat.GenericDefault);



}


}



It changes the colors correct, but the problem is, that the tabs aren't
shown correct (especially if appearence = Button is selected, than it
sometimes draws a normal rectangle instead of an unselected button ).

Does anybody have an idea how I could change the color of the tabs and also
the color of the tabControl itself in a proper way?

I know about "dotnetmagics", but I am not willed to purchase it, because I
think there has to be a different way of implementing this comparative
simple task.
 
Instead of setting OwnerDrawFixed, I set the following style upon
initialization.
SetStyle(ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer |
ControlStyles.UserPaint,true);

This results in a fully ownerdraw Tabcontrol instaed of the partially
ownerdraw style offered by the control itself.
The main disadvantage here is that it is entirely up to you to paint every
part of the control, but the main advantage is that it is entirely up to you
how you draw each part of the control ;-)

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi100/index.html


Paiam Salavati said:
I want to change the the color of the tabs and the color of TabControl
itself in a TabControl. Therefore I wrote the following code in my
customized TabControl-class:

this.DrawMode = TabDrawMode.OwnerDrawFixed;

protected override void OnDrawItem(DrawItemEventArgs e)

{

e.Graphics.FillRectangle(new SolidBrush(Color.Gray), this.ClientRectangle);



for(int i = 0; i < this.TabCount; i++)

{


Rectangle currentPage = this.GetTabRect(i);

e.Graphics.FillRectangle(new SolidBrush(Color.Green), currentPage);

e.Graphics.DrawString(this.TabPages.Text, e.Font, new
SolidBrush(mTabFontColor), currentPage, StringFormat.GenericDefault);



}


}



It changes the colors correct, but the problem is, that the tabs aren't
shown correct (especially if appearence = Button is selected, than it
sometimes draws a normal rectangle instead of an unselected button ).

Does anybody have an idea how I could change the color of the tabs and also
the color of the tabControl itself in a proper way?

I know about "dotnetmagics", but I am not willed to purchase it, because I
think there has to be a different way of implementing this comparative
simple task.
 
Back
Top