c# - Recoloring TabControl -
i have tab control want customize. more specific, want change color of tab page header, color of white line around tab page (check first picture).
i thought of using custom renderer (similar recoloring menu strip, example), i'm not sure how this. i've read setting drawmode
ownerdrawfixed
may this, using option makes the tab control if program made in '90s (check second picture).
what want keep tabs simple , flat and change color. check way tabs in visual studio example (check third picture).
any ideas?
edit: picture of tab page it's more clear "white line" is.
when use ownerdrawfixed
means you supply drawing code. if did not hook , use drawitem
event, nothing gets drawn. same yours @ design time, because event not firing. design time painting, you'd have subclass control , use ondrawitem
.
// colors use private color[] tcolors = {color.salmon, color.white, color.lightblue}; private void tabcontrol1_drawitem(object sender, drawitemeventargs e) { // ref page tabpage tp = ((tabcontrol)sender).tabpages[e.index]; using (brush br = new solidbrush(tcolors[e.index])) { rectangle rect = e.bounds; e.graphics.fillrectangle(br, e.bounds); rect.offset(1, 1); textrenderer.drawtext(e.graphics, tp.text, tp.font, rect, tp.forecolor); // draw border rect = e.bounds; rect.offset(0, 1); rect.inflate(0, -1); // controldark looks right border using (pen p = new pen(systemcolors.controldark)) { e.graphics.drawrectangle(p, rect); } if (e.state == drawitemstate.selected) e.drawfocusrectangle(); } }
basic result:
the tab thumb looks bit cramped me , not tall default. so, added tfontsize
draw text @ different size font.
set tabcontrol.font
10 (which seems plenty), windows draws larger thumb/header. if still draw text @ default 8.25, there more room:
private float tfontsize = 8.25f; // font drawing size ... using (font f = new font(tp.font.fontfamily,tfontsize)) { // shift gutter/padding rect.offset(1, 1); textrenderer.drawtext(e.graphics, tp.text, f, rect, tp.forecolor); }
one thing loose way visualstyles effect, seem clash colored tabs anyway.
Comments
Post a Comment