PDA

View Full Version : چطور header ها رو در یک tabControl در وسط قرار میدن ؟



elham1611
جمعه 26 خرداد 1391, 14:15 عصر
با سلام
ما یک tabControl داریم که header هاش در سمت چپ قرار میگیرن
چی کار میشه کرد و جه خصوصیتی رو باید تغییر داد تا در وسط قرار بگیرن

من گشتم چیزی پیدا نکردم

ممنون

robat7
شنبه 27 خرداد 1391, 01:32 صبح
سری به لینک زیر بزن
http://stackoverflow.com/questions/1849801/c-sharp-winform-how-to-set-the-base-color-of-a-tabcontrol-not-the-tabpage

public FrmMultiPSR()
{
InitializeComponent();
//I_PSRHasSelected = false;
tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
tabControl1.DrawItem += new DrawItemEventHandler(OnDrawItem);
#region Tooltip on DataGridViewColumneader
this.Grid0.ShowCellToolTips = false;
this.Grid0.CellMouseEnter += new DataGridViewCellEventHandler(Grid0_CellMouseEnter) ;

this.Grid1.ShowCellToolTips = false;
this.Grid1.CellMouseEnter += new DataGridViewCellEventHandler(Grid1_CellMouseEnter) ;

this.Grid2.ShowCellToolTips = false;
this.Grid2.CellMouseEnter += new DataGridViewCellEventHandler(Grid2_CellMouseEnter) ;

this.Grid3.ShowCellToolTips = false;
this.Grid3.CellMouseEnter += new DataGridViewCellEventHandler(Grid3_CellMouseEnter) ;

this.Grid4.ShowCellToolTips = false;
this.Grid4.CellMouseEnter += new DataGridViewCellEventHandler(Grid4_CellMouseEnter) ;

#endregion
}

private void OnDrawItem(object sender, DrawItemEventArgs e)
{
//float rotateAngle = 180;
//http://stackoverflow.com/questions/1849801/c-sharp-winform-how-to-set-the-base-color-of-a-tabcontrol-not-the-tabpage
TabPage CurrentTab = tabControl1.TabPages[e.Index];
Rectangle ItemRect = tabControl1.GetTabRect(e.Index);
SolidBrush FillBrush = new SolidBrush(Color.Red);
SolidBrush TextBrush = new SolidBrush(Color.White);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
DateTime dz2;

//If we are currently painting the Selected TabItem we'll
//change the brush colors and inflate the rectangle.
if (System.Convert.ToBoolean(e.State & DrawItemState.Selected))
{
FillBrush.Color = Color.Cyan;
TextBrush.Color = Color.Black;
ItemRect.Inflate(2, 2);
}
else
{
#region Set Tabpages
if (credentials[e.Index])
{
for (int ieb = 0; ieb < 5; ieb++)
{
try
{
dz2 = Convert.ToDateTime(tabControl1.TabPages[e.Index].Text);
if (CheckifTheSelectedDateIsETCDate(dz2))
{
if (CheckifTheSelectedDateIsBLDate(dz2))
{ // ETC & Base Line
FillBrush.Color = Color.Blue;
TextBrush.Color = Color.White;
}
else
{ //Only ETC Date
FillBrush.Color = Color.Red;
TextBrush.Color = Color.Black;
}
}
else
{
if (CheckifTheSelectedDateIsBLDate(dz2))
{ // Only Base Line
FillBrush.Color = Color.DarkCyan;
TextBrush.Color = Color.Black;
}
else
{ //Not ETC Date Nor Base Line
FillBrush.Color = Color.White;
TextBrush.Color = Color.Black;
}
}
}
catch
{
FillBrush.Color = Color.White;
TextBrush.Color = Color.Black;
}
}
}
else
{
FillBrush.Color = Color.White;
TextBrush.Color = Color.Silver;
}
#endregion
ItemRect.Inflate(2, 2);
}

//Set up rotation for left and right aligned tabs
if (tabControl1.Alignment == TabAlignment.Left || tabControl1.Alignment == TabAlignment.Right)
{
float RotateAngle = 90;
if (tabControl1.Alignment == TabAlignment.Left)
RotateAngle = 270;
PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 2), ItemRect.Top + (ItemRect.Height / 2));
e.Graphics.TranslateTransform(cp.X, cp.Y);
e.Graphics.RotateTransform(RotateAngle);
ItemRect = new Rectangle(-(ItemRect.Height / 2), -(ItemRect.Width / 2), ItemRect.Height, ItemRect.Width);
}

//Next we'll paint the TabItem with our Fill Brush
e.Graphics.FillRectangle(FillBrush, ItemRect);

//Now draw the text.
e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, (RectangleF)ItemRect, sf);

//Reset any Graphics rotation
e.Graphics.ResetTransform();

//Finally, we should Dispose of our brushes.
FillBrush.Dispose();
TextBrush.Dispose();
}