Cela semble être une question simple mais comment définir la couleur de l'onglet 'contrôle de tabulation', il semble provenir de la fenêtre standard couleur du thème. Est-il possible de créer un contrôle onglet noir avec du texte blanc écrit sur les onglets eux-mêmes (pas la page à onglet)? Aide, je suis un peu familier avec les contrôles personnalisés étendant les contrôles existants mais je ne sais pas quelles propriétés (si elles existent) à définir.C# Winform: Comment définir la couleur de base d'un TabControl (pas l'onglet)
4
A
Répondre
2
http://dotnetrix.co.uk/tabcontrol.htm
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
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;
//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.White;
TextBrush.Color = Color.Red;
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();
}
1
J'utilise quelque chose comme ça dans la classe dérivée mu TabControl (et il fera aussi des gradients):
protected override void OnDrawItem(DrawItemEventArgs e)
{
// fill in the whole rect
using (SolidBrush br = new SolidBrush(Theme.FormBackColor))
{
e.Graphics.FillRectangle(br, ClientRectangle);
}
// draw the tabs
for (int i = 0; i < TabPages.Count; ++i)
{
TabPage tab = TabPages[i];
// Get the text area of the current tab
RectangleF tabTextArea = (RectangleF)GetTabRect(i);
// determine how to draw the tab based on which type of tab it is
Color tabTopBackColor = GetTopBackColor();
Color tabBottomBackColor = GetBottomBackColor();
Color tabTextColor = GetTextColor();
// draw the background
using (LinearGradientBrush br = new LinearGradientBrush(tabTextArea, tabTopBackColor, tabBottomBackColor, LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(br, tabTextArea);
}
// draw the tab header text
using (SolidBrush brush = new SolidBrush(tabTextColor))
{
e.Graphics.DrawString(tab.Text, Font, brush, CreateTabHeaderTextRect(tabTextArea));
}
}
}
private RectangleF CreateTabHeaderTextRect(RectangleF tabTextArea)
{
tabTextArea.X += 3;
tabTextArea.Y += 1;
tabTextArea.Height -= 1;
return tabTextArea;
}
Questions connexes
- 1. Winform TabControl style
- 2. Modification de l'onglet TabControl titre titre couleur de fond C++
- 3. C# WinForm Principes de base Combobox
- 4. Couleur d'arrière-plan pour Tabcontrol dans l'application C# windows
- 5. Javascript ne peut pas définir la couleur
- 6. C#: transparent dans tabControl
- 7. comment changer la couleur de winform DataGridview en-tête?
- 8. Icônes dans TabControl C# - Comment?
- 9. Réglage TabItem couleur de premier plan définit également la couleur de premier plan TabControl
- 10. UIKit. Comment définir la couleur transparente?
- 11. Cacao: Définir la couleur sélectionnée
- 12. Comment définir l'élément sélectionné par défaut de la zone de liste dans winform C#?
- 13. C# TabControl TabPage Change
- 14. C# tabcontrol - tabulation
- 15. Comment définir la couleur de chaque widget dans GTK
- 16. C# Zone Richtext comment définir la marge de texte dans winform
- 17. Utilisez jQuery pour définir la couleur d'arrière-plan avec la valeur de la base de données
- 18. Comment définir la couleur d'arrière-plan de la grille wxPython?
- 19. Comment définir la couleur de la bordure fieldset?
- 20. classe de base générique pour WinForm UserControl
- 21. comment définir un onglet TabControl pour être invisible
- 22. Définir la couleur de la cellule du tableau à partir de la base de données
- 23. Comment définir la couleur de la région sur Google geomap?
- 24. Comment définir la couleur de la bordure d'un CircleItemRenderer
- 25. Comment définir la couleur et la couleur de fond d'un élément pour la version imprimée
- 26. Modifier la couleur d'arrière-plan des en-têtes Winform ListView
- 27. Définition de la couleur d'arrière-plan des onglets inactif de WPF TabControl
- 28. C# WinForm ne répond pas - System.Speech - Aide
- 29. Définir la visibilité sur un seul onglet dans tabcontrol (winforms)
- 30. C# Winform L'usurpation d'identité ne fonctionne pas
Merci! Je vais vérifier ça. – Zion