By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

Problems with the display of the tabs in my customized TabControl

P: n/a
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[i].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.

Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <pa************@skillworks.de> wrote in message
news:2i************@uni-berlin.de...
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[i].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.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.693 / Virus Database: 454 - Release Date: 31/05/2004
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.