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 Mobile .NET Discussion :

Mettre une image sur un bouton (application pour Windows Mobile 5.0 Pocket PC)


Sujet :

Windows Mobile .NET

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 64
    Points : 31
    Points
    31
    Par défaut Mettre une image sur un bouton (application pour Windows Mobile 5.0 Pocket PC)
    Bonjour, voilà je début tous juste en programmation VB, et j'ai déjà des problèmes

    je souhaite réaliser un programme simple, une fenêtre de 2 boutons,
    avec une image par bouton

    lorsque je clique sur un des boutons, une autre image se charge sur l'autre.

    Si vous pouvez au moin m'expliquer comment mettre une image sur un bouton sa sera déjà énorme

    Merci

    (version utilisé la librairie Windows Mobile 5.0 Pocket PC SDK
    Projet de création d'une application de formulaires .NET Compact Framework 2.0 pour Windows Mobile 5.0 Pocket PC et version ultérieure)

  2. #2
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    je n'ai jamais utilisé le framework compact
    mais si button.image n'existe pas, alors essaye button.CreateGraphics.DrawImage (inconvénient de cette méthode, elle doit etre rappelé sur l'évènement paint de ton control)
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 64
    Points : 31
    Points
    31
    Par défaut
    Merci pour ta réponse, malheureusement, je n'ai pas cette option,
    je pense que les fonctions pour ce type d'application est plus limité
    que pour les applications windows

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 64
    Points : 31
    Points
    31
    Par défaut
    bon j'ai décidé de changer de méthode, si vous pouvez juste me dire
    comment on charge une nouvelle image a partir d'un fichier image
    (de quel format doit etre le fichier est-ce que le png sa pass??)

  5. #5
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    sur le framework normal, quasi tout passe (meme png gif etc...)

    new image.fromfile
    ou new bitmap.fromfile (bitmap ne veut pas dire bmp)
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  6. #6
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 64
    Points : 31
    Points
    31
    Par défaut
    Erreur 1 Type 'Image.fromfile' non défini. C:\Documents and Settings\diophantes\Bureau\DeviceApplication\DeviceApplication\Form1.vb 12 33 DeviceApplication


    voila l'erreur qu'il me met la syntaxe que j'ai est la suivante

    PictureBox1.Image = New Image.fromfile("Image.png")

  7. #7
    Membre actif Avatar de neuropathie
    Inscrit en
    Janvier 2005
    Messages
    223
    Détails du profil
    Informations forums :
    Inscription : Janvier 2005
    Messages : 223
    Points : 201
    Points
    201
    Par défaut
    Tout à fait vrai, la propriété Button.Image n'existe pas.
    Par contre il y a la classe Picture button qui contient deux propriétés:
    -BackgroundImage: pour l'image d'arrière plan sur le bouton.
    -PressedImage: l'image qui apparait au clic du bouton.

    Voici un bout de code explicatif :

    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
     
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
     
     
    Public Class PictureButtonDemo
       Inherits System.Windows.Forms.Form
       Private mainMenu1 As System.Windows.Forms.MainMenu
       Private clickCount As Integer = 0
     
     
        ' Create a bitmap object, fill it with the specified color.   
        ' To make it look like a custom image, draw an ellipse in it.
        Function MakeBitmap(ByVal color As Color, ByVal width As Integer, ByVal height As Integer) As Bitmap
            Dim bmp As New Bitmap(width, height)
            Dim g As Graphics = Graphics.FromImage(bmp)
            g.FillRectangle(New SolidBrush(color), 0, 0, bmp.Width, bmp.Height)
            g.DrawEllipse(New Pen(color.DarkGray), 3, 3, width - 6, height - 6)
            g.Dispose()
     
            Return bmp
        End Function
     
     
        ' Create a new PictureButton control and hook up it's properties.
        Public Sub New()
            '
            ' Required for Windows Form Designer support
            '
            InitializeComponent()
     
            Dim button As New PictureButton
            button.Parent = Me
            button.Bounds = New Rectangle(10, 30, 150, 30)
            button.ForeColor = Color.White
            button.BackgroundImage = MakeBitmap(Color.Blue, button.Width, button.Height)
            button.PressedImage = MakeBitmap(Color.LightBlue, button.Width, button.Height)
            button.Text = "click me"
            AddHandler button.Click, AddressOf button_Click
        End Sub
     
     
        ' Clean up any resources being used.
        '
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            MyBase.Dispose(disposing)
        End Sub
    #Region "Windows Form Designer generated code"
     
        Private Sub InitializeComponent()
            Me.mainMenu1 = New System.Windows.Forms.MainMenu
            ' 
            ' PictureButtonDemo
            ' 
            Me.Menu = Me.mainMenu1
            Me.Text = "Picture Button Demo"
        End Sub 'InitializeComponent 
    #End Region
     
     
        '
        ' The main entry point for the application.
        '
        Shared Sub Main()
            Application.Run(New PictureButtonDemo)
        End Sub
     
     
        ' Because PictureButton inherits from Control, 
        ' you can use the default Click event.
        Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
            Me.clickCount = Me.clickCount + 1
            Me.Text = "Click Count = " & Me.clickCount
        End Sub
    End Class
     
     
    ' This code shows a simle way to have a button-like control 
    ' that has a background image.
     
    Public Class PictureButton
        Inherits Control
        Private backgroundImg, pressedImg As Image
        Private pressed As Boolean = False
     
        ' Property for the background image to be drawn behind the button text.
        Public Property BackgroundImage() As Image
            Get
                Return Me.backgroundImg
            End Get
            Set(ByVal Value As Image)
                Me.backgroundImg = Value
            End Set
        End Property
     
     
        ' Property for the background image to be drawn behind the button text when
        ' the button is pressed.
        Public Property PressedImage() As Image
            Get
                Return Me.pressedImg
            End Get
            Set(ByVal Value As Image)
                Me.pressedImg = Value
            End Set
        End Property
     
     
        '
        ' When the mouse is pressed, set the "pressed" flag = true and invalidate
        ' to cause a repaint.  The .NET Compact Framework sets the mouse capture automatically.
        Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
            Me.pressed = True
            Me.Invalidate()
            MyBase.OnMouseDown(e)
        End Sub
     
     
        ' When the mouse is released, reset the "pressed" flag and invalidate to redraw the 
        ' button in the un-pressed state.
        Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
            Me.pressed = False
            Me.Invalidate()
            MyBase.OnMouseUp(e)
        End Sub 'OnMouseUp
     
     
        ' Override the OnPaint method so we can draw the background image and the text.
        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            If Me.pressed AndAlso Not (Me.pressedImg Is Nothing) Then
                e.Graphics.DrawImage(Me.pressedImg, 0, 0)
            Else
                e.Graphics.DrawImage(Me.backgroundImg, 0, 0)
            End If
            ' Draw the text if there is any.
            If Me.Text.Length > 0 Then
                Dim size As SizeF = e.Graphics.MeasureString(Me.Text, Me.Font)
     
                ' Center the text inside the client area of the PictureButton.
                e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), (Me.ClientSize.Width - size.Width) / 2, (Me.ClientSize.Height - size.Height) / 2)
            End If
     
            ' Draw a border around the outside of the control to   
            ' look like Pocket PC buttons.
            e.Graphics.DrawRectangle(New Pen(Color.Black), 0, 0, Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
     
            MyBase.OnPaint(e)
        End Sub
    End Class

  8. #8
    Expert confirmé
    Avatar de Aspic
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    3 905
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2005
    Messages : 3 905
    Points : 4 388
    Points
    4 388
    Par défaut
    Essaye ca :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    PictureBox1.Image = Image.FromFile("C:\Documents and Settings\Fdiedler\Bureau\exu1.jpg")
    Qui ne tente rien n'a rien !
    Ce qui ne nous tue pas nous rends plus fort !!
    Mon projet ZELDA en C++/Allegro
    http://www.tutoworld.com - Le Forum -
    Mes ressources Dotnet (cours, sources, tutos)
    --------------------------------------------
    + + =

    Ne pas oublier le Tag !

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 64
    Points : 31
    Points
    31
    Par défaut
    je crois que je n'est pas de picture button, cela provient t'il de ma version?
    doit - je télécharger une bibliothèque supplémentaire?

  10. #10
    Membre actif Avatar de neuropathie
    Inscrit en
    Janvier 2005
    Messages
    223
    Détails du profil
    Informations forums :
    Inscription : Janvier 2005
    Messages : 223
    Points : 201
    Points
    201
    Par défaut
    Pas du tout, la classe PictureButton n'est pas livrée en standars ni dans la boite à outils, donc c'est une classe que tu créeras depuis le début comme démontré dans l'exemple de code que j'ai posté

  11. #11
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 64
    Points : 31
    Points
    31
    Par défaut
    J'ai meme pas le choix du fromfile, lorsque je met mon image.
    tout ce que j'ai en choix c'est :

    equals
    FromHbitmap
    ReferenceEquals

  12. #12
    Membre actif Avatar de neuropathie
    Inscrit en
    Janvier 2005
    Messages
    223
    Détails du profil
    Informations forums :
    Inscription : Janvier 2005
    Messages : 223
    Points : 201
    Points
    201
    Par défaut
    pour te simplifier la vie, jettes un cooup d'oeil sur cet article:

    http://www.codeppc.com/dotnet/create...atecontrol.htm

  13. #13
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 64
    Points : 31
    Points
    31
    Par défaut
    bon j'ai trouver une carotte pour faire ce que je voulais

    PictureBox1.Image = ImageList1.Images.Item(integer)
    sa marche, en définissant au préalable une imagelist avec une collection d'image
    seul problème la conversion les met en bitmap et du cou c'est moche

  14. #14
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    pour image.fromfile, il faut référencer system.Drawing et l'importer aussi ...
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  15. #15
    Expert confirmé
    Avatar de Aspic
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    3 905
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2005
    Messages : 3 905
    Points : 4 388
    Points
    4 388
    Par défaut
    Citation Envoyé par sperot51
    pour image.fromfile, il faut référencer system.Drawing et l'importer aussi ...
    Pas besoin c'est deja fait par défaut dans un projet WinForm
    Qui ne tente rien n'a rien !
    Ce qui ne nous tue pas nous rends plus fort !!
    Mon projet ZELDA en C++/Allegro
    http://www.tutoworld.com - Le Forum -
    Mes ressources Dotnet (cours, sources, tutos)
    --------------------------------------------
    + + =

    Ne pas oublier le Tag !

  16. #16
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    Citation Envoyé par Aspic
    Pas besoin c'est deja fait par défaut dans un projet WinForm
    pas l'import je pense ... (imports)
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  17. #17
    Expert confirmé
    Avatar de Aspic
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    3 905
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2005
    Messages : 3 905
    Points : 4 388
    Points
    4 388
    Par défaut
    Chez moi pas besoin d'import ^^
    Qui ne tente rien n'a rien !
    Ce qui ne nous tue pas nous rends plus fort !!
    Mon projet ZELDA en C++/Allegro
    http://www.tutoworld.com - Le Forum -
    Mes ressources Dotnet (cours, sources, tutos)
    --------------------------------------------
    + + =

    Ne pas oublier le Tag !

Discussions similaires

  1. Est-il possible de mettre une image sur le bouton d'un formulaire
    Par Yagami_Raito dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 31/05/2007, 13h06
  2. [deb] mettre une image sur un bouton
    Par phestaca dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 25/03/2006, 23h45
  3. mettre une image sur un bouton de commande
    Par delamarque dans le forum VB 6 et antérieur
    Réponses: 9
    Dernier message: 05/01/2006, 20h18
  4. [wxpython][wx.frame] mettre une image sur un bouton
    Par Kyti dans le forum wxPython
    Réponses: 7
    Dernier message: 02/05/2005, 12h13
  5. [JBouton] Comment mettre une image sur un bouton ?
    Par Kyti dans le forum Composants
    Réponses: 6
    Dernier message: 11/03/2005, 16h08

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