cs_Sipat
Messages postés71Date d'inscriptionmardi 26 octobre 2004StatutMembreDernière intervention15 avril 2007
-
25 févr. 2007 à 18:41
Utilisateur anonyme -
19 juin 2008 à 11:58
Bonsoir,
Est ce qu'il est possible de changer la couleur de l'onglet et de conserver le petit trait qui donne le focus?
Merci.
MyBase.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor,
True)
End
Sub
Protected
Overrides
Sub OnPaint(
ByVal e
As System.Windows.Forms.PaintEventArgs)
If
Not
MyBase.Visible
Then
Return
DrawVisualStyles(e.Graphics,
New System.Drawing.Rectangle(
MyBase.ClientRectangle.Left,
MyBase.DisplayRectangle.Top - 2,
MyBase.ClientRectangle.Width,
MyBase.ClientRectangle.Height -
MyBase.DisplayRectangle.Top + 2), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.Pane.Normal)
Dim StrAttr
As
New System.Drawing.StringFormat()
StrAttr.Alignment = System.Drawing.StringAlignment.Center
StrAttr.LineAlignment = System.Drawing.StringAlignment.Center
For iTab
As
Integer = 0
To
MyBase.TabCount - 1
If
MyBase.SelectedIndex <> iTab
Then
DrawVisualStyles(e.Graphics,
MyBase.GetTabRect(iTab), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal)
e.Graphics.FillRectangle(
New System.Drawing.SolidBrush(
MyBase.TabPages(iTab).BackColor),
New System.Drawing.Rectangle(
MyBase.GetTabRect(iTab).Left + 1,
MyBase.GetTabRect(iTab).Top + 3,
MyBase.GetTabRect(iTab).Width - 2,
MyBase.GetTabRect(iTab).Height - 3))e.Graphics.DrawString(
MyBase.TabPages(iTab).Text.Trim(),
New System.Drawing.Font(System.Drawing.SystemFonts.MenuFont.FontFamily, 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.DarkBlue,
MyBase.GetTabRect(iTab), StrAttr)
End
If
Next iTab
DrawVisualStyles(e.Graphics, System.Drawing.Rectangle.Inflate(
MyBase.GetTabRect(
MyBase.SelectedIndex), 2, 2), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Pressed)e.Graphics.FillRectangle(
New System.Drawing.SolidBrush(
MyBase.TabPages(
MyBase.SelectedIndex).BackColor),
New System.Drawing.Rectangle(
MyBase.GetTabRect(
MyBase.SelectedIndex).Left - 1,
MyBase.GetTabRect(
MyBase.SelectedIndex).Top + 1,
MyBase.GetTabRect(
MyBase.SelectedIndex).Width + 2,
MyBase.GetTabRect(
MyBase.SelectedIndex).Height + 1))
'pour agrandir l'onglet avant et apr‚s le texte de l'onglet faire des espaces.
e.Graphics.DrawString(
MyBase.TabPages(
MyBase.SelectedIndex).Text.Trim(),
New System.Drawing.Font(System.Drawing.SystemFonts.MenuFont.FontFamily, 11, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Blue,
MyBase.GetTabRect(
MyBase.SelectedIndex), StrAttr)
MyBase.OnPaint(e)
End
Sub
Private
Sub DrawVisualStyles(
ByVal g
As System.Drawing.Graphics,
ByVal Rect
As System.Drawing.Rectangle,
ByVal Element
As System.Windows.Forms.VisualStyles.VisualStyleElement)
Dim renderer
As
New System.Windows.Forms.VisualStyles.VisualStyleRenderer(Element)renderer.DrawBackground(g, Rect)
End
Sub
End
Class
Remplacer :
' Friend WithEvents TabControl1 As TabControl
par
Friend
WithEvents TabControl1
As CoulOnglTabCrl
et
' Me.TabControl1 = New
WindowsApplication1.Form1
.TabControl
par
Me.TabControl1 =
New WindowsApplication1.Form1.CoulOnglTabCrl
et voilà ce que ça donne.
On peux changer la couleur du texte la grosseur et mettre une couleur differente quand il y a le focus, et la couleur des onglets qui prend la couleur de BackColor.
Il me reste plus qu'a remercier Kenji...
Alors merci Kenji pour ta grande patience.
Bonne journée.
Il faut que tu reprenne le TabControl.
Tu fais un contrôle qui hérite du TabControl, et du redéfinis le DrawMode pour dessiner toi même les onglets en couleurs
C'est pas avec toi que j'avais fait des onglets en gras non ?
Ben la c'est le même principe :
Public Class CoulOnglTabCrl
Inherits System.Windows.Forms.TabControl
Public Sub New()
MyBase.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
e.Graphics.FillRectangle(Brushes.Aqua, e.Bounds)
Dim StrAttr As New StringFormat()
StrAttr.Alignment = StringAlignment.Center
StrAttr.LineAlignment = StringAlignment.Center
e.Graphics.DrawString(MyBase.TabPages(e.Index).Text, e.Font, New SolidBrush(e.ForeColor), e.Bounds, StrAttr)
MyBase.OnDrawItem(e)
End Sub
End Class,
----
(Coloration syntaxique automatique par Kenji)
__________
Kenji
Vous n’avez pas trouvé la réponse que vous recherchez ?
cs_Sipat
Messages postés71Date d'inscriptionmardi 26 octobre 2004StatutMembreDernière intervention15 avril 2007 25 févr. 2007 à 21:08
Bonsoir oui c'est moi ! et là on n'a pas utilisé trois pages(enfin pas encore)
J'ai remplacé :
Me
.TabControl1 =
New
System.Windows.Forms.TabControl
par
Me.TabControl1 =
New CoulOnglTabCrl
et
Friend
WithEvents
TabControl1
As
System.Windows.Forms.TabControl
par
Friend
WithEvents
TabControl1
As
CoulOnglTabCrl
Ok ça fonctionne
Reste plus que trouver la couleur "control" je ne l'ai pas vu dans la liste !
Tu crois que l'on peux remettre le petit "neon orangé" de focus dessus l'onglet ?
Merci.
cs_Sipat
Messages postés71Date d'inscriptionmardi 26 octobre 2004StatutMembreDernière intervention15 avril 2007 25 févr. 2007 à 21:57
Non mais avant de peindre quand je posais la souris l'onglet avais une petite bande orangé en haut mais avec le OwnerDrawFixed je pense que la fonction doit être desactivé !
Pour la couleur je la trouve comment la couleur control ?
Si tu veux retracer le style windows, utilise les VisualStyles :
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim Style As System.Windows.Forms.VisualStyles.VisualStyleElement
Select Case e.State
Case System.Windows.Forms.DrawItemState.None
Style = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal
Case System.Windows.Forms.DrawItemState.Selected
Style = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Pressed
End Select
Dim renderer As New System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal)
renderer.DrawBackground(e.Graphics, e.Bounds)
Dim StrAttr As New System.Drawing.StringFormat()
StrAttr.Alignment = System.Drawing.StringAlignment.Center
StrAttr.LineAlignment = System.Drawing.StringAlignment.Center
e.Graphics.DrawString(MyBase.TabPages(e.Index).Text, e.Font, New System.Drawing.SolidBrush(e.ForeColor), e.Bounds, StrAttr)
cs_Sipat
Messages postés71Date d'inscriptionmardi 26 octobre 2004StatutMembreDernière intervention15 avril 2007 26 févr. 2007 à 10:05
Bonjour,
Je suis toujours sur la premiere formule :
Public Class CoulOnglTabCrl
Inherits System.Windows.Forms.TabControl
Public Sub New()
MyBase.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
e.Graphics.FillRectangle(Brushes.Aqua, e.Bounds)
Dim StrAttr As New StringFormat()
StrAttr.Alignment = StringAlignment.Center
StrAttr.LineAlignment = StringAlignment.Center
e.Graphics.DrawString(MyBase.TabPages(e.Index).Text, e.Font, New SolidBrush(e.ForeColor), e.Bounds, StrAttr)
MyBase.OnDrawItem(e)
End Sub
End Class
Tu l'utilises comment System.Drawing.SystemColors.Control. à la place de
Brushes.Aqua ?
Tu vois le petit neon orangé en mode normale... c'est dommage qu'il soit perdu !
Il n'y a pas de gris après TabPage4 .
J'ai essayé :
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim Style As System.Windows.Forms.VisualStyles.VisualStyleElement
Select Case e.State
Case System.Windows.Forms.DrawItemState.None
Style = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal
Case System.Windows.Forms.DrawItemState.Selected
Style = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Pressed
End Select
Dim renderer As New System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal)
renderer.DrawBackground(e.Graphics, e.Bounds)
Dim StrAttr As New System.Drawing.StringFormat()
StrAttr.Alignment = System.Drawing.StringAlignment.Center
StrAttr.LineAlignment = System.Drawing.StringAlignment.Center
e.Graphics.DrawString(MyBase.TabPages(e.Index).Text, e.Font, New System.Drawing.SolidBrush(e.ForeColor), e.Bounds, StrAttr)
MyBase.OnDrawItem(e)
End Sub
Non la j'aime pas ,il y a encore le gris après TabPage4 je préfère le mode normale.
Pourquoi il y a ce gris après TabPage4 et aussi en dessous des onglets?
Merci.
Public Class CoulOnglTabCrl
Inherits System.Windows.Forms.TabControl
Public Sub New()
MyBase.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, True)
MyBase.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, True)
MyBase.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, True)
MyBase.SetStyle(System.Windows.Forms.ControlStyles.ResizeRedraw, True)
MyBase.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, True)
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
If Not MyBase.Visible Then Return
Dim StrAttr As New System.Drawing.StringFormat()
StrAttr.Alignment = System.Drawing.StringAlignment.Center
StrAttr.LineAlignment = System.Drawing.StringAlignment.Center
For iTab As Integer = 0 To MyBase.TabCount - 1
If MyBase.SelectedIndex <> iTab Then
DrawVisualStyles(e.Graphics, MyBase.GetTabRect(iTab), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal)
e.Graphics.DrawString(MyBase.TabPages(iTab).Text, System.Drawing.SystemFonts.MenuFont, System.Drawing.SystemBrushes.MenuText, MyBase.GetTabRect(iTab), StrAttr)
End If
Next iTab
DrawVisualStyles(e.Graphics, System.Drawing.Rectangle.Inflate(MyBase.GetTabRect(MyBase.SelectedIndex), 2, 2), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Pressed)
e.Graphics.DrawString(MyBase.TabPages(MyBase.SelectedIndex).Text, System.Drawing.SystemFonts.MenuFont, System.Drawing.SystemBrushes.MenuHighlight, MyBase.GetTabRect(MyBase.SelectedIndex), StrAttr)
MyBase.OnPaint(e)
End Sub
Private Sub DrawVisualStyles(ByVal g As System.Drawing.Graphics, ByVal Rect As System.Drawing.Rectangle, ByVal Element As System.Windows.Forms.VisualStyles.VisualStyleElement)
Dim renderer As New System.Windows.Forms.VisualStyles.VisualStyleRenderer(Element)
renderer.DrawBackground(g, Rect)
End Sub
cs_Sipat
Messages postés71Date d'inscriptionmardi 26 octobre 2004StatutMembreDernière intervention15 avril 2007 26 févr. 2007 à 19:26
Bonsoir, ouhaaaa c'est compliqué ! qu'il est beau ce petit neon orangé !
Je me suis aperçu qu par ce moyen je ne peux pas changer la police j'ai beau mettre 20 ou 72 elle reste identique !
Donc il faudrait pouvoir modifier la grosseur de la police.
Il y a aussi un truc que je trouve bien c'est la couleur du texte de l'onglet quand il a le focus( comment on determine cette couleur ?)
Mais pour en revenir au but du départ c'est de changer la couleur en dessous du texte de l'onglet pour qu'elle correspond avec TabControl
Voilà un modéle.
cs_Sipat
Messages postés71Date d'inscriptionmardi 26 octobre 2004StatutMembreDernière intervention15 avril 2007 26 févr. 2007 à 20:37
Il y a une erreur dans le code:
Protected
Overrides
Sub OnPaint(
ByVal e
As System.Windows.Forms.PaintEventArgs)
Dim StrAttr
As
New System.Drawing.StringFormat()
StrAttr.Alignment = System.Drawing.StringAlignment.Center
StrAttr.LineAlignment = System.Drawing.StringAlignment.Center
If
Not (
MyBase.Visible(ThenReturn))
'
Then 'Erreur 1 'Public Property Visible() As Boolean' n'a aucun paramètre et son type de retour ne peut pas être indexé. C:\Documents and Settings\WindowsApplication1\Form1.Designer.vb 32 21 WindowsApplication1
Erreur 2 Le nom 'ThenReturn' n'est pas déclaré. C:\Documents and Settings\WindowsApplication1\Form1.Designer.vb 32 36 WindowsApplication1
End
Sub
Protected
Overrides
Sub OnPaint(
ByVal e
As System.Windows.Forms.PaintEventArgs)
If
Not
MyBase.Visible
Then
Return
DrawVisualStyles(e.Graphics,
New System.Drawing.Rectangle(
MyBase.ClientRectangle.Left,
MyBase.DisplayRectangle.Top - 2,
MyBase.ClientRectangle.Width,
MyBase.ClientRectangle.Height -
MyBase.DisplayRectangle.Top + 2), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.Pane.Normal)
Dim StrAttr
As
New System.Drawing.StringFormat()
StrAttr.Alignment = System.Drawing.StringAlignment.Center
StrAttr.LineAlignment = System.Drawing.StringAlignment.Center
For iTab
As
Integer = 0
To
MyBase.TabCount - 1
If
MyBase.SelectedIndex <> iTab
Then
DrawVisualStyles(e.Graphics,
MyBase.GetTabRect(iTab), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal)
e.Graphics.FillRectangle(
New System.Drawing.SolidBrush(
MyBase.TabPages(iTab).BackColor),
New System.Drawing.Rectangle(
MyBase.GetTabRect(iTab).Left + 1,
MyBase.GetTabRect(iTab).Top + 3,
MyBase.GetTabRect(iTab).Width - 2,
MyBase.GetTabRect(iTab).Height - 3))
e.Graphics.DrawString(
MyBase.TabPages(iTab).Text, System.Drawing.SystemFonts.MenuFont, System.Drawing.SystemBrushes.MenuText,
MyBase.GetTabRect(iTab), StrAttr)
End
If
Next iTab
DrawVisualStyles(e.Graphics, System.Drawing.Rectangle.Inflate(
MyBase.GetTabRect(
MyBase.SelectedIndex), 2, 2), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Pressed)
e.Graphics.FillRectangle(
New System.Drawing.SolidBrush(
MyBase.TabPages(
MyBase.SelectedIndex).BackColor),
New System.Drawing.Rectangle(
MyBase.GetTabRect(
MyBase.SelectedIndex).Left - 1,
MyBase.GetTabRect(
MyBase.SelectedIndex).Top + 1,
MyBase.GetTabRect(
MyBase.SelectedIndex).Width + 2,
MyBase.GetTabRect(
MyBase.SelectedIndex).Height))
e.Graphics.DrawString(
MyBase.TabPages(
MyBase.SelectedIndex).Text,
New System.Drawing.Font(System.Drawing.SystemFonts.MenuFont.FontFamily, 12, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Red,
MyBase.GetTabRect(
MyBase.SelectedIndex), StrAttr)
MyBase.OnPaint(e)
End
Sub
Private
Sub DrawVisualStyles(
ByVal g
As System.Drawing.Graphics,
ByVal Rect
As System.Drawing.Rectangle,
ByVal Element
As System.Windows.Forms.VisualStyles.VisualStyleElement)
Dim renderer
As
New System.Windows.Forms.VisualStyles.VisualStyleRenderer(Element)
renderer.DrawBackground(g, Rect)
cs_Sipat
Messages postés71Date d'inscriptionmardi 26 octobre 2004StatutMembreDernière intervention15 avril 2007 27 févr. 2007 à 09:45
Bonjour,
J'ai changé la police pour voir mais l'onglet ne s'allonge pas.
A par ça c'est vraiment bien, tu fais presque ce que tu veux en VB c'est dingue !
Tu as vraiment bien compris comment ça fonctionne pas comme moi !
Je n'ai pas trouvé comment tu determines l'épaisseur du néon orangé et la couleur ?
Pour la taille, c'est les coordonnées du FillRectangle. Mais c'est la couleur que tu déplace et non le néon sport.
Pour la taille de l'onglet, c'est e, fonction de la longeur du text dans la police normal. Tu n'as qu'a mettre des espace devant ou derriere le texte de l'onglet que tu supprimera lors de l'affichage.
e.Graphics.DrawString(MyBase.TabPages(MyBase.SelectedIndex).Text.Trim(), New System.Drawing.Font(System.Drawing.SystemFonts.MenuFont.FontFamily, 20, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Red, MyBase.GetTabRect(MyBase.SelectedIndex), StrAttr)
J'en reviens à la police :
Je maitrise la grosseur et la couleur quand l'onglet a le focus,
Mais je ne peux pas changer la grosseur de la police et la couleur quand il n'y a pas le focus comme sur l'image TabPage2 et TabPage3 le texte et plus petit et je ne peux le grossir.
Tu crois que c'est possible?
J'ai été agréablement surpris de voir quand changeant la couleur de fond l'onglet prenait la même couleur ! c'est vraiment bien.
Merci Kenji
For iTab As Integer = 0 To MyBase.TabCount - 1
If MyBase.SelectedIndex <> iTab Then
DrawVisualStyles(e.Graphics, MyBase.GetTabRect(iTab), System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal)
e.Graphics.FillRectangle(New System.Drawing.SolidBrush(MyBase.TabPages(iTab).BackColor), New System.Drawing.Rectangle(MyBase.GetTabRect(iTab).Left + 1, MyBase.GetTabRect(iTab).Top + 3, MyBase.GetTabRect(iTab).Width - 2, MyBase.GetTabRect(iTab).Height - 3))
e.Graphics.DrawString(MyBase.TabPages(iTab).Text, New System.Drawing.Font(System.Drawing.SystemFonts.MenuFont.FontFamily, 10, System.Drawing.FontStyle.Bold), System.Drawing.SystemBrushes.MenuText, MyBase.GetTabRect(iTab), StrAttr)
End If
Next iTab