TabControl - change the tab shapes and appearances?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have tried without success (using C#) to change the standard rectangular tabs (for the TabPages) to look like the ones in Messenger - funky curved jobs. However whenever I try to overwrite an existing tab, either by superimposing a bitmap over it, or by manually drawing a new shape with the Graphics methods, the standard rectangular tab outline always shows through. I captured both the DrawItem and Paint events.
I saw a partial solution in Code Project, which used a wrapper DLL around UxThemes.dll, but this involves installing this extra DLL with my product. And I couldn't get it to work anyway!
It seems this is a known problem in .NET. A colleague using C++/MFC had no trouble doing this.
Any suggestions? - please!
 
* "=?Utf-8?B?U2hvbHRvIERvdWdsYXM=?= said:
I have tried without success (using C#) to change the standard
rectangular tabs (for the TabPages) to look like the ones in Messenger -
funky curved jobs. However whenever I try to overwrite an existing tab,
either by superimposing a bitmap over it, or by manually drawing a new
shape with the Graphics methods, the standard rectangular tab outline
always shows through. I captured both the DrawItem and Paint events.

Maybe these samples help:

I saw a partial solution in Code Project, which used a wrapper DLL
around UxThemes.dll, but this involves installing this extra DLL with my
product. And I couldn't get it to work anyway!

"UxTheme.dll" is shipped with Windows XP, and I doubt that it's allowed
to distribute this DLL. In addition, I doubt that it will work with
older versions of Windows.
 
Vielen Dank, Herfried.
In Mick Doherty's site was some sample code, where I found one method that solved all my problems. Well, my TabControl problems. Still got my financial problems!
Here is the answer:
1) Derive a class from TabControl.
2) Set its style to UserPaint:
SetStyle(ControlStyles.UserPaint,true);
This was the magic bullet. SetStyle is a protected method, hence the need to
derive from TabControl.
3) This activates the OnPaint() event, but de-activates OnDrawItem() for some reason. In OnPaint you can draw the tab in whatever shape you like and those pesky rectangle outlines are duly suppressed. Here is a simple sample:-

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;

for (int i = 0; i < TabCount; i++) {
if (!e.ClipRectangle.IntersectsWith(GetTabRect(i)))
continue;
Region regn = m_regn.Clone();
// Move the cloned region down/along so it represents
// the correct TabPage
regn.Translate(0,i * ItemSize.Width);
// Give tab of selected page a different colour
Color backColor = i == SelectedIndex? Color.Red : CyPhoneTabColour;
g.FillRegion(new SolidBrush(backColor),regn);
}
}

Thanks again Herfried. You too Mick.
--
Cheers,
Sholto Douglas
CyTrack Telecommunications
http://www.cytrack.com.au
 
Back
Top