hi every one,
In Tab control i want to change the color of the tab (rectangular) at the top when the align=left as well as i want how the rectangular tab look in default mode(when it is align=left)
i found some code and used it but it is not displaying the tab name at runtime .
the code which i used :
In load iam making Drawmode=owner drawfixed in tab properties
private void TabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Graphics g = e.Graphics;
TabPage tp = TabControl1.TabPages(e.Index);
Brush br;
StringFormat sf = new StringFormat();
RectangleF r = new RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2);
sf.Alignment = StringAlignment.Center;
string strTitle = tp.Text;
if (TabControl1.SelectedIndex == e.Index) {
br = new SolidBrush(Color.SkyBlue);
g.FillRectangle(br, e.Bounds);
br = new SolidBrush(Color.Black);
g.DrawString(strTitle, TabControl1.Font, br, r, sf);
} else {
br = new SolidBrush(Color.DarkGray);
g.FillRectangle(br, e.Bounds);
br = new SolidBrush(Color.Black);
g.DrawString(strTitle, TabControl1.Font, br, r, sf);
}
}

Sokak37 reputationPosted Apr 25, 2007, 8:03 PM EDT
TabPage tp = TabControl1.TabPages(e.Index);
should read:
TabPage tp = TabControl1.TabPages[e.Index];
I doubt this is your problem if your project is compiling and running, though when I tried the update code it displayed like what it appears it should be doing. If it's still not correct can you describe what you expect to see and what you're getting instead?
arif sharif25 reputationPosted Apr 26, 2007, 12:04 AM EDT
my doubt is that how can i make tabcontrol to display when it is alignment=left but with back color as well as fore color chnaged.
i want to display in the same fashion when tab control is alignment=left by deafult.
warm regards
Sokak37 reputationPosted Apr 26, 2007, 5:41 PM EDT
This will require a bit of messing around with the RotateTransform method on the graphics instance. Give this a try with the tab page set to Left Alignment.
br = new SolidBrush( Color.SkyBlue );
g.FillRectangle( br, e.Bounds );
br = new SolidBrush( Color.Black );
g.TranslateTransform( e.Bounds.X + e.Bounds.Width / 2, e.Bounds.Y + e.Bounds.Height / 2 ); // Set the rotation point to the center of our rectangle area for the tab.
g.RotateTransform( -90f ); // Rotate -90 degrees (Vertical text bottom up.)
g.DrawString( strTitle, tabControl1.Font, br, 0, -4, sf ); // Position text 0 (x) -4(y) in the rotated aspect of bounds of the tab's graphics area.
g.ResetTransform(); // Remove the transform
You don't need the RectangleF instance (r) anymore.
arif sharif25 reputationPosted Apr 26, 2007, 8:47 PM EDT
sucessfully working
with warm regards
arifsharif_2001