Tab control problem in .net 1.1

N

naamala

Hi,
I need to change individual tab's background color in TabControl
in windows form. I am able to change the Backgrond color of each tab
in TabControl with changing the property "DrawMode=OwnerDrawFixed".

The problem When I use "DrawMode=Normal", tabcontrol rendering the
background color of the form where there are no tabs, But When Change
"DrawMode=OwnerDrawFixed", it's not rendering Form's BackGround Color
where there are no tabs, It is displaying Color type of Control?

But I need to display the Background color of the Form where there
are no tab's;
How can I display the /paint it forms background color?


thanks
naamala
 
?

=?ISO-8859-1?Q?Robert-Reinhold_Gro=DF?=

Hey Naamala,

this works at my project. Add these lines to the overriden TabControl
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
Region region = new Region( e.ClipRectangle );
for ( int i = 0; i < TabCount; i++)
{
Rectangle r = GetTabRect(i);
region.Exclude( r );
}
using (SolidBrush brush = new SolidBrush( _backcolor ))
{
e.Graphics.FillRegion( brush, region );
}
}

protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground (pevent);
using (SolidBrush brush = new SolidBrush( _backcolor ))
{
pevent.Graphics.FillRectangle( brush,
pevent.ClipRectangle );
}
}

This fills the region next to Titles of each TabPage.

-Robert Groß.
 
N

naamala

Hey Naamala,

this works at my project. Add these lines to the overriden TabControl
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
Region region = new Region( e.ClipRectangle );
for ( int i = 0; i < TabCount; i++)
{
Rectangle r = GetTabRect(i);
region.Exclude( r );
}
using (SolidBrush brush = new SolidBrush( _backcolor ))
{
e.Graphics.FillRegion( brush, region );
}
}

protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground (pevent);
using (SolidBrush brush = new SolidBrush( _backcolor ))
{
pevent.Graphics.FillRectangle( brush,
pevent.ClipRectangle );
}
}

This fills the region next to Titles of each TabPage.

-Robert Groß.

Hi Robert,

Thank you for the quick reply & help.
I modified the code, my form background color & tabs colors are
changing, In the tabcontrol area where tabs are not available that is
getting different background Color (as default Color type Control). It
is same as what i am getting previously.

GetTabRect() method functionality is missing, Pl. provide me?

Thank you.
naamala
 
N

naamala

Unfortuantely, you will have to Draw the entire control.

You'll see a basic example of this on my site "A Completely OwnerDraw
TabControl.". The description also contains links to a couple of more
advanced examples on codeproject.http://www.dotnetrix.co.uk/tabcontrols.html

You may find TabControlEx already does what you want .http://www.dotnetrix.co.uk/controls.html

Hi,
Sorry! for the late .

I tried with that , I am able to Draw Tabs in the TabControl, Now
also facing same problem. In tab control where Tab are not
available it's not taking color from form background color, it
displaying with Different color as Form Control.

regards.
naamala
 
M

Mick Doherty

Hi,
Sorry! for the late .

I tried with that , I am able to Draw Tabs in the TabControl, Now
also facing same problem. In tab control where Tab are not
available it's not taking color from form background color, it
displaying with Different color as Form Control.

regards.
naamala

That's because you need to draw the background yourself in order to mimic
transparency. You can see how to do this in my "Create a Simple Rounded
Panel" example at http://www.dotnetrix.co.uk/custom.html. (you just need the
first paragraph of the OnPaintBackground override).

If you used TabControlEx, you can simply set the BackColor to Transparent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top