- /// <summary>
- /// Permet d'avoir les onglets de la même couleur que les tabPages
- /// Mettre la propriété du tabControl à drawMode=OwnerDrawFixed
- /// Faire pointer cette fonction sur l'evenement DrawItem
- /// </summary>
- /// <param name="sender">objet de type TabControl</param>
- /// <param name="e">Arguments de l'evenement declanché par DrawItem</param>
- public static void OngletColore(object sender, System.Windows.Forms.DrawItemEventArgs e)
- {
- System.Windows.Forms.TabControl tabControl = (System.Windows.Forms.TabControl)sender;
- Brush brushBack;
- Brush brushFore;
-
- if(e.Index == tabControl.SelectedIndex)
- {
- brushBack = new System.Drawing.SolidBrush(tabControl.TabPages[e.Index].BackColor);
- brushFore = new SolidBrush(tabControl.TabPages[e.Index].ForeColor);
- }
- else
- {
- brushBack = new SolidBrush(Color.FromKnownColor(KnownColor.Control));
- brushFore = new SolidBrush(tabControl.TabPages[e.Index].ForeColor);
- }
- e.Graphics.FillRectangle(brushBack, e.Bounds.X+2,e.Bounds.Y,e.Bounds.Width-2,e.Bounds.Height);
- e.Graphics.DrawString(tabControl.TabPages[e.Index].Text, tabControl.TabPages[e.Index].Font, brushFore,(float)(e.Bounds.X+3),(float)(e.Bounds.Y+3));
- brushBack.Dispose();
- brushFore.Dispose();
- }
- }
/// <summary>
/// Permet d'avoir les onglets de la même couleur que les tabPages
/// Mettre la propriété du tabControl à drawMode=OwnerDrawFixed
/// Faire pointer cette fonction sur l'evenement DrawItem
/// </summary>
/// <param name="sender">objet de type TabControl</param>
/// <param name="e">Arguments de l'evenement declanché par DrawItem</param>
public static void OngletColore(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
System.Windows.Forms.TabControl tabControl = (System.Windows.Forms.TabControl)sender;
Brush brushBack;
Brush brushFore;
if(e.Index == tabControl.SelectedIndex)
{
brushBack = new System.Drawing.SolidBrush(tabControl.TabPages[e.Index].BackColor);
brushFore = new SolidBrush(tabControl.TabPages[e.Index].ForeColor);
}
else
{
brushBack = new SolidBrush(Color.FromKnownColor(KnownColor.Control));
brushFore = new SolidBrush(tabControl.TabPages[e.Index].ForeColor);
}
e.Graphics.FillRectangle(brushBack, e.Bounds.X+2,e.Bounds.Y,e.Bounds.Width-2,e.Bounds.Height);
e.Graphics.DrawString(tabControl.TabPages[e.Index].Text, tabControl.TabPages[e.Index].Font, brushFore,(float)(e.Bounds.X+3),(float)(e.Bounds.Y+3));
brushBack.Dispose();
brushFore.Dispose();
}
}