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 :

La taille des composantes ne s'adaptent pas à un changement de taille


Sujet :

C++Builder

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné

    Profil pro
    Inscrit en
    Juin 2005
    Messages
    351
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juin 2005
    Messages : 351
    Par défaut La taille des composantes ne s'adaptent pas à un changement de taille
    Bonjour à tous,

    J'ai une frame qui contient des composantes graphiques alignées avec les ancres (akLeft, akTop et akRight) dans un formulaire.

    J'aligne ce formulaire à côté d'un autre avec la fonction ci-dessous, mais certaines composantes ne "suivent" pas le changement de taille est restent bloquées à leur taille d'avant le changement de dimension du formulaire. Ensuite, lorsque je bouge manuellement la taille du formulaire, elles s'adaptent mais en gardant la même marge à droite qui est fausse.

    Savez-vous comment RAD Studio (j'ai la version 2007) gère les Anchors et comment je pourrais le force à se mettre à jour?

    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
     
     
    //! Values for horizontal and vertical alignement of a form on another control
    typedef enum { afthLeft  =-1,
                   afthCenter= 0,
                   afthRight =+1,
                   afthIgnore=+2 } EHorizontalAlignFormTo;
    //! Values for vertical alignement of a form on another control
    typedef enum { aftvTop   =-1,
                   aftvMiddle= 0,
                   aftvBottom=+1,
                   aftvIgnore=+2 } EVerticalAlignFormTo;
     
    //---------------------------------------------------------------------------
    //! Align a form on a parent form
    /*! \param formToAlign is the form to change the position of
        \param modelControl is the master control to get the position as template for
                       alignement (if NULL, then use screen coordinated and center
                       the form in the screen with the required margin values)
        \param hPosition is the horizontal alignement position (-1 value to
                       align the form on the left, zero to center and +1
                       value to align right, other value=no alignement)
        \param vPosition is the same for vertical alignement (-1=top, 0=middel,
                       +1=bottom, other values=no alignement)
        \param leftMargin is the margin to let between the left border of the
                       form and the closest border of the master
        \param rightMargin is the margin to let between the right border of the
                      form and the closest border of the master
        \param topMargin is the margin to let between the top border of the form
                      and the closest border of the master
        \param bottomMargin is the margin to let between the bottom border of the
                     form and the closest border of the master
        \param minWidth is the minimum width of the form after alignement (ignored
                     if negative)
        \param minHeight is the minimum height of the form after alignement (ignored
                     if negative)
        \param maxWidth is the maximum width of the form after alignement (ignored
                     if negative)
        \param maxHeight is the maximum height of the form after alignement (ignored
                     if negative)
     */
    void PACKAGE AlignFormTo(TForm* formToAlign,const TControl* modelControl,
                             EHorizontalAlignFormTo hPosition,
                             EVerticalAlignFormTo vPosition,
                             int leftMargin,int rightMargin,
                             int topMargin,int bottomMargin,
                             int minWidth,int minHeight,
                             int maxWidth,int maxHeight) {
     
      // Check parameters
      if (formToAlign==NULL) return;
     
      // Get the dimensions of the master form (or screen)
      TRect master;
      if (modelControl) {
        master=const_cast<TControl*>(modelControl)->BoundsRect;
        if (modelControl->Parent) {
          TPoint topleft(master.left,master.top);
          topleft=const_cast<TWinControl*>(modelControl->Parent)->ClientToScreen(topleft);
          master.left=topleft.x;
          master.top =topleft.y;
        }
      } else {
        master=Screen->WorkAreaRect;
        hPosition=vPosition=0;
      }
     
      // Get the dimensions of the form to align
      TRect form=formToAlign->BoundsRect;
     
      // Horizontal alignement
           if (hPosition==-1) { int w=form.Width(); form.left=master.left-form.Width()-rightMargin; form.right=form.left+w; }
      else if (hPosition==+1) { int w=form.Width(); form.left=master.left+master.Width()+leftMargin;form.right=form.left+w; }
      else if (hPosition== 0) {
         form.left =master.left+leftMargin;
         form.right=master.left+master.Width()-rightMargin;
      }
     
      // Vertical alignement
           if (vPosition==-1) { int h=form.Height(); form.top=master.top-form.Height()-bottomMargin;form.bottom=form.top+h; }
      else if (vPosition==+1) { int h=form.Height(); form.top=master.top+master.Height()+topMargin; form.bottom=form.top+h; }
      else if (vPosition== 0) {
         form.top   =master.top+topMargin;
         form.bottom=master.top+master.Height()-bottomMargin;
      }
     
      // Bound form with screen
      TRect screen=Screen->WorkAreaRect;
      if (form.left>screen.Width())    { int w=form.Width(); form.left=screen.Width()-form.Width(); form.right=form.left+w; }
      if (form.left<0)                 { form.left=0; form.right=std::max((long)0,form.right); }
      if (maxWidth>=0)                 { form.right =form.left+std::min(form.Width(),maxWidth); }
      if (minWidth>=0)                 { form.right =form.left+std::max(form.Width(),minWidth); }
      if (form.right>screen.Width())   { int w=form.Width(); form.left=form.left-(form.right-screen.Width()); form.right=form.left+w; }
     
      if (form.top>screen.Height())    { int h=form.Height(); form.top=screen.Height()-form.Height(); form.bottom=form.top+h; }
      if (form.top<0)                  { form.top=0; form.bottom=std::max((long)0,form.bottom); }
      if (maxHeight>=0)                { form.bottom=form.top+std::min(form.Height(),maxHeight); }
      if (minHeight>=0)                { form.bottom=form.top+std::max(form.Height() ,minHeight); }
      if (form.bottom>screen.Height()) { int h=form.Height(); form.top=form.top-(form.bottom+screen.Height()); form.bottom=form.top+h; }
     
      // Assign new dimensions of the form
      formToAlign->Width =form.Width();     formToAlign->Left=form.left;
      formToAlign->Height=form.Height();    formToAlign->Top =form.top;
     
      // Call resize function
      if (formToAlign->OnResize) formToAlign->OnResize(NULL);
     
    }

  2. #2
    Expert confirmé

    Avatar de pottiez
    Homme Profil pro
    Développeur C++
    Inscrit en
    Novembre 2005
    Messages
    7 152
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur C++
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2005
    Messages : 7 152
    Par défaut
    Bonjour,
    il me semble, mais je ne suis pas sur de ce que j'avance, qu'il faut définir les ancre qu'une fois les positions et tailles du composant correctement définit, donc ne définir les ancre qu'au tout dernier moment.

  3. #3
    Membre chevronné

    Profil pro
    Inscrit en
    Juin 2005
    Messages
    351
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juin 2005
    Messages : 351
    Par défaut
    Bonjour,

    C'est bien ce que j'ai. En design-time, tout fonctionne correctement. C'est seulement en runtime que j'ai le problème...

    J'ai fait quelques essais et mon problème semblaient venir d'ailleurs: en enlevant ma fonction d'alignement les composantes s'affichaient aussi avec une fausse taille.

    J'ai modifié la taille de la fiche avec la souris, j'ai aussi modifié la taille dans la liste des propriétés ainsi que les contraintes et la position par défaut (sur poMainFormCenter) et maintenant tout fonctionne correctement :-)

    Je pense que c'était le .dfm qui n'était pas à jour.

    @pottiez: Merci pour ton aide :-)

  4. #4
    Expert confirmé

    Avatar de pottiez
    Homme Profil pro
    Développeur C++
    Inscrit en
    Novembre 2005
    Messages
    7 152
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur C++
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2005
    Messages : 7 152
    Par défaut
    Tant mieux

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

Discussions similaires

  1. Réponses: 3
    Dernier message: 28/07/2014, 21h50
  2. Réponses: 5
    Dernier message: 18/12/2010, 20h14
  3. Réponses: 6
    Dernier message: 24/06/2008, 10h24
  4. Réponses: 2
    Dernier message: 22/02/2008, 22h22
  5. Hauteur adapté à l'ensemble des champs d'une ligne: Pas de réponses?!
    Par mikebo74 dans le forum SAP Crystal Reports
    Réponses: 0
    Dernier message: 05/12/2007, 15h22

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