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

VB.NET Discussion :

combobox - image


Sujet :

VB.NET

Vue hybride

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

    Informations forums :
    Inscription : Janvier 2005
    Messages : 145
    Par défaut combobox - image
    Bonjour à tous! Voici mon code , mais j'ai une erreur qui est
    Une valeur de type 'ComboIcone' ne peut pas être convertie en 'System.Web.UI.Control'.
    Voici la classe:
    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
    Imports Microsoft.VisualBasic
    Public Class ComboIcone
        Inherits System.Windows.Forms.ComboBox
        Public ListaImg1 As New Windows.Forms.ImageList
        'It is the ImageList associated to the Combo
     
        Public Sub New()
            DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
            'Set the DrawMode to OwnerDraw
        End Sub
     
        Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
            e.DrawBackground()
            e.DrawFocusRectangle()
            Dim item As New ComboBoxIconItem
            Dim imageSize As New Drawing.Size
            imageSize = ListaImg1.ImageSize
            Dim bounds As New Drawing.Rectangle
            bounds = e.Bounds
            Try
                item = Me.Items(e.Index)
                If (item.ImageIndex <> -1) Then
                    Me.ListaImg1.Draw(e.Graphics, bounds.Left, _
                        bounds.Top, item.ImageIndex)
                    e.Graphics.DrawString(item.Text, e.Font, _
                        New Drawing.SolidBrush(e.ForeColor), bounds.Left + _
                        imageSize.Width, bounds.Top)
                Else
                    e.Graphics.DrawString(item.Text, e.Font, _
                        New Drawing.SolidBrush(e.ForeColor), bounds.Left, _
                        bounds.Top)
                End If
            Catch ex As Exception
                If (e.Index <> -1) Then
                    e.Graphics.DrawString(Items(e.Index).ToString(), e.Font, _
                        New Drawing.SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
                Else
                    e.Graphics.DrawString(Text, e.Font, _
                        New Drawing.SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
                End If
            End Try
            MyBase.OnDrawItem(e)
        End Sub
     
    End Class
    Public Class ComboBoxIconItem
        Private _text As String
     
        Property Text() As String
            Get
                Return _text
            End Get
            Set(ByVal Value As String)
                _text = Value
            End Set
        End Property
     
        Private _imageIndex As Integer
     
        Property ImageIndex() As Integer
            Get
                Return _imageIndex
            End Get
     
            Set(ByVal Value As Integer)
                _imageIndex = Value
            End Set
        End Property
     
        Public Sub New()
            _text = ""
        End Sub
     
        Public Sub New(ByVal text As String)
            _text = text
        End Sub
     
        Public Sub New(ByVal text As String, ByVal imageIndex As Integer)
            _text = text
            _imageIndex = imageIndex
        End Sub
     
     
        Public Overrides Function ToString() As String
            Return _text
        End Function
    End Class
    Et voici le code de la page:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Dim MyCombo As New ComboIcone 'Create the Combo
            Dim ImageList1 As Windows.Forms.ImageList
            Dim image1 As Drawing.Bitmap
            image1 = New Drawing.Bitmap("~\Images\1.bmp", True)
            ImageList1.Images.Add(image1)
            MyCombo.ListaImg1 = ImageList1
            'Associates the Combo to an ImageList
            MyCombo.Items.Add(New ComboBoxIconItem("", 0))
            'Add new Item text=Bart image=0 
            Me.Controls.Add(MyCombo) 'add the combobox to the form
            'Place the combobox in a nice place
            MyCombo.Top = 30
            MyCombo.Left = 50
    L'erreur se situe au niveau de cette ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
            Me.Controls.Add(MyCombo) 'add the combobox to the form
    Comment faire ? Merci à tous!

  2. #2
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Par défaut
    Ben c'est normal, tu hérites de System.Windows.Forms.ComboBox...
    Besoin d'un MessageBox amélioré ? InformationBox pour .NET 1.1, 2.0, 3.0, 3.5, 4.0 sous license Apache 2.0.

    Bonnes pratiques pour les accès aux données
    Débogage efficace en .NET
    LINQ to Objects : l'envers du décor

    Mon profil LinkedIn - MCT - MCPD WinForms - MCTS Applications Distribuées - MCTS WCF - MCTS WCF 4.0 - MCTS SQL Server 2008, Database Development - Mon blog - Twitter

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 145
    Par défaut
    Ah ouai j'avais pas fait gaffe! Comment je peux faire alors?

  4. #4
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Par défaut
    Tu hérites de System.Web.UI.ComboBox à la place.
    Besoin d'un MessageBox amélioré ? InformationBox pour .NET 1.1, 2.0, 3.0, 3.5, 4.0 sous license Apache 2.0.

    Bonnes pratiques pour les accès aux données
    Débogage efficace en .NET
    LINQ to Objects : l'envers du décor

    Mon profil LinkedIn - MCT - MCPD WinForms - MCTS Applications Distribuées - MCTS WCF - MCTS WCF 4.0 - MCTS SQL Server 2008, Database Development - Mon blog - Twitter

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 145
    Par défaut
    Ca n'existe pas...

  6. #6
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Par défaut
    Rho tu n'es pas dispensé de chercher non plus , il s'agit de DropDownList...
    Besoin d'un MessageBox amélioré ? InformationBox pour .NET 1.1, 2.0, 3.0, 3.5, 4.0 sous license Apache 2.0.

    Bonnes pratiques pour les accès aux données
    Débogage efficace en .NET
    LINQ to Objects : l'envers du décor

    Mon profil LinkedIn - MCT - MCPD WinForms - MCTS Applications Distribuées - MCTS WCF - MCTS WCF 4.0 - MCTS SQL Server 2008, Database Development - Mon blog - Twitter

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

Discussions similaires

  1. Combobox -- image excel
    Par Phryxus dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 23/02/2015, 15h07
  2. [AC-2010] Combobox + images
    Par jacquesprogram dans le forum IHM
    Réponses: 2
    Dernier message: 13/07/2011, 22h47
  3. combobox image swt
    Par dally_01 dans le forum SWT/JFace
    Réponses: 1
    Dernier message: 10/12/2008, 14h55
  4. Probleme image dans combobox.
    Par devoluti0n dans le forum Delphi
    Réponses: 11
    Dernier message: 10/07/2007, 09h53
  5. afficher une image depuis un combobox
    Par ghosthacker dans le forum MFC
    Réponses: 5
    Dernier message: 11/06/2007, 10h35

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