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

wxWidgets Discussion :

Getvalue, setvalue pour du texte


Sujet :

wxWidgets

  1. #1
    Membre à l'essai
    Inscrit en
    Octobre 2005
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 27
    Points : 12
    Points
    12
    Par défaut Getvalue, setvalue pour du texte
    Bonjour,

    Je suis entrain de construire une application wxwidgets.

    J'utilise les exemples présent dans la partie cour du site.

    J'aimerai creer une boite de dialogue personnaliser qui demande le nom de la prénom de la personne ainsi que deux boutons OK et Annuler.

    Voici l'exmple du site dans lequel j'aimerai enlever les Radiobouton pour les remplacer par deux wxTextCtrl qui me permettrai d'enregistrer le nom et le prénom de la personne dans deux variables.


    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
     
    #ifndef wxWinH
    #define wxWinH
     
    class Application : public wxApp
    {
    public:
        virtual bool OnInit();
    };
    //------------------------------------------------------------------------------
    class Frame : public wxFrame
    {
    public:
        Frame(const wxString& title, const wxPoint& pos, const wxSize& size,
                                                long style = wxDEFAULT_FRAME_STYLE);
    private:
        int Chiffre; //mémorise le chiffre sélectionné
        wxStaticText *Label;
        void OnQuit(wxCommandEvent& event);
        void OnDialog(wxCommandEvent& event);
    DECLARE_EVENT_TABLE()
    };
    //------------------------------------------------------------------------------
    class Dialog : public wxDialog
    {
    public:
        Dialog(wxWindow* parent, wxWindowID id, const wxString& title, int nb = 0);
        int GetValue();
        void SetValue(int);
    private:
        wxRadioButton *RadioBouton1;
        wxRadioButton *RadioBouton2;
        wxRadioButton *RadioBouton3;
    };
    //------------------------------------------------------------------------------
    enum
    {
        App_Quit = 1,
        Menu_dialog
    };
    
    #endif //wxWinH
    et

    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
     
    #include "wx/wxprec.h"
     
    #ifdef __BORLANDC__
        #pragma hdrstop
    #endif
     
    #ifndef WX_PRECOMP
        #include "wx/wx.h"
    #endif
    //------------------------------------------------------------------------------
    #include "wxWin.h"
     
    BEGIN_EVENT_TABLE(Frame, wxFrame)
        EVT_MENU(App_Quit,  Frame::OnQuit)
        EVT_MENU(Menu_dialog,  Frame::OnDialog)
    END_EVENT_TABLE()
     
    IMPLEMENT_APP(Application)
     
    bool Application::OnInit()
    {
        Frame *frame = new Frame("Frame", wxPoint(150, 150), wxSize(480, 220));
        frame->Show();
        return true;
    }
     
    //------------------------------------------------------------------------------
    //LA FENETRE PRINCIPALE
    //------------------------------------------------------------------------------
    Frame::Frame(const wxString& title, const wxPoint& pos, const wxSize& size,
                            long style) : wxFrame(NULL, -1, title, pos, size, style)
    {
        SetIcon(wxICON(monicone));
        SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
     
        wxMenu *menuFichier = new wxMenu;
        menuFichier->Append(Menu_dialog,"Dialogue");
        menuFichier->Append(App_Quit,"Quitter l'application");
        wxMenuBar *menuBarre = new wxMenuBar();
        menuBarre->Append(menuFichier,("&Fichier"));
        SetMenuBar(menuBarre);
     
        Label = new wxStaticText(this,-1,"N° Sélectionné : Aucun",wxDefaultPosition,
                               wxSize(-1, 60),wxALIGN_CENTRE | wxST_NO_AUTORESIZE );
        Label->SetFont(wxFont(12, wxSWISS , wxNORMAL, wxBOLD, false, "Arial"));
     
        wxBoxSizer *Psizer = new wxBoxSizer( wxVERTICAL );
        Psizer->Add(-1,60);
        Psizer->Add(Label,0, wxEXPAND );
        SetSizer(Psizer);
     
        Chiffre = 0;
    }
    //------------------------------------------------------------------------------
    void Frame::OnQuit(wxCommandEvent& WXUNUSED(event))
    {
         Close();
    }
    //------------------------------------------------------------------------------
    void Frame::OnDialog(wxCommandEvent& WXUNUSED(event))
    {
         Dialog dialog(NULL,-1,"Titre",Chiffre);
         if ( dialog.ShowModal() == wxID_OK )
             {
                wxString st = "Aucun";
                Chiffre = dialog.GetValue();
                  switch(Chiffre)
                   {
                     case 1 : st = "Un";
                              break;
                     case 2 : st = "Deux";
                              break;
                     case 3 : st = "Trois";
                              break;
                    }
                Label->SetLabel("N° Sélectionné : " + st);
             }
    }
     
    //------------------------------------------------------------------------------
    //LA BOITE DE DIALOGUE
    //------------------------------------------------------------------------------
    Dialog::Dialog(wxWindow* parent, wxWindowID id, const wxString& titre, int nb)
                      : wxDialog(parent,id,titre,wxDefaultPosition,wxSize(240, 200))
    {
          RadioBouton1 = new wxRadioButton(this,-1,"Un");
          RadioBouton2 = new wxRadioButton(this,-1,"Deux");
          RadioBouton3 = new wxRadioButton(this,-1,"Trois");
          wxButton *MonBouton1 = new wxButton(this,wxID_OK,"Ok");
          wxButton *MonBouton2 = new wxButton(this,wxID_CANCEL,"Annuler");
     
          wxBoxSizer *sizer1 = new wxBoxSizer( wxVERTICAL );
          sizer1->Add(-1,25);
          sizer1->Add(RadioBouton1,0,wxALL,5);
          sizer1->Add(RadioBouton2,0,wxALL,5);
          sizer1->Add(RadioBouton3,0,wxALL,5);
     
          wxBoxSizer *sizer2 = new wxBoxSizer( wxHORIZONTAL );
          sizer2->Add(MonBouton1,0,wxBOTTOM | wxLEFT | wxRIGHT ,5);
          sizer2->Add(MonBouton2,0,wxBOTTOM | wxLEFT | wxRIGHT ,5);
     
          wxBoxSizer *Psizer = new wxBoxSizer( wxVERTICAL );
          Psizer->Add(sizer1,3,wxALIGN_CENTER);
          Psizer->Add(sizer2,1,wxALIGN_CENTER);
          SetSizer(Psizer);
          SetValue(nb);
    }
    //------------------------------------------------------------------------------
    int Dialog::GetValue()
    {
          int x = 0;
          if( RadioBouton1->GetValue() ) x = 1;
          if( RadioBouton2->GetValue() ) x = 2;
          if( RadioBouton3->GetValue() ) x = 3;
          return x;
    }
    //------------------------------------------------------------------------------
    void Dialog::SetValue(int x)
    {
          switch(x)
           {
            case 1 : RadioBouton1->SetValue(true);
                     break;
            case 2 : RadioBouton2->SetValue(true);
                     break;
            case 3 : RadioBouton3->SetValue(true);
                     break;
            }
    }
    Je pense qu'il faut que j'utilise Getvalue et Setvalue mais dans cet exemple setValue renvoi un entier alors que je souhaite envoyer des caractères.

    Si vous avez des exemples qui ressemblent à ce que je souhaite réaliser.

    Merci

  2. #2
    Rédacteur

    Avatar de Matthieu Brucher
    Profil pro
    Développeur HPC
    Inscrit en
    Juillet 2005
    Messages
    9 810
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur HPC
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2005
    Messages : 9 810
    Points : 20 970
    Points
    20 970
    Par défaut
    Donc tu remplaces les wxRadioButton par des wxTextCtrl et tu rajoutes un argument à la fonction setValue qui prendra une chaîne de caractères en plus.

Discussions similaires

  1. [fonction] fonction pour formatage texte
    Par titiyo dans le forum Delphi
    Réponses: 5
    Dernier message: 29/06/2006, 12h16
  2. loadVars pour du texte
    Par CR_Gio dans le forum Dynamique
    Réponses: 1
    Dernier message: 05/05/2006, 20h07
  3. Composants pour afficher texte
    Par log2n dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 30/01/2006, 06h52
  4. Réponses: 1
    Dernier message: 15/07/2005, 00h09
  5. Des styles pour le texte et les liens dans la meme div?
    Par Donkey' Shot dans le forum Mise en page CSS
    Réponses: 4
    Dernier message: 26/01/2005, 20h03

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