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 :

Ces contrôles existent-ils ?


Sujet :

Windows Forms

  1. #1
    Rédacteur
    Avatar de Franck.H
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2004
    Messages
    6 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2004
    Messages : 6 951
    Points : 12 462
    Points
    12 462
    Par défaut Ces contrôles existent-ils ?


    J'aurais aimé savoir si de tels contrôles existent sur VB.Net



    Celui-ci (zone verte) permet, en cliquant sur la flèche, de dévoiler une nouvelle zone d'interface et ceux-là



    Le permier qui permet de choisir un dossier puis d'afficher son nom à côté et les quatre boutons qui sont dans la seconde zone de contrôles qui permettent d'ouvrir une fenêtre de choix de fichier et affiche son nom une fois sélectionné.

    Ceci est fait en C/GTK+ mais j'aurais aimé retranscrire tout ça en VB.Net


    Mon Site
    Ma bibliothèque de gestion des chaînes de caractères en C

    L'imagination est plus importante que le savoir. A. Einstein

    Je ne répond à aucune question technique par MP, merci d'avance !

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    436
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2006
    Messages : 436
    Points : 963
    Points
    963
    Par défaut
    VB.NET c'est vague

    Pour l'UI tu passes par quoi ? WPF ? Silverlight ? Winform ? ASP.NET ?

    La majorité de ces contrôles existes.

    Expender pour afficher / masquer une partie de l'interface avec effet slide in/out.

    OpenFileDialog pour ouvrir un popup de sélection de fichier.
    "S'adapter, c'est vaincre" - Cellendhyll de Cortavar

  3. #3
    Rédacteur
    Avatar de Franck.H
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2004
    Messages
    6 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2004
    Messages : 6 951
    Points : 12 462
    Points
    12 462
    Par défaut
    Pour l'UI tu passes par quoi ? WPF ? Silverlight ? Winform ? ASP.NET ?
    Je suis sur quel forum à ton avis ?!

    Expender pour afficher / masquer une partie de l'interface avec effet slide in/out
    Il me semble pas l'avoir vu dans la liste des contrôles.

    OpenFileDialog pour ouvrir un popup de sélection de fichier.
    Oui peut-être mais là je cherche un contrôle comme un bouton si tu veux, comme dans la capture d'écran
    Mon Site
    Ma bibliothèque de gestion des chaînes de caractères en C

    L'imagination est plus importante que le savoir. A. Einstein

    Je ne répond à aucune question technique par MP, merci d'avance !

  4. #4
    Modérateur
    Avatar de Sankasssss
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2006
    Messages
    1 842
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 842
    Points : 4 232
    Points
    4 232
    Par défaut
    Bonjour,

    Pour l'expander, il n'existe pas en windows form mais il est assez aisé de recréer un controle ayant son comportement,on en trouve d'ailleurs sur internet très facilement.

    Concernant le premier, il suffit de mettre un label et lier l’événement Click pour ouvrir une OpenFileDialog.

  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

    Pour l'expander voici un control panel "collapsible" accompage de son "collapsebutton" cliquable adhoc...


    Mettre les 3 fichiers de code vb qui suivent dans un meme projet library .vb :

    1/buttonbase.vb(class ancestor de collapsebutton)
    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
     
     
    Imports System.ComponentModel
     
    ' This class is the base for all button controls in this project.
    ' It contains fields so that inheriting buttons can track 
    ' button state (normal, hover, pressed, and disabled)
    Public MustInherit Class StateButtonBase
        Inherits Control
        Implements IButtonControl
     
        'ToDo: Add Implements Clauses for implementation methods of these interface(s)
        '
     
        Private _dialogResult As DialogResult = dialogResult.None
        Private _state As StateButtonState
     
        Public Sub New()
            SetStyle(ControlStyles.StandardClick Or ControlStyles.StandardDoubleClick, False)
        End Sub 'New
     
        Protected Overrides ReadOnly Property DefaultSize() As Size
            Get
                Return New Size(75, 23)
            End Get
        End Property
     
        <Category("Behavior"), DefaultValue(GetType(DialogResult), "DialogResult.None"), Description("Specifies the dialog result that this button will return when a form is closed by clicking it")> _
            Public Property DialogResult() As DialogResult Implements IButtonControl.DialogResult
            Get
                Return _dialogResult
            End Get
            Set(ByVal value As DialogResult)
                _dialogResult = value
            End Set
        End Property
     
        Protected ReadOnly Property State() As StateButtonState
            Get
                Return _state
            End Get
        End Property
     
        Private Sub SetState(ByVal setState As StateButtonState, ByVal [set] As Boolean)
            Dim newState As StateButtonState = Me.state
            If [set] Then
                newState = newState Or setState
            Else
                newState = newState And Not setState
            End If
     
            If Me.state <> newState Then
                _state = newState
                Invalidate()
            End If
        End Sub
     
        Public Sub NotifyDefault(ByVal isDefault As Boolean) Implements IButtonControl.NotifyDefault
            SetState(StateButtonState.Default, isDefault)
        End Sub
     
        Public Sub PerformClick() Implements IButtonControl.PerformClick
            OnClick(EventArgs.Empty)
        End Sub
     
        Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
            SetState(StateButtonState.Pressed, True)
            MyBase.OnMouseDown(e)
        End Sub
     
        Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
            Dim click As Boolean = False
            If (state And StateButtonState.Pressed) <> 0 Then
                click = True
            End If
            SetState(StateButtonState.Pressed, False)
            MyBase.OnMouseUp(e)
     
            If click Then
                Update()
                PerformClick()
            End If
        End Sub
     
        Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
            If Capture Then
                SetState(StateButtonState.Pressed, ClientRectangle.Contains(e.X, e.Y))
            End If
            MyBase.OnMouseMove(e)
        End Sub
     
        Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
            SetState(StateButtonState.MouseHover, True)
            MyBase.OnMouseEnter(e)
        End Sub
     
        Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
            SetState(StateButtonState.MouseHover, False)
            MyBase.OnMouseLeave(e)
        End Sub
     
    End Class
     
    <Flags()> _
    Public Enum StateButtonState
        None = &H0
        Pressed = &H1
        MouseHover = &H2
        [Default] = &H4
        Disabled = &H8
    End Enum
    2/CollapseButton.vb
    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
     
     
    '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))
     
            ' 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
    3/Collapsible Panel (il utilise collapsebutton)

    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
     
    '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
    <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
    Apres generation ,il faut le referencer le .dll dans le projet qui l'utilise ,le CollapsiblePanel apparait dans la boite à outils...
    il suffit de le dropper sur le form et rajouter les controls heberges (boutons radios,labels etc...)...

    NB:contenu de son design specifique il ne faut pas surtout pas le docker...car ca va à l'encontre de l'effet rechercher (extensibilite)...
    S'il est seul dans le form comme dans le screenshot,mettre la prop autosize du form à true...


    Le principe en est simple,un timer
    -(expand) incremente progressivement sa hauteur avec un max egal à height du boundscore qui est capture au demarrage...
    -(collapse) decremente progressivement sa hauteur avec un mini egal à height du collapse button embarque (25)...

    bon code...

Discussions similaires

  1. Réponses: 5
    Dernier message: 08/03/2012, 13h40
  2. Contrôle Existence d'un membre dans un PDS en JCL
    Par magfred03 dans le forum JCL - SORT
    Réponses: 4
    Dernier message: 27/10/2009, 12h39
  3. Nouveaux contrôles (existant comme activeX)
    Par statquant dans le forum Windows Forms
    Réponses: 8
    Dernier message: 15/06/2009, 21h45
  4. [C#] Savoir si un contrôle existe
    Par LE NEINDRE dans le forum Windows Forms
    Réponses: 3
    Dernier message: 27/06/2006, 08h50
  5. [Newbie] Ces livres sont-ils corrects ?
    Par Metzgermeister dans le forum C++
    Réponses: 7
    Dernier message: 04/12/2005, 15h10

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