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 :

Container comme celui de la boite à outils dans Visual Studio


Sujet :

Windows Forms

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    335
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2011
    Messages : 335
    Points : 111
    Points
    111
    Par défaut Container comme celui de la boite à outils dans Visual Studio
    Bonjour à tous,

    Comment faire pour avoir un container du même type que celui utilisé pour la boite à outil dans visual studio?



    Quelque chose qui Cache/Decouvre une partie du menu...


    Merci d'avance

  2. #2
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    1 048
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2009
    Messages : 1 048
    Points : 2 201
    Points
    2 201
    Par défaut
    Pour la gestion des fenêtre à la Visual Studio il y a:

    http://sourceforge.net/projects/dockpanelsuite/

    Autrement pour la liste, ça ressemble à un treeview customisé (le fameux contrôle windows avec le +).

  3. #3
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    335
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2011
    Messages : 335
    Points : 111
    Points
    111
    Par défaut
    Merci Sinople,

    Ce n'est pas le docking que je recherche, mais plutot ce qui ressemble au TreeView...Mais pas pour mettre des lignes mais des objets.

    En fait ce serait des pages qui se Expand/Collapse à la manière du TreeView custom de VisualStudio pour la ToollBox...

    Voyez ce que je veux dire?

  4. #4
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Autrement pour la liste, ça ressemble à un treeview customisé (le fameux contrôle windows avec le +).
    +1
    Voyez ce que je veux dire?
    Non.
    On peut redéssiner comme on veut une ligne de TreeView et y insérer du texte et des images (mais pas des controls).
    " Le croquemitaine ! Aaaaaah ! Où ça ? " ©Homer Simpson

  5. #5
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour gualino .
    Ce n'est pas un TreeView comme l'as dit Graffito.
    Le treeview ne permet pas de gerer que du contenu string.
    En fait ce que tu cherche c'est un controle Panneau Extensible(Collapsible Panel) qui est un custom control panel .
    C'est assez complexe mais realisable .
    En voici un exemple .
    Il est compose d'un Custom Button du type Toggle ou Bouton Bascule inclus lui-meme dans un Custom Panel .
    Lors d'un click sur le Custom Button et suivant l'etat du bouton le Custom Panel agrandit ou retrecit sa hauteur.
    Pour avoir une transition douce entre les 2 etats agrandi-retrecit le custom panel est dote ... oui d'un timer qui agrandit sa hauteur jusqu'a oldHeight (hauteur initiale) puis la ratrecit au click suivant jusqu'à arriver à hauteur du Custom Bouton (sinon il va faire disparaitre ce dernier).
    Le code du CollapseButton comporte un dessin d'une fleche qui provient de la lib RenderStyleButton du Net Framework prebuilt mais que tu peux remplacer par 2 images :l'une avec un rectangle et un signe + ,l'autre avec rectangle et un signe -.

    ci-apres le 1er code du CollapseButton(2 fleches) et du CollapsePanel original:
    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
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
     
     
    'Le CUSTOM BUTTON 
    Imports System.Drawing.Drawing2D
    Imports System.Drawing.Design
    Imports System.ComponentModel
    Imports System.Windows.Forms.VisualStyles
     
     
    Public Class CollapseButton
        Inherits StateButtonBase
     
        ' Property fields
        Private _collapsed As Boolean
     
     
        Public Sub New()
            Me.SetStyle(ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
            Me.DoubleBuffered = True
        End Sub
     
     
        Public Property Collapsed() As Boolean
            Get
                Return _collapsed
            End Get
            Set(ByVal value As Boolean)
                If value <> _collapsed Then
                    _collapsed = value
                    Invalidate()
                End If
            End Set
        End Property
     
        Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
            MyBase.OnTextChanged(e)
            Invalidate()
        End Sub
     
        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            Dim renderer As VisualStyleRenderer
     
            ' Paint parent background
            InvokePaintBackground(Me, New PaintEventArgs(e.Graphics, ClientRectangle))
     
            ' Paint background
            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupHead.Normal)
            'renderer.DrawBackground(e.Graphics, new Rectangle(0, 0, e.ClipRectangle.Width, 25));
            renderer.DrawBackground(e.Graphics, ClientRectangle)
     
            ' Draw Text
            Dim fontRect As New Rectangle(17, 6, Me.Width - 17 - 24, Me.Height)
     
            If (State And StateButtonState.Pressed) <> 0 Then
                TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, fontRect, SystemColors.InactiveCaption, TextFormatFlags.Top Or TextFormatFlags.Left)
            Else
                If (State And StateButtonState.MouseHover) <> 0 Then
                    TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, fontRect, SystemColors.InactiveCaption, TextFormatFlags.Top Or TextFormatFlags.Left)
                Else
                    If Not Enabled Then
                        TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, fontRect, SystemColors.GrayText, TextFormatFlags.Top Or TextFormatFlags.Left)
                    Else
                        TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, fontRect, SystemColors.MenuHighlight, TextFormatFlags.Top Or TextFormatFlags.Left)
                    End If
                End If
            End If
            If Not Collapsed Then
                If (State And StateButtonState.Pressed) <> 0 Then
                    renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Pressed)
     
                    ' If hot
                Else
                    If (State And StateButtonState.MouseHover) <> 0 Then
                        renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Hot)
     
                        ' If disabled
                    Else
                        If Not Enabled Then
                            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal)
     
                            ' If normal
                        Else
                            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal)
                        End If
                    End If
                End If
            Else
                ' If pressed
                If (State And StateButtonState.Pressed) <> 0 Then
                    renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Pressed)
     
                    ' If hot
                Else
                    If (State And StateButtonState.MouseHover) <> 0 Then
                        renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Hot)
     
                        ' If disabled
                    Else
                        If Not Enabled Then
                            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Normal)
     
                            ' If normal
                        Else
                            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Normal)
                        End If
                    End If
                End If
            End If
            renderer.DrawBackground(e.Graphics, New Rectangle(Me.Width - 22, 3, 20, 20))
            MyBase.OnPaint(e)
        End Sub
    End Class 
    'Le CUSTOM PANEL
     
    Imports System.Drawing.Drawing2D
    Imports System.Drawing.Design
    Imports System.ComponentModel
    Imports System.Windows.Forms.VisualStyles
     
     
    ' This disables the autodock smart tag
    '<Designer(GetType(CollapsiblePanelDesigner))> _
    <Docking(DockingBehavior.Never)> _
    Public Class CollapsiblePanel
        Inherits Panel
     
        ' Controls
        Private button As CollapseButton
        Private timer As Timer
     
        ' Fields
        Private collapsing As Boolean
        Private oldHeight As Integer
        Private accelerator As Integer
        Private _collapsed As Boolean
     
     
        Public Sub New()
            Me.SetStyle(ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor, True)
     
            Me.DoubleBuffered = True
     
            ' Setup button
            button = New CollapseButton()
            button.Size = New Size(Me.Width, 25)
            button.Location = New Point(0, 0)
            button.Font = New Font("Tahoma", 8.0F, FontStyle.Bold)
            button.Dock = DockStyle.Top
            AddHandler button.Click, AddressOf button_Click
            Me.Controls.Add(button)
     
            ' Set up timer
            timer = New Timer()
            timer.Interval = 25
            AddHandler timer.Tick, AddressOf timer_Tick
        End Sub 'New
     
        ' Properties
     
        Public Property Collapsed() As Boolean
            Get
                Return _collapsed
            End Get
            Set(ByVal value As Boolean)
                If Collapsed <> value Then
                    _collapsed = value
                    If _collapsed Then
                        PerformCollapse()
                    Else
                        PerformExpand()
                    End If
                End If
            End Set
        End Property
     
        <Browsable(True)> _
            Public Overrides Property [Text]() As String
            Get
                Return button.Text
            End Get
            Set(ByVal value As String)
                button.Text = value
            End Set
        End Property
     
     
        ' Methods
        Private Sub PerformCollapse()
            collapsing = True
            SuspendLayout()
            timer.Enabled = True
        End Sub
     
     
        Private Sub PerformExpand()
            collapsing = False
            SuspendLayout()
            timer.Enabled = True
        End Sub
     
     
        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            ' Paint parent background
            InvokePaintBackground(Me, New PaintEventArgs(e.Graphics, ClientRectangle))
     
            ' Fill the rest of the background
            Dim renderer As New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupBackground.Normal)
     
            'renderer.DrawBackground(e.Graphics, e.ClipRectangle);
            Dim paintRectangle As Rectangle = e.ClipRectangle
            paintRectangle.Inflate(1, 1)
            renderer.DrawBackground(e.Graphics, paintRectangle)
     
            If Not timer.Enabled Then
                MyBase.OnPaint(e)
            End If
        End Sub
     
     
        Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
            MyBase.SetBoundsCore(x, y, width, height, specified)
            ' My new code
            If Not timer.Enabled And Not Collapsed Then
                oldHeight = height
            End If
        End Sub 'SetBoundsCore
     
     
        Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
            If collapsing Then
                Me.Size = New Size(Me.Width, Me.Height - 2 - accelerator)
                If Me.Height <= 25 Then
                    Me.Size = New Size(Me.Width, 25)
                    timer.Enabled = False
                    button.Collapsed = True
                    accelerator = 0
                    ResumeLayout()
                End If
            Else
                Me.Size = New Size(Me.Width, Me.Height + 2 + accelerator)
                If Me.Height >= oldHeight Then
                    Me.Size = New Size(Me.Width, oldHeight)
                    timer.Enabled = False
                    button.Collapsed = False
                    accelerator = 0
                    ResumeLayout()
                End If
            End If
            accelerator += 1
        End Sub
     
     
        Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
            If Not collapsing Then
                Collapsed = True
            Else
                Collapsed = False
            End If
        End Sub
    End Class
    code du form pour l'utiliser :
    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
     
    Public Class CollabsibleLayout
        'un panel ordinaire pour aligner les panneaux extensibles
        Private simplePanel As Panel = New Panel
        'le panneau extensible ou collapse panel
        Private collapsePNL As CollapsiblePanel = New CollapsiblePanel
     
        Public Sub New()
     
            ' Cet appel est requis par le Concepteur Windows Form.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            'cree le simplePanel
            Me.simplePanel.AutoScroll = True
            Me.simplePanel.Dock = DockStyle.Fill
            Me.simplePanel.BorderStyle = BorderStyle.FixedSingle
            Me.simplePanel.BackColor = Color.BlanchedAlmond
     
     
            'ajouts de 5 panels expandables
     
            For i As Integer = 0 To 4
                collapsePNL = New CollapsiblePanel
                collapsePNL.Text = "Panel" & (i + 1).ToString
                collapsePNL.Dock = DockStyle.Top
                Me.simplePanel.Controls.Add(collapsePNL)
     
            Next
     
            Me.Controls.Add(Me.simplePanel)
            Me.BackColor = SystemColors.GradientActiveCaption
            Me.Name = "CollabsibleLayout"
            Me.Text = "CollabsibleLayout"
     
            'ajoute des   remplissages entre simplePanel
            'et le  form pour aerer
            Dim pd As Padding = New Padding
            pd.All = 10
            Me.Padding = pd
     
        End Sub
    End Class
    mettre le tout dans le meme projet winform.....

    ci-apres le 2eme code du CollapseButtonPerso avec indication de l'endroit ou le code est modifie pour inclure les 2 bitmaps que tu pourrais faire avec paint (moi j'utilise soit visio soit photoshop) et le meme CollapsePanel original qui fait reference cette fois au CollapseButtonPerso :
    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
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
     
    Le CUSTOM BUTTON PERSO
    Imports System.Drawing.Drawing2D
    Imports System.Drawing.Design
    Imports System.ComponentModel
    Imports System.Windows.Forms.VisualStyles
     
     
    Public Class CollapseButtonPerso
        Inherits StateButtonBase
     
        ' Property fields
        Private _collapsed As Boolean
     
     
        Public Sub New()
            Me.SetStyle(ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
            Me.DoubleBuffered = True
        End Sub
     
     
        Public Property Collapsed() As Boolean
            Get
                Return _collapsed
            End Get
            Set(ByVal value As Boolean)
                If value <> _collapsed Then
                    _collapsed = value
                    Invalidate()
                End If
            End Set
        End Property
     
        Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
            MyBase.OnTextChanged(e)
            Invalidate()
        End Sub
     
        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            Dim renderer As VisualStyleRenderer
     
            ' Paint parent background
            InvokePaintBackground(Me, New PaintEventArgs(e.Graphics, ClientRectangle))
     
            ' Paint background
            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupHead.Normal)
            'renderer.DrawBackground(e.Graphics, new Rectangle(0, 0, e.ClipRectangle.Width, 25));
            renderer.DrawBackground(e.Graphics, ClientRectangle)
     
            ' Draw Text
            'ligne originale du text du bouton
            'Dim fontRect As New Rectangle(17, 6, Me.Width - 17 - 24, Me.Height)
            'le texte est decale à gauche à 20 pour placer le rectangle avec signe+ ou -
            Dim fontRect As New Rectangle(20, 6, Me.Width - 17 - 24, Me.Height)
     
            If (State And StateButtonState.Pressed) <> 0 Then
                TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, fontRect, SystemColors.InactiveCaption, TextFormatFlags.Top Or TextFormatFlags.Left)
            Else
                If (State And StateButtonState.MouseHover) <> 0 Then
                    TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, fontRect, SystemColors.InactiveCaption, TextFormatFlags.Top Or TextFormatFlags.Left)
                Else
                    If Not Enabled Then
                        TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, fontRect, SystemColors.GrayText, TextFormatFlags.Top Or TextFormatFlags.Left)
                    Else
                        TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, fontRect, SystemColors.MenuHighlight, TextFormatFlags.Top Or TextFormatFlags.Left)
                    End If
                End If
            End If
            If Not Collapsed Then 'not collapsed
                If (State And StateButtonState.Pressed) <> 0 Then
                    renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Pressed)
     
                    ' If hot
                Else
                    If (State And StateButtonState.MouseHover) <> 0 Then
                        renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Hot)
     
                        ' If disabled
                    Else
                        If Not Enabled Then
                            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal)
     
                            ' If normal
                        Else
                            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal)
                        End If
                    End If
                End If
                'remplace la ligne double fleche avec celle-la qui dessine ExpandButtonlmg (dessin  avec rectangle signe +  )
                'dimension 3x3,position 20,20 voir ci-dessus
                Dim bmp As Bitmap = My.Resources.ExpandButtonlmg
                renderer.DrawImage(e.Graphics, New Rectangle(3, 3, 20, 20), bmp)
     
            Else ' collapsed
                ' If pressed
                If (State And StateButtonState.Pressed) <> 0 Then
                    renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Pressed)
     
                    ' If hot
                Else
                    If (State And StateButtonState.MouseHover) <> 0 Then
                        renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Hot)
     
                        ' If disabled
                    Else
                        If Not Enabled Then
                            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Normal)
     
                            ' If normal
                        Else
                            renderer = New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Normal)
                        End If
                    End If
                End If
                'remplace la ligne double fleche -par celle-la qui dessine un bitmap CollapseButtonImg(un rectangle  signe -)
                'dimension 3x3,position 20,20 voir ci-dessus
                Dim bmp As Bitmap = My.Resources.CollapseButtonImg
                renderer.DrawImage(e.Graphics, New Rectangle(3, 3, 20, 20), bmp)
            End If
            'commente cette ligne originale qui dessine double fleche
            'renderer.DrawBackground(e.Graphics, New Rectangle(Me.Width - 22, 3, 20, 20))
     
            MyBase.OnPaint(e)
        End Sub
    End Class
    Le CUSTOM PANEL
    Imports System.Drawing.Drawing2D
    Imports System.Drawing.Design
    Imports System.ComponentModel
    Imports System.Windows.Forms.VisualStyles
     
     
    ' This disables the autodock smart tag
    '<Designer(GetType(CollapsiblePanelDesigner))> _
    <Docking(DockingBehavior.Never)> _
    Public Class CollapsiblePanelPerso
        Inherits Panel
     
        ' Controls
        'commente cette ligne
        'Private button As CollapseButton
     
        'et referencer le CollapseButtonPerso=> unique modif
        Private button As CollapseButtonPerso
        Private timer As Timer
     
        ' Fields
        Private collapsing As Boolean
        Private oldHeight As Integer
        Private accelerator As Integer
        Private _collapsed As Boolean
     
     
        Public Sub New()
            Me.SetStyle(ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor, True)
     
            Me.DoubleBuffered = True
     
            ' Setup button
            button = New CollapseButtonPerso()
            button.Size = New Size(Me.Width, 25)
            button.Location = New Point(0, 0)
            button.Font = New Font("Tahoma", 8.0F, FontStyle.Bold)
            button.Dock = DockStyle.Top
            AddHandler button.Click, AddressOf button_Click
            Me.Controls.Add(button)
     
            ' Set up timer
            timer = New Timer()
            timer.Interval = 25
            AddHandler timer.Tick, AddressOf timer_Tick
        End Sub 'New
     
        ' Properties
     
        Public Property Collapsed() As Boolean
            Get
                Return _collapsed
            End Get
            Set(ByVal value As Boolean)
                If Collapsed <> value Then
                    _collapsed = value
                    If _collapsed Then
                        PerformCollapse()
                    Else
                        PerformExpand()
                    End If
                End If
            End Set
        End Property
     
        <Browsable(True)> _
            Public Overrides Property [Text]() As String
            Get
                Return button.Text
            End Get
            Set(ByVal value As String)
                button.Text = value
            End Set
        End Property
     
     
        ' Methods
        Private Sub PerformCollapse()
            collapsing = True
            SuspendLayout()
            timer.Enabled = True
        End Sub
     
     
        Private Sub PerformExpand()
            collapsing = False
            SuspendLayout()
            timer.Enabled = True
        End Sub
     
     
        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            ' Paint parent background
            InvokePaintBackground(Me, New PaintEventArgs(e.Graphics, ClientRectangle))
     
            ' Fill the rest of the background
            Dim renderer As New VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupBackground.Normal)
     
            'renderer.DrawBackground(e.Graphics, e.ClipRectangle);
            Dim paintRectangle As Rectangle = e.ClipRectangle
            paintRectangle.Inflate(1, 1)
            renderer.DrawBackground(e.Graphics, paintRectangle)
     
            If Not timer.Enabled Then
                MyBase.OnPaint(e)
            End If
        End Sub
     
     
        Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
            MyBase.SetBoundsCore(x, y, width, height, specified)
            ' My new code
            If Not timer.Enabled And Not Collapsed Then
                oldHeight = height
            End If
        End Sub 'SetBoundsCore
     
     
        Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
            If collapsing Then
                Me.Size = New Size(Me.Width, Me.Height - 2 - accelerator)
                If Me.Height <= 25 Then
                    Me.Size = New Size(Me.Width, 25)
                    timer.Enabled = False
                    button.Collapsed = True
                    accelerator = 0
                    ResumeLayout()
                End If
            Else
                Me.Size = New Size(Me.Width, Me.Height + 2 + accelerator)
                If Me.Height >= oldHeight Then
                    Me.Size = New Size(Me.Width, oldHeight)
                    timer.Enabled = False
                    button.Collapsed = False
                    accelerator = 0
                    ResumeLayout()
                End If
            End If
            accelerator += 1
        End Sub
     
     
        Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
            If Not collapsing Then
                Collapsed = True
            Else
                Collapsed = False
            End If
        End Sub
    End Class
    code du form pour l'utiliser :
    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
     
    Public Class CollabsibleLayoutPerso
        Private simplePanel As Panel = New Panel
        Private collapsePNL As CollapsiblePanelPerso = New CollapsiblePanelPerso
     
        Public Sub New()
     
            ' Cet appel est requis par le Concepteur Windows Form.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            'cree le simplePanel
            Me.simplePanel.AutoScroll = True
            Me.simplePanel.Dock = DockStyle.Fill
            Me.simplePanel.BorderStyle = BorderStyle.FixedSingle
            Me.simplePanel.BackColor = Color.BlanchedAlmond
     
     
            'ajouts de 5 panels expandables
     
            For i As Integer = 0 To 4
                collapsePNL = New CollapsiblePanelPerso
                collapsePNL.Text = "Panel" & (i + 1).ToString
                collapsePNL.Dock = DockStyle.Top
                collapsePNL.BackColor = Color.BlanchedAlmond
                Me.simplePanel.Controls.Add(collapsePNL)
     
            Next
     
            Me.Controls.Add(Me.simplePanel)
            Me.BackColor = SystemColors.GradientActiveCaption
            Me.Name = "CollabsibleLayoutPerso"
            Me.Text = "CollabsibleLayoutPerso"
            'ajoute des   remplissages entre simplePanel
            'et le  form pour aerer
            Dim pd As Padding = New Padding
            pd.All = 10
            Me.Padding = pd
     
        End Sub
    End Class
    Mettre le tout dans le meme projet winform.....

    Le plus interessant est de dropper autant de CollapsiblePanels que tu veux suivant la meme techique ci-dessus mais sur un user control .
    De plus sur un usercontrol tu peux rajouter un Toolstrip control docke en haut avec un label(le nom de ta boite à outils),un bouton avec le dessin d'une croix pour fermer le usercontrol etc.....j'arrete là .
    Tu remarquera egalement -un fait fort interessant -:tu peux mettre des controls sur chaque CollapsiblePanel et en quantite..................ce que ne permet pas un treeview.
    bon code................

  6. #6
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    335
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2011
    Messages : 335
    Points : 111
    Points
    111
    Par défaut
    Merci Mabrouki!

    Ta passion et ta générosité m’impressionneront toujours.

    Dans l'immédiat, j'ai trouvé une solution à mon problème mais je garde ta solution précieusement.

    Ce serait bien qu'un modo modifie mon titre de post pour mettre les mots clef

    Controle Panneau Extensible - Collapsible Panel - Custom Control Canel

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant] PB Boite à outils sur Visual Studio Ultimate 2010
    Par zezito dans le forum Visual Studio
    Réponses: 0
    Dernier message: 03/03/2013, 19h38
  2. Comment afficher la boite à outils dans d'editeur vba
    Par abj8077 dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 12/10/2010, 22h57
  3. Réponses: 0
    Dernier message: 07/10/2010, 09h54
  4. Boite à outils à la Visual studio
    Par Evildoer_62 dans le forum Windows Forms
    Réponses: 5
    Dernier message: 11/12/2008, 15h26
  5. Nom d'un control style boite à outils de visual studio
    Par Cedric33 dans le forum Windows Forms
    Réponses: 5
    Dernier message: 18/09/2008, 16h40

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