IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

[VB.NET] Modifier le background d'un TabControl


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 212
    Par défaut
    encore une fois mille mercis à toi

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 212
    Par défaut
    oups j'ai encore un truc à te demander cher Neguib

    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 ?



    Merci

    Ludo

  3. #3
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    Citation Envoyé par exclusif
    ...mais par contre la couleur de fond du TabControl n'est plus transparente ..
    Ah bon et comment tu avais réussi à rendre ton TabControl Transparent avant :

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 212
    Par défaut
    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.

  5. #5
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    montre moi l'image de ce que tu avais avant comme onglet complet

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 212
    Par défaut
    la voici :


  7. #7
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    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

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 212
    Par défaut
    oki merci bcp

  9. #9
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 212
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  10. #10
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 212
    Par défaut
    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...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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);
    }
    je le mets dès fois que ça serve à certains.

    Ludo

  11. #11
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    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

  12. #12
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 212
    Par défaut
    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

  13. #13
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    Merci pour la dll

  14. #14
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2004
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 64
    Par défaut
    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

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. [VB.NET]Modifier le background d'une MessageBox
    Par informix2006 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 26/04/2006, 00h37
  2. [.NET]Modifier les variables d'environnement dans...
    Par GusS dans le forum Général Dotnet
    Réponses: 4
    Dernier message: 09/02/2005, 16h25
  3. [MFC] Background D'une TabControl
    Par Muby53 dans le forum MFC
    Réponses: 4
    Dernier message: 13/11/2004, 22h34
  4. [VB.NET] Cache l'onglet d'un TabControl
    Par Lois dans le forum Windows Forms
    Réponses: 14
    Dernier message: 27/10/2004, 09h55
  5. [VB.NET] Couleurs des onglets d'un TabControl
    Par ineznia dans le forum Windows Forms
    Réponses: 6
    Dernier message: 09/04/2004, 13h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo