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

C++Builder Discussion :

Transformer un Enter en tabulation


Sujet :

C++Builder

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Août 2002
    Messages
    481
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2002
    Messages : 481
    Par défaut Transformer un Enter en tabulation
    Bonjour à tous,
    Je travaille avec C++ Builder XE6.
    j'ai un problème dont je ne comprends pas l'origine.
    Dans un KeyPress je veux transformer un Enter ('r' ou VK_RETURN) en tabulation.
    J'utilisais sans problème :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    	if(Key =='r')
    	{
    		Key=0; // pour éviter le beep
    		//ShowMessage("Vers NextControl");
    		FindNextControl(dynamic_cast<TWinControl*>(Sender),true,true,false)->SetFocus();
    	}
    Actuellement avec le code suivant :
    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
    	void __fastcall TfNouveau::eSystoleKeyPress(TObject *Sender, System::WideChar &Key)
    {
    	ShowMessage("Entrée dans eSystoleKeyPress");
    	if(Key == VK_RETURN)  // ou if(Key == 'r')
    	{
    		Key=0; // pour éviter le beep
    		ShowMessage("Vers NextControl");
    		FindNextControl(dynamic_cast<TWinControl*>(Sender),true,true,false)->SetFocus();
    	}
    	else
    	{
    	 char DecimalSeparator = '.';
    	 if ((Key < '0' || Key >'9') && Key != 8 && (Key != DecimalSeparator ||
    												((TEdit *)Sender)->Text.Pos(DecimalSeparator)!=0))
    																														Key = NULL;
    	}
    }
    //-----------------
    Non seulement il n'y a pas la transformation du Retour chariot en tabulation, mais il n'y a pas le message "Entrée dans eSystoleKeyPress".
    Quelle peut être la cause de ce comportement ?
    Merci de votre aide.

  2. #2
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par défaut
    Salut
    il me semble qu'il y aie une certaine confusion
    en effet 'r' n'est pas égal à VK_RETURN mais à 0x0D

    ton code n'est il pas tiré de http://http://swag.outpostbbs.net/DELPHI/0079.PAS.html

    Dans ce cas ta traduction est incorrecte
    je verrais plutôt ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     
    void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
    {
    	 if ((Key ==0x0d)
                SelectNext(dynamic_cast<TWinControl*>(Sender),true,true);
             Key=0;								
    	}
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Août 2002
    Messages
    481
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2002
    Messages : 481
    Par défaut
    Merci.
    Dans mon exemple la fonction est :
    void __fastcall TfNouveau::eSystoleKeyPress(TObject *Sender, System::WideChar &Key)
    Puis je changer le en ?

  4. #4
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par défaut
    bonjour
    cela dépend de la manière d'on ce code est appelé

    comment est déclaré dans ton code TfNouveau::eSystoleKeyPress
    TfNouveau est il un descendant de Tform?
    eSystoleKeyPress est il une surcharge de FormKeyPress?
    dans le cas contraire pourquoi n''utilise tu pas la méthode FormKeyPress de Tform avec l'implémentation que je t'ai fournie


    le code de ta classe TfNouveau est nécessaire pour apporter une aide efficace

    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Août 2002
    Messages
    481
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2002
    Messages : 481
    Par défaut
    Merci, j'ai appliqué votre proposition.
    J'ai une réponse du compiler que je ne comprends pas.
    Je l'ai appliquée dans deux KeyPress.
    J'obtiens une seule erreur disant que je fais appel à une fonction inexistante.
    Elle ne concerne que l'un des 2 KeyPress
    Il s'agit de FindNext'….

  6. #6
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par défaut
    Salut
    voici un petit exemple avec 8 EditBox sur 1 fiche, ayant comme capacité d'être sélectionnable soit par la touche Tab ou la touche Enter(Return)
    a chaque fois qu'une EditBox est sélectionnée sa couleur change, lors de la désélection sa couleur revient celle par défaut.
    pour ce faire l'event OnKeyPress de chaque EditBox est renseigné par une méthode commune LabelKeyPress

    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
     
     
    // la form en format Texte
    object Form117: TForm117
      Left = 0
      Top = 0
      Caption = 'Form117'
      ClientHeight = 261
      ClientWidth = 185
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object Edit1: TEdit
        Left = 35
        Top = 25
        Width = 121
        Height = 21
        TabOrder = 0
        OnEnter = EditEnter
        OnExit = EditExit
        OnKeyPress = LabelKeyPress
      end
      object Edit2: TEdit
        Left = 35
        Top = 52
        Width = 121
        Height = 21
        TabOrder = 1
        OnEnter = EditEnter
        OnExit = EditExit
        OnKeyPress = LabelKeyPress
      end
      object Edit3: TEdit
        Left = 35
        Top = 81
        Width = 121
        Height = 21
        TabOrder = 2
        OnEnter = EditEnter
        OnExit = EditExit
        OnKeyPress = LabelKeyPress
      end
      object Edit4: TEdit
        Left = 35
        Top = 109
        Width = 121
        Height = 21
        TabOrder = 3
        OnEnter = EditEnter
        OnExit = EditExit
        OnKeyPress = LabelKeyPress
      end
      object Edit5: TEdit
        Left = 35
        Top = 138
        Width = 121
        Height = 21
        TabOrder = 4
        OnEnter = EditEnter
        OnExit = EditExit
        OnKeyPress = LabelKeyPress
      end
      object Edit6: TEdit
        Left = 35
        Top = 166
        Width = 121
        Height = 21
        TabOrder = 5
        OnEnter = EditEnter
        OnExit = EditExit
        OnKeyPress = LabelKeyPress
      end
      object Edit7: TEdit
        Left = 35
        Top = 195
        Width = 121
        Height = 21
        TabOrder = 6
        OnEnter = EditEnter
        OnExit = EditExit
        OnKeyPress = LabelKeyPress
      end
      object Edit8: TEdit
        Left = 35
        Top = 222
        Width = 121
        Height = 21
        TabOrder = 7
        OnEnter = EditEnter
        OnExit = EditExit
        OnKeyPress = LabelKeyPress
      end
    end
     
    // le hpp
    //---------------------------------------------------------------------------
     
    #ifndef Unit117H
    #define Unit117H
    //---------------------------------------------------------------------------
    #include <System.Classes.hpp>
    #include <Vcl.Controls.hpp>
    #include <Vcl.StdCtrls.hpp>
    #include <Vcl.Forms.hpp>
    //---------------------------------------------------------------------------
    class TForm117 : public TForm
    {
    __published:	// Composants gérés par l'EDI
    	TEdit *Edit1;
    	TEdit *Edit2;
    	TEdit *Edit3;
    	TEdit *Edit4;
    	TEdit *Edit5;
    	TEdit *Edit6;
    	TEdit *Edit7;
    	TEdit *Edit8;
        void __fastcall LabelKeyPress(TObject *Sender, System::WideChar &Key);
    	void __fastcall EditEnter(TObject *Sender);
    	void __fastcall EditExit(TObject *Sender);
     
    private:	// Déclarations utilisateur
    public:		// Déclarations utilisateur
    	__fastcall TForm117(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm117 *Form117;
    //---------------------------------------------------------------------------
    #endif
     
     
    // le cpp
    // ---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit117.h"
    // ---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm117 *Form117;
     
    // ---------------------------------------------------------------------------
    __fastcall TForm117::TForm117(TComponent* Owner)
    	: TForm(Owner)
    {
     
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TForm117::LabelKeyPress(TObject *Sender, System::WideChar &Key)
    {
    	if (Key == 0x0D)
    	{
    		SelectNext(dynamic_cast<TWinControl*>(Sender), true, true);
    		Key = 0;
    	}
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TForm117::EditEnter(TObject *Sender)
    {
    	dynamic_cast<TEdit*>(Sender)->Color = (TColor)10483700;
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TForm117::EditExit(TObject *Sender)
    {
    	dynamic_cast<TEdit*>(Sender)->Color = clWindow;
    }
    // ---------------------------------------------------------------------------
    important
    l'évenement OnKeyPress de TForm est déclenché uniquement si la propriété KeyPreview est égal à true
    voir :http://docs.embarcadero.com/products...eyPreview.html


    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  7. #7
    Membre éclairé
    Profil pro
    Inscrit en
    Août 2002
    Messages
    481
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2002
    Messages : 481
    Par défaut
    Merci, j'essaie de me débrouiller avec le fichier que vous m'avez transmis.
    Je vous tiendrai au courant.

Discussions similaires

  1. Datagridview, enter et tabulation
    Par kolosawoi dans le forum Windows Forms
    Réponses: 1
    Dernier message: 18/03/2007, 10h37
  2. [HTML][formulaire] remplacer "Enter" par "tabulation"
    Par anti-conformiste dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 05/11/2006, 21h29
  3. comment je peux faire une tabulation avec Enter
    Par iam dans le forum Bases de données
    Réponses: 3
    Dernier message: 26/04/2006, 20h41
  4. [LG] Transformer une tabulation par un espace
    Par JoseF dans le forum Langage
    Réponses: 2
    Dernier message: 28/12/2005, 22h24
  5. [Editeur] Transformer tabulation en espace
    Par Oliveuh dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 07/11/2005, 15h29

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