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

 Delphi Discussion :

Texte dédoublé dans Stringgrid


Sujet :

Delphi

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    356
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2003
    Messages : 356
    Points : 133
    Points
    133
    Par défaut Texte dédoublé dans Stringgrid
    bonjour

    je suis sous delphi xe berlin,

    j'ai mis un stringgrid avec des données dedans, le problème c'est que dès que je veux colorier une ligne sur 2
    d'une couleur différente en mettant dans le ondrawcell:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
    begin
      if(Sender = nil) then exit;
      With Sender As TStringGrid Do With Canvas Do
      Begin
        If Odd(ARow) then
          Font.Color:=clred
        else
          Font.Color:=clBlue;
        TextOut(Rect.Left,Rect.Top,Cells[ACol,ARow]);
      End;  
    end;
    mais en faisant ça j'ai mon texte bleu ou rouge mais je vois l'original en noir mais décalé.

    Nom : Capture.JPG
Affichages : 761
Taille : 27,5 Ko

    j'ai enlevé les thèmes, pareil...
    je crois que j'ai déjà eu ça avec un listview et c’était une option a la con, je sais plus..
    la j'ai un peu tout coché/décoché, ça change rien, quelqu'un aurait une idée ?


    merci

    exyacc

  2. #2
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 693
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 693
    Points : 13 126
    Points
    13 126
    Par défaut
    Propriété DefaultDrawing.

    A noter qu'il est possible de concaténer les with. Ce genre de ligne : With Sender As TStringGrid Do With Canvas Do peut s'écrire With Sender As TStringGrid, Canvas Do.

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    356
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2003
    Messages : 356
    Points : 133
    Points
    133
    Par défaut
    merci pour ta réponse.

    quand j’enlève la "mise" en couleur j'ai à l'origine ça:
    Nom : Capture.JPG
Affichages : 668
Taille : 19,7 Ko

    si j'ajoute le code dans le onDrawCell , et que je met defaultdrawing à false j'ai
    Nom : Capture2.JPG
Affichages : 678
Taille : 19,9 Ko

    je suis obligé de redessiner aussi les cellule du coup ?

    merci
    exyacc

  4. #4
    Membre émérite
    Avatar de ALWEBER
    Homme Profil pro
    Expert Delphi
    Inscrit en
    Mars 2006
    Messages
    1 496
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Expert Delphi

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 496
    Points : 2 762
    Points
    2 762
    Billets dans le blog
    10
    Par défaut
    Avant de faire ton TextOut tu peux faire un fillRect de ta case avec le paramètre Rect

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    356
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2003
    Messages : 356
    Points : 133
    Points
    133
    Par défaut
    oki, c'est mieux, mais du coup je dois aussi redefinir la couleur pour mettre en surbrillance la ligne sélectionnée avec
    un truc genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     if gdSelected in State then 
            StringGrid.Canvas.Brush.Color := $00940A4B;
    ?

    mais du coup je suis obligé de mettre une couleur qui va peur être plus avec le thème que j'ai choisis ....
    je passe du thème windows10 et windows10 slategray et peut être d'autres....
    je peux récupérer la couleur "d'origine" de la cellule ?

    merci

  6. #6
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 693
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 693
    Points : 13 126
    Points
    13 126
    Par défaut
    Tu peux récupérer la couleur du thème :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    uses Vcl.Themes;
     
    StringGrid.Canvas.Brush.Color := StyleServices.GetSystemColor(clHighlight);

  7. #7
    Membre expérimenté
    Avatar de retwas
    Homme Profil pro
    Développeur Java/Delphi
    Inscrit en
    Mars 2010
    Messages
    698
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur Java/Delphi
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2010
    Messages : 698
    Points : 1 608
    Points
    1 608
    Billets dans le blog
    4
    Par défaut
    Mon message va peut être pas beaucoup t'aider mais tu utilises que les composants de base ? Il existe des grilles ou tu peux écrire directement en html pour mettre des liens, de la couleur, etc..

  8. #8
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 459
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 459
    Points : 24 873
    Points
    24 873
    Par défaut
    Compatible avec XE2, je me suis fait mes fonctions maisons pour le dessin dans une TStringGrid, TDBGrid, TListView ...

    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
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    //------------------------------------------------------------------------------
    (*                SoLuTions is an Versatile Library for Delphi                 -
     *                                                                             -
     *  Copyright ou © ou Copr. "SLT Solutions", (2006)                            -
     *  contributeur : ShaiLeTroll (2012) - Gestion des Styles sous C++BuilderXE2  -
     *  contributeur : ShaiLeTroll (2012) - Documentation Insight                  -
     *  contributeur : ShaiLeTroll (2014) - Traduction du code C++Builder vers DelphiXE2
     *                                                                             -
     * Ce logiciel est un programme informatique servant à aider les développeurs  -
     * Delphi avec une bibliothèque polyvalente, adaptable et fragmentable.        -
     *                                                                             -
     * Ce logiciel est régi par la licence CeCILL-C soumise au droit français et   -
     * respectant les principes de diffusion des logiciels libres. Vous pouvez     -
     * utiliser, modifier et/ou redistribuer ce programme sous les conditions      -
     * de la licence CeCILL-C telle que diffusée par le CEA, le CNRS et l'INRIA    -
     * sur le site "http://www.cecill.info".                                       -
     *                                                                             -
     * En contrepartie de l'accessibilité au code source et des droits de copie,   -
     * de modification et de redistribution accordés par cette licence, il n'est   -
     * offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons,   -
     * seule une responsabilité restreinte pèse sur l'auteur du programme,  le     -
     * titulaire des droits patrimoniaux et les concédants successifs.             -
     *                                                                             -
     * A cet égard  l'attention de l'utilisateur est attirée sur les risques       -
     * associés au chargement,  à l'utilisation,  à la modification et/ou au       -
     * développement et à la reproduction du logiciel par l'utilisateur étant      -
     * donné sa spécificité de logiciel libre, qui peut le rendre complexe à       -
     * manipuler et qui le réserve donc à des développeurs et des professionnels   -
     * avertis possédant  des  connaissances  informatiques approfondies.  Les     -
     * utilisateurs sont donc invités à charger  et  tester  l'adéquation  du      -
     * logiciel à leurs besoins dans des conditions permettant d'assurer la        -
     * sécurité de leurs systèmes et ou de leurs données et, plus généralement,    -
     * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.          -
     *                                                                             -
     * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez      -
     * pris connaissance de la licence CeCILL-C, et que vous en avez accepté les   -
     * termes.                                                                     -
     *                                                                             -
     *----------------------------------------------------------------------------*)
    unit SLT.Controls.VCL.GridsEx;
     
    interface
     
    uses System.SysUtils, System.Types,
      Vcl.Grids, Vcl.Graphics, Vcl.Themes;
     
    type
      /// <summary>Erreur liée à l'assistant TStringGridSLTAssistant de la classe TStringGrid</summary>
      EStringGridSLTAssistantError = class(Exception);
     
      /// <summary>Assistance de la classe TStringGrid</summary>
      /// <remarks>Le TStringGridSLTAssistant n'est pas un class helper car lors de sa création la version utilisée était C++Builder XE2,
      /// Traduction C++Builder vers Delphi en concervant ce concept des Assistances de classes (Class Helper) du Delphi.NET</remarks>
      TStringGridSLTAssistant = class(TObject)
      private
        // Membres privés
        FStringGrid: TStringGrid;
      public
        // Constructeurs
        constructor Create(AStringGrid: TStringGrid); overload;
        constructor Create(Sender: TObject); overload;
     
        /// <summary>DrawCellOfEmptyGrid Fournit une assistance au TStringGrid.OnDrawCell pour fournir le rendu d'une cellule vide</summary>
        /// <param name="ACol">indique l'indice de colonne de la cellule à redessiner</param>
        /// <param name="ARow">indique l'indice de ligne de la cellule à redessiner</param>
        /// <param name="ABackgroundColor">Couleur de fond, clNone pour utiliser la couleur du thème</param>
        /// <param name="AState">Le paramètre State indique si la cellule détient la focalisation, si elle est sélectionnée ou si la cellule est une cellule fixe (qui ne défile pas).</param>
        procedure DrawCellEmpty(ACol, ARow: Integer; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
     
        /// <summary>DrawCellTitleCenter Fournit une assistance au TStringGrid.OnDrawCell pour fournir le rendu d'une cellule de titre avec son texte centré horizontalement et verticalement</summary>
        /// <param name="ACol">indique l'indice de colonne de la cellule à redessiner</param>
        /// <param name="ARow">indique l'indice de ligne de la cellule à redessiner</param>
        /// <param name="AText">indique le texte de cellule à redessiner</param>
        /// <param name="ABackgroundColor">Couleur de fond, clNone pour utiliser la couleur du thème</param>
        /// <param name="AState">Le paramètre State indique si la cellule détient la focalisation, si elle est sélectionnée ou si la cellule est une cellule fixe (qui ne défile pas).</param>
        procedure DrawCellTitleCenter(ACol, ARow: Integer; const AText: string; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
     
        /// <summary>DrawCheckBox fournit un assistant d'implémentation d'un TStringGrid.OnDrawColumnCell qui dessine une case à cocher centrée dans la zone définie par ARect</summary>
        /// <param name="ACol">indique l'indice de colonne de la cellule à redessiner</param>
        /// <param name="ARow">indique l'indice de ligne de la cellule à redessiner</param>
        /// <param name="AChecked">Etat de la case à cocher</param>
        /// <param name="AEnabled">la case à cocher est-elle active</param>
        /// <param name="ABackgroundColor">Couleur de fond, clNone pour utiliser la couleur du thème</param>
        /// <param name="AState">Etat de la cellule d'une grille qui est en cours de restitution</param>
        procedure DrawCellCheckBox(ACol, ARow: Integer; AChecked: Boolean; AEnabled: Boolean = True; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
     
        // Méthodes d'ergonomie
        procedure ZoomColumnWidth(AZoomPourcent: Integer);
     
        // Propriétés
        property StringGrid: TStringGrid read FStringGrid;
      end;
     
    implementation
     
    uses Winapi.Windows;
      // Dépendance retiré pour le forum SLT.Controls.VCL.GraphicsEx
     
    const
      ERR_UNASSISTED_CLASS = 'La Classe d''Assistance %s ne prend pas en charge la classe %s mais la classe %s';
     
    { TStringGridSLTAssistant }
     
    //------------------------------------------------------------------------------
    constructor TStringGridSLTAssistant.Create(AStringGrid: TStringGrid);
    begin
      inherited Create();
     
      FStringGrid := AStringGrid;
    end;
     
    //------------------------------------------------------------------------------
    constructor TStringGridSLTAssistant.Create(Sender: TObject);
    begin
      inherited Create();
     
      if Assigned(Sender) then
      begin
        if Sender is TStringGrid then
          FStringGrid := TStringGrid(Sender)
        else
          raise EStringGridSLTAssistantError.CreateFmt(ERR_UNASSISTED_CLASS, [ClassName(), Sender.ClassName(), TStringGrid.ClassName()]);
      end
      else
        raise EStringGridSLTAssistantError.CreateFmt(ERR_UNASSISTED_CLASS, [ClassName(), '[nil]', TStringGrid.ClassName()])
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSLTAssistant.DrawCellCheckBox(ACol, ARow: Integer; AChecked: Boolean; AEnabled: Boolean = True; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    const
      CSelected: array[TGridDrawingStyle] of TThemedGrid = (
        tgClassicCellSelected, tgCellSelected, tgGradientCellSelected);
    var
      uState: UINT;
      tbState: TThemedButton;
      Details: TThemedElementDetails;
      StyleColor: TColor;
      Buffer: Vcl.Graphics.TBitmap;
      vRect, BufferRect: TRect;
    begin
      if StyleServices.Enabled then
      begin
        vRect := StringGrid.CellRect(ACol, ARow); // Rect Plus fiable que celui fourni par OnDrawCell !
     
        // J'utilise un Buffer temporaire pour dessiner le ThemedButton CheckBox dans le TStringGrid
        Buffer := Vcl.Graphics.TBitmap.Create();
        try
          BufferRect := Rect(0, 0, vRect.Width, vRect.Height);
          Buffer.SetSize(BufferRect.Width, BufferRect.Height);
     
          if ABackgroundColor = clNone then
          begin
            // On dessine un fond normal assurant normalement un bon constrate avec la CheckBox
            Details := StyleServices.GetElementDetails(tgCellNormal);
            StyleServices.GetElementColor(Details, ecFillColor, StyleColor);
          end
          else
            StyleColor := ABackgroundColor;
     
          // Même si la cellule est sélectionné, on laisse un fond neutre pour mieux voir la CheckBox
          // Force un fond opaque pour cacher le texte !
          Buffer.Canvas.Brush.Color := StyleColor;
          Buffer.Canvas.Brush.Style := bsSolid;
          Buffer.Canvas.FillRect(BufferRect);
     
          tbState := tbCheckBoxUncheckedNormal;
          if AChecked then
            tbState := tbCheckBoxCheckedNormal;
     
          if not AEnabled then
          begin
            if AChecked then
              tbState := tbCheckBoxCheckedDisabled
            else
              tbState := tbCheckBoxUncheckedDisabled;
          end;
     
          Details := StyleServices.GetElementDetails(tbState);
          StyleServices.DrawElement(Buffer.Canvas.Handle, Details, BufferRect, BufferRect);
          // Dessin final
          StringGrid.Canvas.Draw(vRect.Left, vRect.Top, Buffer);
        finally
          Buffer.Free();
        end;
      end
      else
      begin
        uState := DFCS_BUTTONCHECK;
        if AChecked then
          uState := uState or DFCS_CHECKED;
     
        if not AEnabled then
          uState := uState or DFCS_INACTIVE;
     
        StringGrid.Canvas.FillRect(vRect);
        DrawFrameControl(StringGrid.Canvas.Handle, vRect, DFC_BUTTON, uState);
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSLTAssistant.DrawCellEmpty(ACol, ARow: Integer; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    var
      Details: TThemedElementDetails;
      DetailColor: TColor;
      vRect: TRect;
    begin
      with StringGrid.Canvas do
      begin
        if StyleServices.Enabled then
        begin
          Details := StyleServices.GetElementDetails(tgCellNormal);
          StyleServices.GetElementColor(Details, ecFillColor, DetailColor);
          if ABackgroundColor = clNone then
          begin
            Pen.Color := DetailColor;
            Brush.Color := DetailColor;
          end
          else
          begin
            Pen.Color := ABackgroundColor;
            Brush.Color := ABackgroundColor;      
          end;
        end
        else
        begin
          Pen.Color := StringGrid.Color;
          Brush.Color := StringGrid.Color;
        end;  
     
        vRect := StringGrid.CellRect(ACol, ARow); // Rect Plus fiable que celui fourni par OnDrawCell !
        Rectangle(vRect);
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSLTAssistant.DrawCellTitleCenter(ACol, ARow: Integer; const AText: string; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    var
      vText: string;
      vRect: TRect;
    begin
      if ABackgroundColor <> clNone then
      begin
        StringGrid.Canvas.Pen.Color := ABackgroundColor;
        StringGrid.Canvas.Brush.Color := ABackgroundColor;
        DrawCellEmpty(ACol, ARow, ABackgroundColor, AState);
     
        // Nécessite une dépendance : StringGrid.Canvas.Font.Color := TCanvasSLTAssistant.GetConstratedColor(ABackgroundColor); // Couleur de luminosité inverse : Contraste garanti pour les couleurs claires ou foncées
      end;
     
      // TextRect encapsule DraxTextEx et est aussi pénible avec ses paramètres in-out !
      vText := AText;
      vRect := StringGrid.CellRect(ACol, ARow);
      vRect.Left := vRect.Left + 3; // Pour ne pas superposer le texte et le rectangle de sélection
      // DT_CENTER Centers text horizontally in the rectangle.
      // DT_VCENTER Centers text vertically. This value is used only with the DT_SINGLELINE value.
      StringGrid.Canvas.TextRect(vRect, vText, [tfCenter, tfSingleLine, tfVerticalCenter]);
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSLTAssistant.ZoomColumnWidth(AZoomPourcent: Integer);
    var
      I: Integer;
    begin
      for I := 0 to StringGrid.ColCount - 1 do
        StringGrid.ColWidths[I] := Round(StringGrid.ColWidths[I] * AZoomPourcent / 100);
    end;
     
    end.
    le Helper lorsque l'on est un gros flémard

    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
     
      TStringGridSliteHelper = class helper for TStringGrid
      public
        procedure DrawCellEmpty(ACol, ARow: Integer; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
        procedure DrawCellTitleCenter(ACol, ARow: Integer; const AText: string; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
        procedure DrawCellCheckBox(ACol, ARow: Integer; AChecked: Boolean; AEnabled: Boolean = True; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
        procedure ZoomColumnWidth(AZoomPourcent: Integer);
      end;
     
    ...
     
    { TStringGridSliteHelper }
     
    //------------------------------------------------------------------------------
    procedure TStringGridSliteHelper.DrawCellCheckBox(ACol, ARow: Integer; AChecked: Boolean; AEnabled: Boolean = True; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    begin
      with TStringGridSLTAssistant.Create(Self) do
      try
        DrawCellCheckBox(ACol, ARow, AChecked, AEnabled, ABackgroundColor, AState);
      finally
        Free();
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSliteHelper.DrawCellEmpty(ACol, ARow: Integer; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    begin
      with TStringGridSLTAssistant.Create(Self) do
      try
        DrawCellEmpty(ACol, ARow, ABackgroundColor, AState);
      finally
        Free();
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSliteHelper.DrawCellTitleCenter(ACol, ARow: Integer; const AText: string; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    begin
      with TStringGridSLTAssistant.Create(Self) do
      try
        DrawCellTitleCenter(ACol, ARow, AText, ABackgroundColor, AState);
      finally
        Free();
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSliteHelper.ZoomColumnWidth(AZoomPourcent: Integer);
    begin
      with TStringGridSLTAssistant.Create(Self) do
      try
        ZoomColumnWidth(AZoomPourcent);
      finally
        Free();
      end;
    end;
    le Helper permet un code d'appel très simple


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    //------------------------------------------------------------------------------
    procedure TModulePrimesManageProfilPalierEffectifForm.StringGridBaseCagnotteDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
    begin
      if StringGridBaseCagnotte.Enabled then
      begin
        // Centre le titre dans les entetes de colonne 
        if (ARow = ROW_EFFECTIF) and (ACol >= StringGridBaseCagnotte.FixedCols) then
          StringGridBaseCagnotte.DrawCellTitleCenter(ACol, ARow, FloatToStr(GetEffectif(ACol)), clNone, State);
      end
      else
        StringGridBaseCagnotte.DrawCellEmpty(ACol, ARow, clNone, State);
    end;
    ou encore
    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
     
    //------------------------------------------------------------------------------
    procedure TModulePrimesManageEnseigneForm.StringGridProfilParEnseigneDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
    const
      ECOMMERCE_COLORS: array[TECommerceGridObject.TECommerce] of TColor = (clBtnFace, clWebPapayaWhip, clWebTurquoise);
    var
      ObjECommerce: TECommerceGridObject;
      FlagECommerce: TECommerceGridObject.TECommerce;
    begin
      if (ACol = COL_ECOMMERCE) and (ARow > ROW_TITLE) then
      begin
        // Prise en Compte du e-Commerce selon l'enseigne limité en fonction du Profil
        ObjECommerce := TECommerceGridObject(StringGridProfilParEnseigne.Objects[COL_ECOMMERCE, ARow]);
        if Assigned(ObjECommerce) then
          FlagECommerce := ObjECommerce.ECommerce
        else
          FlagECommerce := ecForbidden;
     
        if FlagECommerce <> ecForbidden then
          StringGridProfilParEnseigne.DrawCellCheckBox(ACol, ARow, FlagECommerce = ecActived, True, ECOMMERCE_COLORS[FlagECommerce], State)
        else
          StringGridProfilParEnseigne.DrawCellTitleCenter(ACol, ARow, 'Non concerné', ECOMMERCE_COLORS[FlagECommerce], State)
      end;
    end;
    Ce qui donne ceci à l'écran

    Nom : StringGrid.png
Affichages : 1561
Taille : 190,4 Ko
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  9. #9
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    356
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2003
    Messages : 356
    Points : 133
    Points
    133
    Par défaut
    merci beaucoup ça marche, par contre c'est galère...

    juste pour avoir une ligne en couleur, on perd tout du thème et doit redéfinir la couleur du brush, de la ligne sélectionné, la taille de la font, etc..

    a+

    exyacc

  10. #10
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    356
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2003
    Messages : 356
    Points : 133
    Points
    133
    Par défaut
    Citation Envoyé par retwas Voir le message
    Mon message va peut être pas beaucoup t'aider mais tu utilises que les composants de base ? Il existe des grilles ou tu peux écrire directement en html pour mettre des liens, de la couleur, etc..
    oui compo de base ou jvcl

  11. #11
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 459
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 459
    Points : 24 873
    Points
    24 873
    Par défaut
    Citation Envoyé par exyacc Voir le message
    merci beaucoup ça marche, par contre c'est galère...

    juste pour avoir une ligne en couleur, on perd tout du thème et doit redéfinir la couleur du brush, de la ligne sélectionné, la taille de la font, etc..

    a+

    exyacc
    D'où l'intérêt de se faire ses fonctions maisons pour ne faire ce travail "galère" qu'une seule fois même si je trouve que personnellement c'est très intéressant à coder (bien plus que le code métier à coup de SQL)
    Tu noteras que les CheckBox dessiné dans la StringGrid sont thèmées !
    Suffit juste d'apprendre les fonctions VCL gérant les thèmes !

    Pour éviter le double texte superposé et de perdre le thème,
    Au lieu de tout redessiner, je ne mets pas de valeur dans Cells[] mais je déporte cela dans Objects[]
    Du coup, il dessine la cellule vide et ses bordures avec le thème et tout le tralala des effets de dégradé,
    il suffit de dessiner le texte par dessus en mode transparent (dans le OnDrawCell du TStringGrid, tu l'es déjà) et ainsi tu conserves tous les effets ...
    C'est un peu comme utiliser la TStringGrid partiellement comme une TDrawGrid juste pour les parties qui te concerne

    C'est l'astuce que j'utilise pour mes titres de colonne centré !
    Il n'y pas de texte dans Cells[] mais j'ai un objet dans Objects[] qui contient l'information permettant le dessin
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  12. #12
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    356
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2003
    Messages : 356
    Points : 133
    Points
    133
    Par défaut
    Citation Envoyé par ShaiLeTroll Voir le message
    Compatible avec XE2, je me suis fait mes fonctions maisons pour le dessin dans une TStringGrid, TDBGrid, TListView ...

    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
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    //------------------------------------------------------------------------------
    (*                SoLuTions is an Versatile Library for Delphi                 -
     *                                                                             -
     *  Copyright ou © ou Copr. "SLT Solutions", (2006)                            -
     *  contributeur : ShaiLeTroll (2012) - Gestion des Styles sous C++BuilderXE2  -
     *  contributeur : ShaiLeTroll (2012) - Documentation Insight                  -
     *  contributeur : ShaiLeTroll (2014) - Traduction du code C++Builder vers DelphiXE2
     *                                                                             -
     * Ce logiciel est un programme informatique servant à aider les développeurs  -
     * Delphi avec une bibliothèque polyvalente, adaptable et fragmentable.        -
     *                                                                             -
     * Ce logiciel est régi par la licence CeCILL-C soumise au droit français et   -
     * respectant les principes de diffusion des logiciels libres. Vous pouvez     -
     * utiliser, modifier et/ou redistribuer ce programme sous les conditions      -
     * de la licence CeCILL-C telle que diffusée par le CEA, le CNRS et l'INRIA    -
     * sur le site "http://www.cecill.info".                                       -
     *                                                                             -
     * En contrepartie de l'accessibilité au code source et des droits de copie,   -
     * de modification et de redistribution accordés par cette licence, il n'est   -
     * offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons,   -
     * seule une responsabilité restreinte pèse sur l'auteur du programme,  le     -
     * titulaire des droits patrimoniaux et les concédants successifs.             -
     *                                                                             -
     * A cet égard  l'attention de l'utilisateur est attirée sur les risques       -
     * associés au chargement,  à l'utilisation,  à la modification et/ou au       -
     * développement et à la reproduction du logiciel par l'utilisateur étant      -
     * donné sa spécificité de logiciel libre, qui peut le rendre complexe à       -
     * manipuler et qui le réserve donc à des développeurs et des professionnels   -
     * avertis possédant  des  connaissances  informatiques approfondies.  Les     -
     * utilisateurs sont donc invités à charger  et  tester  l'adéquation  du      -
     * logiciel à leurs besoins dans des conditions permettant d'assurer la        -
     * sécurité de leurs systèmes et ou de leurs données et, plus généralement,    -
     * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.          -
     *                                                                             -
     * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez      -
     * pris connaissance de la licence CeCILL-C, et que vous en avez accepté les   -
     * termes.                                                                     -
     *                                                                             -
     *----------------------------------------------------------------------------*)
    unit SLT.Controls.VCL.GridsEx;
     
    interface
     
    uses System.SysUtils, System.Types,
      Vcl.Grids, Vcl.Graphics, Vcl.Themes;
     
    type
      /// <summary>Erreur liée à l'assistant TStringGridSLTAssistant de la classe TStringGrid</summary>
      EStringGridSLTAssistantError = class(Exception);
     
      /// <summary>Assistance de la classe TStringGrid</summary>
      /// <remarks>Le TStringGridSLTAssistant n'est pas un class helper car lors de sa création la version utilisée était C++Builder XE2,
      /// Traduction C++Builder vers Delphi en concervant ce concept des Assistances de classes (Class Helper) du Delphi.NET</remarks>
      TStringGridSLTAssistant = class(TObject)
      private
        // Membres privés
        FStringGrid: TStringGrid;
      public
        // Constructeurs
        constructor Create(AStringGrid: TStringGrid); overload;
        constructor Create(Sender: TObject); overload;
     
        /// <summary>DrawCellOfEmptyGrid Fournit une assistance au TStringGrid.OnDrawCell pour fournir le rendu d'une cellule vide</summary>
        /// <param name="ACol">indique l'indice de colonne de la cellule à redessiner</param>
        /// <param name="ARow">indique l'indice de ligne de la cellule à redessiner</param>
        /// <param name="ABackgroundColor">Couleur de fond, clNone pour utiliser la couleur du thème</param>
        /// <param name="AState">Le paramètre State indique si la cellule détient la focalisation, si elle est sélectionnée ou si la cellule est une cellule fixe (qui ne défile pas).</param>
        procedure DrawCellEmpty(ACol, ARow: Integer; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
     
        /// <summary>DrawCellTitleCenter Fournit une assistance au TStringGrid.OnDrawCell pour fournir le rendu d'une cellule de titre avec son texte centré horizontalement et verticalement</summary>
        /// <param name="ACol">indique l'indice de colonne de la cellule à redessiner</param>
        /// <param name="ARow">indique l'indice de ligne de la cellule à redessiner</param>
        /// <param name="AText">indique le texte de cellule à redessiner</param>
        /// <param name="ABackgroundColor">Couleur de fond, clNone pour utiliser la couleur du thème</param>
        /// <param name="AState">Le paramètre State indique si la cellule détient la focalisation, si elle est sélectionnée ou si la cellule est une cellule fixe (qui ne défile pas).</param>
        procedure DrawCellTitleCenter(ACol, ARow: Integer; const AText: string; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
     
        /// <summary>DrawCheckBox fournit un assistant d'implémentation d'un TStringGrid.OnDrawColumnCell qui dessine une case à cocher centrée dans la zone définie par ARect</summary>
        /// <param name="ACol">indique l'indice de colonne de la cellule à redessiner</param>
        /// <param name="ARow">indique l'indice de ligne de la cellule à redessiner</param>
        /// <param name="AChecked">Etat de la case à cocher</param>
        /// <param name="AEnabled">la case à cocher est-elle active</param>
        /// <param name="ABackgroundColor">Couleur de fond, clNone pour utiliser la couleur du thème</param>
        /// <param name="AState">Etat de la cellule d'une grille qui est en cours de restitution</param>
        procedure DrawCellCheckBox(ACol, ARow: Integer; AChecked: Boolean; AEnabled: Boolean = True; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
     
        // Méthodes d'ergonomie
        procedure ZoomColumnWidth(AZoomPourcent: Integer);
     
        // Propriétés
        property StringGrid: TStringGrid read FStringGrid;
      end;
     
    implementation
     
    uses Winapi.Windows;
      // Dépendance retiré pour le forum SLT.Controls.VCL.GraphicsEx
     
    const
      ERR_UNASSISTED_CLASS = 'La Classe d''Assistance %s ne prend pas en charge la classe %s mais la classe %s';
     
    { TStringGridSLTAssistant }
     
    //------------------------------------------------------------------------------
    constructor TStringGridSLTAssistant.Create(AStringGrid: TStringGrid);
    begin
      inherited Create();
     
      FStringGrid := AStringGrid;
    end;
     
    //------------------------------------------------------------------------------
    constructor TStringGridSLTAssistant.Create(Sender: TObject);
    begin
      inherited Create();
     
      if Assigned(Sender) then
      begin
        if Sender is TStringGrid then
          FStringGrid := TStringGrid(Sender)
        else
          raise EStringGridSLTAssistantError.CreateFmt(ERR_UNASSISTED_CLASS, [ClassName(), Sender.ClassName(), TStringGrid.ClassName()]);
      end
      else
        raise EStringGridSLTAssistantError.CreateFmt(ERR_UNASSISTED_CLASS, [ClassName(), '[nil]', TStringGrid.ClassName()])
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSLTAssistant.DrawCellCheckBox(ACol, ARow: Integer; AChecked: Boolean; AEnabled: Boolean = True; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    const
      CSelected: array[TGridDrawingStyle] of TThemedGrid = (
        tgClassicCellSelected, tgCellSelected, tgGradientCellSelected);
    var
      uState: UINT;
      tbState: TThemedButton;
      Details: TThemedElementDetails;
      StyleColor: TColor;
      Buffer: Vcl.Graphics.TBitmap;
      vRect, BufferRect: TRect;
    begin
      if StyleServices.Enabled then
      begin
        vRect := StringGrid.CellRect(ACol, ARow); // Rect Plus fiable que celui fourni par OnDrawCell !
     
        // J'utilise un Buffer temporaire pour dessiner le ThemedButton CheckBox dans le TStringGrid
        Buffer := Vcl.Graphics.TBitmap.Create();
        try
          BufferRect := Rect(0, 0, vRect.Width, vRect.Height);
          Buffer.SetSize(BufferRect.Width, BufferRect.Height);
     
          if ABackgroundColor = clNone then
          begin
            // On dessine un fond normal assurant normalement un bon constrate avec la CheckBox
            Details := StyleServices.GetElementDetails(tgCellNormal);
            StyleServices.GetElementColor(Details, ecFillColor, StyleColor);
          end
          else
            StyleColor := ABackgroundColor;
     
          // Même si la cellule est sélectionné, on laisse un fond neutre pour mieux voir la CheckBox
          // Force un fond opaque pour cacher le texte !
          Buffer.Canvas.Brush.Color := StyleColor;
          Buffer.Canvas.Brush.Style := bsSolid;
          Buffer.Canvas.FillRect(BufferRect);
     
          tbState := tbCheckBoxUncheckedNormal;
          if AChecked then
            tbState := tbCheckBoxCheckedNormal;
     
          if not AEnabled then
          begin
            if AChecked then
              tbState := tbCheckBoxCheckedDisabled
            else
              tbState := tbCheckBoxUncheckedDisabled;
          end;
     
          Details := StyleServices.GetElementDetails(tbState);
          StyleServices.DrawElement(Buffer.Canvas.Handle, Details, BufferRect, BufferRect);
          // Dessin final
          StringGrid.Canvas.Draw(vRect.Left, vRect.Top, Buffer);
        finally
          Buffer.Free();
        end;
      end
      else
      begin
        uState := DFCS_BUTTONCHECK;
        if AChecked then
          uState := uState or DFCS_CHECKED;
     
        if not AEnabled then
          uState := uState or DFCS_INACTIVE;
     
        StringGrid.Canvas.FillRect(vRect);
        DrawFrameControl(StringGrid.Canvas.Handle, vRect, DFC_BUTTON, uState);
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSLTAssistant.DrawCellEmpty(ACol, ARow: Integer; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    var
      Details: TThemedElementDetails;
      DetailColor: TColor;
      vRect: TRect;
    begin
      with StringGrid.Canvas do
      begin
        if StyleServices.Enabled then
        begin
          Details := StyleServices.GetElementDetails(tgCellNormal);
          StyleServices.GetElementColor(Details, ecFillColor, DetailColor);
          if ABackgroundColor = clNone then
          begin
            Pen.Color := DetailColor;
            Brush.Color := DetailColor;
          end
          else
          begin
            Pen.Color := ABackgroundColor;
            Brush.Color := ABackgroundColor;      
          end;
        end
        else
        begin
          Pen.Color := StringGrid.Color;
          Brush.Color := StringGrid.Color;
        end;  
     
        vRect := StringGrid.CellRect(ACol, ARow); // Rect Plus fiable que celui fourni par OnDrawCell !
        Rectangle(vRect);
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSLTAssistant.DrawCellTitleCenter(ACol, ARow: Integer; const AText: string; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    var
      vText: string;
      vRect: TRect;
    begin
      if ABackgroundColor <> clNone then
      begin
        StringGrid.Canvas.Pen.Color := ABackgroundColor;
        StringGrid.Canvas.Brush.Color := ABackgroundColor;
        DrawCellEmpty(ACol, ARow, ABackgroundColor, AState);
     
        // Nécessite une dépendance : StringGrid.Canvas.Font.Color := TCanvasSLTAssistant.GetConstratedColor(ABackgroundColor); // Couleur de luminosité inverse : Contraste garanti pour les couleurs claires ou foncées
      end;
     
      // TextRect encapsule DraxTextEx et est aussi pénible avec ses paramètres in-out !
      vText := AText;
      vRect := StringGrid.CellRect(ACol, ARow);
      vRect.Left := vRect.Left + 3; // Pour ne pas superposer le texte et le rectangle de sélection
      // DT_CENTER Centers text horizontally in the rectangle.
      // DT_VCENTER Centers text vertically. This value is used only with the DT_SINGLELINE value.
      StringGrid.Canvas.TextRect(vRect, vText, [tfCenter, tfSingleLine, tfVerticalCenter]);
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSLTAssistant.ZoomColumnWidth(AZoomPourcent: Integer);
    var
      I: Integer;
    begin
      for I := 0 to StringGrid.ColCount - 1 do
        StringGrid.ColWidths[I] := Round(StringGrid.ColWidths[I] * AZoomPourcent / 100);
    end;
     
    end.
    le Helper lorsque l'on est un gros flémard

    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
     
      TStringGridSliteHelper = class helper for TStringGrid
      public
        procedure DrawCellEmpty(ACol, ARow: Integer; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
        procedure DrawCellTitleCenter(ACol, ARow: Integer; const AText: string; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
        procedure DrawCellCheckBox(ACol, ARow: Integer; AChecked: Boolean; AEnabled: Boolean = True; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
        procedure ZoomColumnWidth(AZoomPourcent: Integer);
      end;
     
    ...
     
    { TStringGridSliteHelper }
     
    //------------------------------------------------------------------------------
    procedure TStringGridSliteHelper.DrawCellCheckBox(ACol, ARow: Integer; AChecked: Boolean; AEnabled: Boolean = True; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    begin
      with TStringGridSLTAssistant.Create(Self) do
      try
        DrawCellCheckBox(ACol, ARow, AChecked, AEnabled, ABackgroundColor, AState);
      finally
        Free();
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSliteHelper.DrawCellEmpty(ACol, ARow: Integer; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    begin
      with TStringGridSLTAssistant.Create(Self) do
      try
        DrawCellEmpty(ACol, ARow, ABackgroundColor, AState);
      finally
        Free();
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSliteHelper.DrawCellTitleCenter(ACol, ARow: Integer; const AText: string; ABackgroundColor: TColor = clNone; AState: TGridDrawState = []);
    begin
      with TStringGridSLTAssistant.Create(Self) do
      try
        DrawCellTitleCenter(ACol, ARow, AText, ABackgroundColor, AState);
      finally
        Free();
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TStringGridSliteHelper.ZoomColumnWidth(AZoomPourcent: Integer);
    begin
      with TStringGridSLTAssistant.Create(Self) do
      try
        ZoomColumnWidth(AZoomPourcent);
      finally
        Free();
      end;
    end;
    le Helper permet un code d'appel très simple


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    //------------------------------------------------------------------------------
    procedure TModulePrimesManageProfilPalierEffectifForm.StringGridBaseCagnotteDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
    begin
      if StringGridBaseCagnotte.Enabled then
      begin
        // Centre le titre dans les entetes de colonne 
        if (ARow = ROW_EFFECTIF) and (ACol >= StringGridBaseCagnotte.FixedCols) then
          StringGridBaseCagnotte.DrawCellTitleCenter(ACol, ARow, FloatToStr(GetEffectif(ACol)), clNone, State);
      end
      else
        StringGridBaseCagnotte.DrawCellEmpty(ACol, ARow, clNone, State);
    end;
    ou encore
    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
     
    //------------------------------------------------------------------------------
    procedure TModulePrimesManageEnseigneForm.StringGridProfilParEnseigneDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
    const
      ECOMMERCE_COLORS: array[TECommerceGridObject.TECommerce] of TColor = (clBtnFace, clWebPapayaWhip, clWebTurquoise);
    var
      ObjECommerce: TECommerceGridObject;
      FlagECommerce: TECommerceGridObject.TECommerce;
    begin
      if (ACol = COL_ECOMMERCE) and (ARow > ROW_TITLE) then
      begin
        // Prise en Compte du e-Commerce selon l'enseigne limité en fonction du Profil
        ObjECommerce := TECommerceGridObject(StringGridProfilParEnseigne.Objects[COL_ECOMMERCE, ARow]);
        if Assigned(ObjECommerce) then
          FlagECommerce := ObjECommerce.ECommerce
        else
          FlagECommerce := ecForbidden;
     
        if FlagECommerce <> ecForbidden then
          StringGridProfilParEnseigne.DrawCellCheckBox(ACol, ARow, FlagECommerce = ecActived, True, ECOMMERCE_COLORS[FlagECommerce], State)
        else
          StringGridProfilParEnseigne.DrawCellTitleCenter(ACol, ARow, 'Non concerné', ECOMMERCE_COLORS[FlagECommerce], State)
      end;
    end;
    Ce qui donne ceci à l'écran

    Nom : StringGrid.png
Affichages : 1561
Taille : 190,4 Ko
    merci beaucoup, j'vais étudier tout ça.

    moi j'aime bien les Helper !

    a+

    exyacc

Discussions similaires

  1. Barrer texte dans StringGrid
    Par PhilLU dans le forum Débuter
    Réponses: 5
    Dernier message: 08/12/2013, 13h00
  2. Agir sur le texte entré dans un éditeur
    Par FatalError dans le forum C++
    Réponses: 1
    Dernier message: 24/10/2004, 14h54
  3. couleur dans StringGrid
    Par amrock dans le forum C++Builder
    Réponses: 1
    Dernier message: 06/09/2004, 11h57
  4. VB6] imprimer le texte afficher dans une picturebox
    Par Persons dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 27/08/2004, 11h15
  5. Options dans StringGrid
    Par AnneOlga dans le forum C++Builder
    Réponses: 5
    Dernier message: 25/03/2004, 14h17

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