Click here to Skip to main content
15,927,055 members
Home / Discussions / C#
   

C#

 
GeneralColor Pin
sreejith ss nair5-Aug-04 21:56
sreejith ss nair5-Aug-04 21:56 
GeneralRe: Color Pin
sreejith ss nair6-Aug-04 1:35
sreejith ss nair6-Aug-04 1:35 
GeneralRe: Color Pin
Colin Angus Mackay6-Aug-04 3:59
Colin Angus Mackay6-Aug-04 3:59 
GeneralRe: Color Pin
Heath Stewart6-Aug-04 4:58
protectorHeath Stewart6-Aug-04 4:58 
GeneralRe: Color Pin
Colin Angus Mackay6-Aug-04 5:24
Colin Angus Mackay6-Aug-04 5:24 
GeneralRe: Color Pin
sreejith ss nair6-Aug-04 18:45
sreejith ss nair6-Aug-04 18:45 
GeneralRe: Color Pin
Colin Angus Mackay6-Aug-04 23:41
Colin Angus Mackay6-Aug-04 23:41 
GeneralRe: Color Pin
sreejith ss nair8-Aug-04 17:47
sreejith ss nair8-Aug-04 17:47 
Who is going to draw ?

Tabcontrol have a properties called DrawMode. This will set or get the value that whether user or system will paint the caption.By default it is normal. Means system(OS) will paint the caption for you. If you(parent form) want to draw the caption you have to set the value of the property to OwnerDrawFixed.

You can mention DrawMode on design time or runtime like below mentioned code.

this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;

Now you mention who is going to draw the caption.


Next thing is how is going draw ?

Tab control have an event called DrawItem event which will occure when ever an area need to be painted.

eg:

this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);



private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{


Font f;
Brush backBrush;
Brush foreBrush;

if(e.Index == this.tabControl1.SelectedIndex)
{
f = new Font(e.Font, FontStyle.Bold | FontStyle.Bold);
backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Blue, Color.Gold, System.Drawing.Drawing2D.LinearGradientMode.Vertical);

foreBrush = Brushes.White;
}

else
{
f = e.Font;
backBrush = new SolidBrush(e.BackColor);
foreBrush = new SolidBrush(e.ForeColor);
}

string tabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
e.Graphics.FillRectangle(backBrush, e.Bounds);
Rectangle r = e.Bounds;
r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
e.Graphics.DrawString(tabName, f, foreBrush, r, sf);
sf.Dispose();
if(e.Index == this.tabControl1.SelectedIndex)
{
f.Dispose();
backBrush.Dispose();
}
else
{
backBrush.Dispose();
foreBrush.Dispose();
}
}
}
Big Grin | :-D

**************************
S r e e j i t h N a i r
**************************
GeneralRe: Color Pin
sreejith ss nair8-Aug-04 17:55
sreejith ss nair8-Aug-04 17:55 
Generalsetting directory permissions Pin
Gavin Jeffrey5-Aug-04 21:18
Gavin Jeffrey5-Aug-04 21:18 
GeneralRe: setting directory permissions Pin
Heath Stewart6-Aug-04 5:02
protectorHeath Stewart6-Aug-04 5:02 
GeneralRe: setting directory permissions Pin
Gavin Jeffrey16-Aug-04 3:22
Gavin Jeffrey16-Aug-04 3:22 
GeneralReflection Question Pin
Angel Reyes5-Aug-04 17:42
Angel Reyes5-Aug-04 17:42 
GeneralRe: Reflection Question Pin
leppie5-Aug-04 19:22
leppie5-Aug-04 19:22 
GeneralRe: Reflection Question Pin
Angel Reyes6-Aug-04 6:29
Angel Reyes6-Aug-04 6:29 
GeneralStatically linking dependency assemblies Pin
softp_vc5-Aug-04 17:40
softp_vc5-Aug-04 17:40 
GeneralRe: Statically linking dependency assemblies Pin
leppie5-Aug-04 19:25
leppie5-Aug-04 19:25 
GeneralRe: Statically linking dependency assemblies Pin
softp_vc5-Aug-04 20:17
softp_vc5-Aug-04 20:17 
GeneralRe: Statically linking dependency assemblies Pin
Colin Angus Mackay5-Aug-04 23:01
Colin Angus Mackay5-Aug-04 23:01 
GeneralRe: Statically linking dependency assemblies Pin
softp_vc6-Aug-04 3:46
softp_vc6-Aug-04 3:46 
GeneralRe: Statically linking dependency assemblies Pin
Heath Stewart6-Aug-04 5:07
protectorHeath Stewart6-Aug-04 5:07 
GeneralRe: Statically linking dependency assemblies Pin
softp_vc6-Aug-04 17:22
softp_vc6-Aug-04 17:22 
GeneralDisplay Image in ListView ! Pin
Colinyin5-Aug-04 16:31
Colinyin5-Aug-04 16:31 
GeneralRe: Display Image in ListView ! Pin
leppie5-Aug-04 19:55
leppie5-Aug-04 19:55 
GeneralRe: Display Image in ListView ! Pin
Colinyin5-Aug-04 20:07
Colinyin5-Aug-04 20:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.