Bonjour,
Où puis-je trouver svp la chronologie complète des évènements dotnet ?
Et autre question, comment puis-je coloriser différement chaque TabPage d'un TabControl (Onglet compris) ?
Merci bcp pour vos réponses
Ludo
Version imprimable
Bonjour,
Où puis-je trouver svp la chronologie complète des évènements dotnet ?
Et autre question, comment puis-je coloriser différement chaque TabPage d'un TabControl (Onglet compris) ?
Merci bcp pour vos réponses
Ludo
pour quel composant svp :?:Citation:
Envoyé par exclusif
En utilisant GDI+ et l'objet System.Drawing.Graphics notammentCitation:
Envoyé par exclusif
merci bcp pour les reponses.
Concernant la chronologie des évènements c'est surtout pour une form et une treeview.
Débutant en langage vb.net (moins de 50 lignes de code), peux tu m'expliquer ou me donner un exemple de code pour utiliser gdi+ afin de colorer un TabPage ?
Merci d'avance
Ludo
Voici une entrée de la doc MSDN pour comprendre la chronologie de certains evenement des derivés de la classe Control :
:arrow: Événement Control
le premier étant donc Enter
Dans un premier temps concernant GDI+, je prefère que tu lises un peu en fouillant dans cette entrée MSDN tout ce qui te permettra de te familiariser avec ses classes et membres
Dans un second temps tu seras donc mieux disposer à ce que je pourrai te montrer comme code
:arrow: Utilisation des classes managées GDI+
ok :)
super je te remercie bcp :))
bonjour,
je n'arrive toujours pas à colorer les onglets d'un TabControl :'(
Même après avoir lu tout ce qu'il faut savoir sur le GDI+.
Personne n'a la solution svp ???
Merci
Ludo
il y en a de nombreuses donc faut que tu me precises ton cahier des charges
1. Est-ce provoqué par une action utilisateur
2. Est-ce un nouveau TabControl qui te permettrait d'exposer un nouveau type de propriété
3. Quelles couleurs, quels TabPages ??,
Enfin va-y décris moi de façon très très détaillé, utilises l'email da,s mon profil si ta doc est longue à decrire, je te donnerai une marche à suivre avec exemple ici
Ben en fait j'ai un TabControl qui se compose de 4 onglets bien définis et je voudrais que chaque TapPage (ainsi que l'onglet) soit d'une couleur bien définie et fixe (genre un onglet bleu, un rouge, un vert et un jaune) et ce dès le chargement de mon formulaire et jusqu'à la fermeture de celui-ci.
C'est cool de bien vouloir m'aider :)
Ludo
ok et le ForeColor du texte il est de quel couleur :?:
je le laisse noir le forecolor, par contre concernant les couleurs je voudrais des couleurs pastels.
Bon au pif je te mets le texte en noir pour tous les onglets, tu adapteras par toi même
Donc le principe est de developpé ton propre TabControl : MyTabControl afin d'implementer le Delegate DrawItem
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 Imports System Imports System.Drawing Imports System.Windows.Forms Public Class MyTabControl Inherits TabControl '... Private Sub MyTabControl_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs) Handles MyBase.DrawItem 'declarer les brosses pour peindre le fond et le texte Dim backBrush As SolidBrush Dim foreBrush As SolidBrush 'recuperer le rectangleF de l'onglet avec la marge Dim rF As RectangleF = New RectangleF(e.Bounds.X, e.Bounds.Y + Me.Padding.Y, e.Bounds.Width, e.Bounds.Height - Me.Padding.Y) 'instancier un format de texte Dim strF As New System.Drawing.StringFormat() 'formater l'alignement du texte strF.Alignment = StringAlignment.Center ' selon l'index du TabPage en cours d'être dessiné ' instancier la brosse pour la couleur de fond Select Case e.Index Case 0: backBrush = New SolidBrush(Color.Blue) Case 1: backBrush = New SolidBrush(Color.Red) Case 2: backBrush = New SolidBrush(Color.Green) Case 3: backBrush = New SolidBrush(Color.Yellow) Case Else: backBrush = New SolidBrush(Me.BackColor) End Select 'instancier la brosse pour le texte foreBrush = New SolidBrush(Color.Black) 'peindre le fond de l'onglet e.Graphics.FillRectangle(backBrush, e.Bounds) 'peindre le texte de l'onglet e.Graphics.DrawString(Me.TabPages(e.Index).Text, e.Font, foreBrush, rF, strF) End Sub End Class
Merci bcp Neguib :)
Dès que je rentre chez moi je teste tout ça.
Encore une fois mille mercis !
Ludo
Je viens de tester j'ai donc ajouté une classe à mon projet dans laquelle j'ai collé le code que tu m'as donné. Ensuite je suis allé sur ma form et j'ai ajouté le nouveau composant ainsi créé à partir de la ToolBox. Hélas après compilation je n'ai toujours pas de couleur pour mes onglets :'(
Où me suis-je trompé ???
montre moi le code généré automatiquement dans la Form, notamment la declaration du TabControl et son instanciation dans InitializeComponent
Voici le code généré :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100 <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.MyTabControl1 = New WindowsApplication1.MyTabControl Me.TabPage1 = New System.Windows.Forms.TabPage Me.TabPage2 = New System.Windows.Forms.TabPage Me.TabPage3 = New System.Windows.Forms.TabPage Me.TabPage4 = New System.Windows.Forms.TabPage Me.MyTabControl1.SuspendLayout() Me.SuspendLayout() ' 'MyTabControl1 ' Me.MyTabControl1.Controls.Add(Me.TabPage1) Me.MyTabControl1.Controls.Add(Me.TabPage2) Me.MyTabControl1.Controls.Add(Me.TabPage3) Me.MyTabControl1.Controls.Add(Me.TabPage4) Me.MyTabControl1.Location = New System.Drawing.Point(12, 12) Me.MyTabControl1.Name = "MyTabControl1" Me.MyTabControl1.SelectedIndex = 0 Me.MyTabControl1.Size = New System.Drawing.Size(268, 242) Me.MyTabControl1.TabIndex = 0 ' 'TabPage1 ' Me.TabPage1.Location = New System.Drawing.Point(4, 22) Me.TabPage1.Name = "TabPage1" Me.TabPage1.Padding = New System.Windows.Forms.Padding(3) Me.TabPage1.Size = New System.Drawing.Size(260, 216) Me.TabPage1.TabIndex = 0 Me.TabPage1.Text = "TabPage1" Me.TabPage1.UseVisualStyleBackColor = True ' 'TabPage2 ' Me.TabPage2.Location = New System.Drawing.Point(4, 22) Me.TabPage2.Name = "TabPage2" Me.TabPage2.Padding = New System.Windows.Forms.Padding(3) Me.TabPage2.Size = New System.Drawing.Size(74, 51) Me.TabPage2.TabIndex = 1 Me.TabPage2.Text = "TabPage2" Me.TabPage2.UseVisualStyleBackColor = True ' 'TabPage3 ' Me.TabPage3.Location = New System.Drawing.Point(4, 22) Me.TabPage3.Name = "TabPage3" Me.TabPage3.Padding = New System.Windows.Forms.Padding(3) Me.TabPage3.Size = New System.Drawing.Size(260, 216) Me.TabPage3.TabIndex = 2 Me.TabPage3.Text = "TabPage3" Me.TabPage3.UseVisualStyleBackColor = True ' 'TabPage4 ' Me.TabPage4.Location = New System.Drawing.Point(4, 22) Me.TabPage4.Name = "TabPage4" Me.TabPage4.Padding = New System.Windows.Forms.Padding(3) Me.TabPage4.Size = New System.Drawing.Size(260, 216) Me.TabPage4.TabIndex = 3 Me.TabPage4.Text = "TabPage4" Me.TabPage4.UseVisualStyleBackColor = True ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.MyTabControl1) Me.Name = "Form1" Me.Text = "Form1" Me.MyTabControl1.ResumeLayout(False) Me.ResumeLayout(False) End Sub Friend WithEvents MyTabControl1 As WindowsApplication1.MyTabControl Friend WithEvents TabPage1 As System.Windows.Forms.TabPage Friend WithEvents TabPage2 As System.Windows.Forms.TabPage Friend WithEvents TabPage3 As System.Windows.Forms.TabPage Friend WithEvents TabPage4 As System.Windows.Forms.TabPage End Class
La seule difference avec mon propre test est cette modification de propriété
ainsi les onglets sont dessinés par la fenêtre parente et non par le systeme d'exploitationCode:Me.MyTabControl1 .DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
ajoutes-le et dis-moi :?:
ca fonctionne a merveille !!!
merci t genial et super cool d'avoir passé du temps sur mon problème avec une telle efficacité en plus !!!!
Merciiiiiiii !
J'ai une dernière question à te poser Neguib. Est-ce possible de colorer les onglets non pas en fonction de leur index mais en fonction de leur Name.
Je m'explique, je dispose de 4 onglets dont 3 sont cachés au départ. Je les fait apparaitre indépendemment que quand l'utilisateur clique sur un bouton précis et je voudrais que chaque couleur soit donc associée non pas à la position de l'onglet dans MyTabControl mais à son Name. Est-ce possible ou pas ?
J'ai essayé de modifier la classe MyTabControl que tu m'as créé en vain.
Merci pour ta reponse.
Ludo
voici ma modification. Tout fonctionne les couleurs sont bien attribuées à un TabName mais est-ce que tu penses que mon code est correct pas trop compliqué ?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 Select Case e.Index Case 0 Select Case Form1.MyTabControl1.TabPages(e.Index).Name Case "TabPage1" : backBrush = New SolidBrush(Color.Blue) Case "TabPage2" : backBrush = New SolidBrush(Color.Red) Case "TabPage3" : backBrush = New SolidBrush(Color.Green) Case "TabPage4" : backBrush = New SolidBrush(Color.Yellow) Case Else : backBrush = New SolidBrush(Me.BackColor) End Select Case 1 Select Case Form1.MyTabControl1.TabPages(e.Index).Name Case "TabPage1" : backBrush = New SolidBrush(Color.Blue) Case "TabPage2" : backBrush = New SolidBrush(Color.Red) Case "TabPage3" : backBrush = New SolidBrush(Color.Green) Case "TabPage4" : backBrush = New SolidBrush(Color.Yellow) Case Else : backBrush = New SolidBrush(Me.BackColor) End Select Case 2 Select Case Form1.MyTabControl1.TabPages(e.Index).Name Case "TabPage1" : backBrush = New SolidBrush(Color.Blue) Case "TabPage2" : backBrush = New SolidBrush(Color.Red) Case "TabPage3" : backBrush = New SolidBrush(Color.Green) Case "TabPage4" : backBrush = New SolidBrush(Color.Yellow) Case Else : backBrush = New SolidBrush(Me.BackColor) End Select Case 3 Select Case Form1.MyTabControl1.TabPages(e.Index).Name Case "TabPage1" : backBrush = New SolidBrush(Color.Blue) Case "TabPage2" : backBrush = New SolidBrush(Color.Red) Case "TabPage3" : backBrush = New SolidBrush(Color.Green) Case "TabPage4" : backBrush = New SolidBrush(Color.Yellow) Case Else : backBrush = New SolidBrush(Me.BackColor) End Select Case Else backBrush = New SolidBrush(Me.BackColor) End Select
Comme je ne comprends pas trop où tu as mis ce code je prefere partir de la classe MyTabControl, en attendant je te propose d'utiliser la propriété Tag du TabPage, ainsi cela ne dependra ni de l'index ni du nom mais le TabPage indiquera lui même la couleur souhaité (l'ideal étant bien plus tard de developper ta propre classe TabPage qui exposerai une propriété OngletBackColor et une OngletForeColor)
Il ne reste plus qu'à initialiser la propriété Tag de chacun de tes TabPages par une couleur.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 Imports System Imports System.Drawing Imports System.Windows.Forms Public Class MyTabControl Inherits TabControl '... Private Sub MyTabControl_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs) Handles MyBase.DrawItem Dim backBrush As SolidBrush Dim foreBrush As SolidBrush Dim rF As RectangleF = New RectangleF(e.Bounds.X, e.Bounds.Y + Me.Padding.Y, e.Bounds.Width, e.Bounds.Height - Me.Padding.Y) Dim strF As New System.Drawing.StringFormat() strF.Alignment = StringAlignment.Center 'recupérer le TabPage en cours Dim tb As TabPage = CType(sender, TabControl).TabPages(e.Index) 'recupérer la couleur dans la propriété Tag du TabPage en cours Dim backColor As Color = CType(tb.Tag, Color) 'si une valeur existe If Not IsNothing(backColor) Then : backBrush = New SolidBrush(backColor) 'sinon definir un backColor par defaut Else : backBrush = New SolidBrush(Me.BackColor) End IfSelect Case e.Index foreBrush = New SolidBrush(Color.Black) e.Graphics.FillRectangle(backBrush, e.Bounds) e.Graphics.DrawString(Me.TabPages(e.Index).Text, e.Font, foreBrush, rF, strF) End Sub End Class
Attention si tu le fais en mode Design, méfies-toi car si tu mets dans la boîte de propriété Tag: Color.Blue c'est transformer en String dans le code generé automatiquement
Donc à modifier :wink:Code:Me.MonTabPage.Tag = "Color.Blue"
encore une fois mille mercis à toi :)
oups j'ai encore un truc à te demander cher Neguib :oops:
Lorsque MyTabControl est dessiné les couleurs sont bien attribuées aux onglets mais par contre la couleur de fond du TabControl n'est plus transparente et donc ca ne fait pas trop esthétique. Est-ce possible de corriger ce problème car je ne trouve pas de propriété la définissant ?
http://rc200x.free.fr/temp/MyTabControl.JPG
Merci
Ludo
Ah bon et comment tu avais réussi à rendre ton TabControl Transparent avant :?:Citation:
Envoyé par exclusif
ben je pense qu'il était transparent car c'est le style XP qui lui donnait cette propriété. Sinon sais-tu comment faire afficher une image sur les onglets modifiés car ils n'apparaissent plus alors qu'un espace vide se crée là où elle devraient apparaitre ?
C'est la folie ses onglets je galère grave avec. Heureusement que tu as bien voulu m'aider car je n'y serai jamais arrivé tout seul sinon. Merci encore.
montre moi l'image de ce que tu avais avant comme onglet complet
la voici :
http://rc200x.free.fr/temp/TabControl.jpg
Bon ok, mais là effectivement je vais te laisser un peu coder seul puisque le principe n'est pas bien compliqué
Dans la nouvelle classe TabControl, dans DrawItem il te faut simplment maitriser la nouvelle longueur de chaine à ecrire pour pouvoir dessiner l'icône
Donc
SI Me.ImageList n'est pas Nothing je calcule le recTangleF de la chaine d'une façon
SINON je le calcule d'une autre façon
De plus je dessine une Image (e.Graphics.DrawImage) à l'endroit que j'indique par un autre rectangle
Allez lances-toi et montres moi si vraiment tu ne t'en sors pas :wink:
oki merci bcp :)
je n'arrive toujours pas a modifier la couleur de fond d'un tabcontrol :(
Quelqu'un n'aurait-il pas la solution svp ?
J'ai essayé enormément de code différent pour arriver à mes fins mais le code modifier également l'apparence des onglets que Neguib a réussi à personnaliser et du coup tout foire....:(
Merci pour vos reponses.
Ludo
PS : Voici le code que j'ai trouvé pour modifier un TabControl mais je voudrais uniquement récupérer la possibilité de modifier le background d'un TabControl svp
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231 Imports System.ComponentModel Imports System.Runtime.InteropServices Imports System.Reflection Public Class TabControlEX Inherits System.Windows.Forms.TabControl #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call SetStyle(ControlStyles.AllPaintingInWmPaint Or _ ControlStyles.DoubleBuffer Or _ ControlStyles.ResizeRedraw Or _ ControlStyles.UserPaint, True) End Sub 'UserControl1 overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container End Sub #End Region #Region " InterOP " <StructLayout(LayoutKind.Sequential)> _ Private Structure NMHDR Public HWND As Int32 Public idFrom As Int32 Public code As Int32 Public Overloads Function ToString() As String Return String.Format("Hwnd: {0}, ControlID: {1}, Code: {2}", HWND, idFrom, code) End Function End Structure Private Const TCN_FIRST As Int32 = &HFFFFFFFFFFFFFDDA& Private Const TCN_SELCHANGING As Int32 = (TCN_FIRST - 2) Private Const WM_USER As Int32 = &H400& Private Const WM_NOTIFY As Int32 = &H4E& Private Const WM_REFLECT As Int32 = WM_USER + &H1C00& #End Region #Region " BackColor Manipulation " 'As well as exposing the property to the Designer we want it to behave just like any other 'controls BackColor property so we need some clever manipulation. Private m_Backcolor As Color = Color.Empty <Browsable(True), _ Description("The background color used to display text and graphics in a control.")> _ Public Overrides Property BackColor() As Color Get If m_Backcolor.Equals(Color.Empty) Then If Parent Is Nothing Then Return Control.DefaultBackColor Else Return Parent.BackColor End If End If Return m_Backcolor End Get Set(ByVal Value As Color) If m_Backcolor.Equals(Value) Then Return m_Backcolor = Value Invalidate() 'Let the Tabpages know that the backcolor has changed. MyBase.OnBackColorChanged(EventArgs.Empty) End Set End Property Public Function ShouldSerializeBackColor() As Boolean Return Not m_Backcolor.Equals(Color.Empty) End Function Public Overrides Sub ResetBackColor() m_Backcolor = Color.Empty Invalidate() End Sub #End Region Protected Overrides Sub OnParentBackColorChanged(ByVal e As System.EventArgs) MyBase.OnParentBackColorChanged(e) Invalidate() End Sub Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs) MyBase.OnSelectedIndexChanged(e) Invalidate() End Sub Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) e.Graphics.Clear(BackColor) Dim r As Rectangle = Me.ClientRectangle If TabCount <= 0 Then Return 'Draw a custom background for Transparent TabPages r = SelectedTab.Bounds Dim sf As New StringFormat sf.Alignment = StringAlignment.Center sf.LineAlignment = StringAlignment.Center Dim DrawFont As New Font(Font.FontFamily, 24, FontStyle.Regular, GraphicsUnit.Pixel) ControlPaint.DrawStringDisabled(e.Graphics, "Micks Ownerdraw TabControl", DrawFont, BackColor, RectangleF.op_Implicit(r), sf) DrawFont.Dispose() 'Draw a border around TabPage r.Inflate(3, 3) Dim tp As TabPage = TabPages(SelectedIndex) Dim PaintBrush As New SolidBrush(tp.BackColor) e.Graphics.FillRectangle(PaintBrush, r) 'ControlPaint.DrawBorder(e.Graphics, r, PaintBrush.Color, ButtonBorderStyle.Solid) ControlPaint.DrawBorder(e.Graphics, r, PaintBrush.Color, ButtonBorderStyle.Dotted) 'Draw the Tabs For index As Integer = 0 To TabCount - 1 tp = TabPages(index) r = GetTabRect(index) 'Dim bs As ButtonBorderStyle = ButtonBorderStyle.Outset Dim bs As ButtonBorderStyle = ButtonBorderStyle.Inset If index = SelectedIndex Then bs = ButtonBorderStyle.None PaintBrush.Color = tp.BackColor e.Graphics.FillRectangle(PaintBrush, r) '===================================================================== ControlPaint.DrawBorder(e.Graphics, r, PaintBrush.Color, bs) '===================================================================== PaintBrush.Color = tp.ForeColor 'Set up rotation for left and right aligned tabs If Alignment = TabAlignment.Left Or Alignment = TabAlignment.Right Then Dim RotateAngle As Single = 90 If Alignment = TabAlignment.Left Then RotateAngle = 270 Dim cp As New PointF(r.Left + (r.Width \ 2), r.Top + (r.Height \ 2)) e.Graphics.TranslateTransform(cp.X, cp.Y) e.Graphics.RotateTransform(RotateAngle) r = New Rectangle(-(r.Height \ 2), -(r.Width \ 2), r.Height, r.Width) End If 'Draw the Tab Text If tp.Enabled Then e.Graphics.DrawString(tp.Text, Font, PaintBrush, RectangleF.op_Implicit(r), sf) Else ControlPaint.DrawStringDisabled(e.Graphics, tp.Text, Font, tp.BackColor, RectangleF.op_Implicit(r), sf) End If e.Graphics.ResetTransform() Next PaintBrush.Dispose() End Sub <Description("Occurs as a tab is being changed.")> _ Public Event SelectedIndexChanging As SelectedTabPageChangeEventHandler Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = (WM_REFLECT + WM_NOTIFY) Then Dim hdr As NMHDR = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(NMHDR)), NMHDR) If hdr.code = TCN_SELCHANGING Then Dim tp As TabPage = TestTab(Me.PointToClient(Windows.Forms.Cursor.Position)) If Not tp Is Nothing Then Dim e As New TabPageChangeEventArgs(Me.SelectedTab, tp) RaiseEvent SelectedIndexChanging(Me, e) If e.Cancel OrElse tp.Enabled = False Then m.Result = New IntPtr(1) Return End If End If End If End If MyBase.WndProc(m) End Sub Private Function TestTab(ByVal pt As Point) As TabPage For index As Integer = 0 To TabCount - 1 If GetTabRect(index).Contains(pt.X, pt.Y) Then Return TabPages(index) End If Next Return Nothing End Function End Class #Region " EventArgs Class's " Public Class TabPageChangeEventArgs Inherits EventArgs Private _Selected As TabPage Private _PreSelected As TabPage Public Cancel As Boolean = False Public ReadOnly Property CurrentTab() As TabPage Get Return _Selected End Get End Property Public ReadOnly Property NextTab() As TabPage Get Return _PreSelected End Get End Property Public Sub New(ByVal CurrentTab As TabPage, ByVal NextTab As TabPage) _Selected = CurrentTab _PreSelected = NextTab End Sub End Class Public Delegate Sub SelectedTabPageChangeEventHandler(ByVal sender As Object, ByVal e As TabPageChangeEventArgs) #End Region
je n'arrive toujours pas à modifier ce satané background c'est exaspérant....:(
j'ai trouvé également ce code en c# mais ca ne peut pas s'appliquer dans mon cas car moi j'ai un Tabcontrol Multiline...
je le mets dès fois que ça serve à certains.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 protected override void OnDrawItem(DrawItemEventArgs e) { e.Graphics.FillRectangle(new SolidBrush(Color.Lavender), this.GetTabRect(this.TabCount -1).Right,e.Bounds.Top, this.ClientRectangle.Right-this.GetTabRect(this.TabCount -1).Right, e.Bounds.Bottom - e.Bounds.Top); e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Gray)), this.ClientRectangle.Right-1, this.ClientRectangle.Top, this.ClientRectangle.Right-1, e.Bounds.Bottom); e.Graphics.DrawLine(new Pen(new SolidBrush(Color.White)), this.ClientRectangle.Left, this.ClientRectangle.Top, this.ClientRectangle.Right, this.ClientRectangle.Top); e.Graphics.FillRectangle(new SolidBrush(Color.LightSteelBlue), e.Bounds.Left - 1, e.Bounds.Top, e.Bounds.Width +1, e.Bounds.Height); SizeF stringSize = new SizeF(); stringSize = e.Graphics.MeasureString(this.TabPages[e.Index].Text, e.Font,e.Bounds.Width, StringFormat.GenericDefault); float CenterX = (e.Bounds.Width - stringSize.Width)/2; float CenterY = (e.Bounds.Height - stringSize.Height)/2; e.Graphics.DrawString(this.TabPages[e.Index].Text, e.Font, new SolidBrush(Color.Black), e.Bounds.Left + CenterX, e.Bounds.Top + CenterY+1, StringFormat.GenericDefault); base.OnDrawItem (e); }
Ludo
Salut exclusif
je ne t'avais pas oublier, j'ai retourné le problème dans tous les sens et j'en arrive à la conclusion que tu ne peux echapper au developpement C++ d'un contrôle MFC spécifique, dont voici un modèle possible:
http://www.codeproject.com/tabctrl/customtab.asp
:)
Thanks a lot Neguib !
J'ai aussi trouvé une dll qui est un TabControl qui permet justement de tout modifier y compris le styles onglets. De plus ce contrôle est gratuit :)
http://homepage.ntlworld.com/mdaudi1...bControlEX.dll
Ludo
Merci :ccool: pour la dll
Désolé pour le up mais ... on ne peut pas modifier la backColor d'un tabControl sans faire tout cela ?
je comprends pas qu'il n'y ait pas de propriété adéquate o_O