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 :

Comment ins�rer une image dans une cellule d'un TStringGrid ?


Sujet :

C++Builder

  1. #1
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut Comment ins�rer une image dans une cellule d'un TStringGrid ?
    Bonjour,

    et bien tout est dans le titre ...

    j'ai un composant TStringGrid sur ma Form que je souhaiterai utiliser comme une sorte de journal d'alertes et ins�rer � l'int�rieur d'une cellule une image de type ".ico".

    Comment puis je faire ???


  2. #2
    R�dacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Par d�faut
    Salut petitclem
    Voici un bout de code qui affiche une image BMP contenue dans un TImage dans chaque cellule d'un STringGrid, a toi de le modifier a ta convenance
    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
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
          int ARow, TRect &Rect, TGridDrawState State)
    {
    int i, j, X, Y;
    TRect R;
    if(State.Contains(gdFixed))
    {
    // Les cellules fixes sont toujours dessinées en gris
    StringGrid1->Canvas->Brush->Color = clBtnFace;
    StringGrid1->Canvas->Brush->Style = bsSolid;
    StringGrid1->Canvas->FillRect(Rect);
    }
    else if(State.Contains(gdSelected))
    {
    // Les cellules sélectionnées sont en bleue
    StringGrid1->Canvas->Brush->Color = clNavy;
    StringGrid1->Canvas->Brush->Style = bsSolid;
    StringGrid1->Canvas->FillRect(Rect);
    }
    else
    {
    // Recherche de la zone image à copier pour tenir compte des décalages
    // de la grille en fonction des barres de défilement.
    X = 0;
    for(i = StringGrid1->FixedCols + 1; i <= ACol; i++) (X++, StringGrid1->ColWidths [i]);
    {
    Y = 0;
    for(i = StringGrid1->FixedRows + 1; i <= ARow; i++) (Y++, StringGrid1->RowHeights[i]);
    {
    R.Left = X;
    R.Right = X + Rect.Right - Rect.Left;
    R.Top = Y;
    R.Bottom = Y + Rect.Bottom - Rect.Top;
    // Dessin d'une partie de l'image
    Image1->Visible = false;
    // D:\\Copie_USB\\Sauvegarde mes documents C\\Mes images\\Massiv10\\Massiv10\\Bitmaps\\Arrow
    Image1->Picture->Bitmap->LoadFromFile("D:\\Copie_USB\\Sauvegarde mes documents C\\Mes images\\Massiv10\\Massiv10\\Bitmaps\\Arrow\\arcarrow1.bmp");
    // "C:\\Documents and Settings\\blondelle\\Mes documents\\Mes images\\Massiv10\\Massiv10\\Bitmaps\\Arrow\\arcarrow1.bmp"
    StringGrid1->Canvas->CopyRect(Rect, Image1->Picture->Bitmap->Canvas, R);
    StringGrid1->Canvas->Brush->Style = bsClear;
    }
    }
    }
    // Sélection de la couleur de texte
    if(State.Contains(gdSelected))
    {
    SetTextColor(StringGrid1->Canvas->Handle, clWhite);
    }
    else
    {
    SetTextColor(StringGrid1->Canvas->Handle, clBlack);
    }
    // Dessin du texte en utilisant la fonction API
    DrawText(StringGrid1->Canvas->Handle, (StringGrid1->Cells[ACol][ARow]).c_str(), -1, &Rect, DT_NOPREFIX );
    }
    //---------------------------------------------------------------------------

  3. #3
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut
    Merci pour ton aide blondelle !

    Ton code fonctionne bien, il remplit mon StringGrid avec l'image mais je n'arrive pas � le modifier pour que �a me mette l'image � l'endroit que je veux (ex: case [1][1]) !!!

    Pourrais tu m'expliquer ?

  4. #4
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut
    C'est bon, j'ai r�ussi !!!

    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
     
    void __fastcall TFormJournal::StringGridAlertesDrawCell(TObject *Sender,
    	  int ACol, int ARow, TRect &Rect, TGridDrawState State)
    {
     
     
    	AnsiString RepertoireApplication = ExtractFilePath(Application->ExeName);
    	AnsiString IconeValider = RepertoireApplication + "IconeValider.bmp";
     
    	TImage *Valider = new TImage(0);
     
    	Valider->Picture->Bitmap->LoadFromFile(IconeValider);
    	StringGridAlertes->Canvas->CopyRect(Rect, Valider->Picture->Bitmap->Canvas, Rect);
     
     
     
     
     
    }
    Par contre comment centrer l'image ?

  5. #5
    R�dacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Par d�faut
    Tu te sert des valeurs de Rect et de ton Image
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    pour recuperer les valeurs
    xx = Rect.Left;
    xx = Rect.Right;
    xx = Rect.Top;
    xx = Rect.Bottom;
     
    pour ecrire les valeurs
    Rect.Left = ...;
    Rect.Right = ...;
    Rect.Top = ...;
    Rect.Bottom = ...;

  6. #6
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut
    OK, merci blondelle.

    Je viens de me rendre compte qu'avec le code que j'ai fait, l'image s'affiche toujours sur la case en haut � gauche !!!

    Comment puis je d�finir la case o� je veux mettre cette image ???


  7. #7
    R�dacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Par d�faut
    je reposte le code complet avec la modification, il faudra affiner le testeen fonction de tes besoins, le calcul de la position de l'image est fonction de mes parametres Image Et cellule
    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
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
          int ARow, TRect &Rect, TGridDrawState State)
    {
    int i, j, X, Y;
    TRect R;
    if(State.Contains(gdFixed))
    {
    // Les cellules fixes sont toujours dessin�es en gris
    StringGrid1->Canvas->Brush->Color = clBtnFace;
    StringGrid1->Canvas->Brush->Style = bsSolid;
    StringGrid1->Canvas->FillRect(Rect);
    }
    else if(State.Contains(gdSelected))
    {
    // Les cellules s�lectionn�es sont en bleue
    StringGrid1->Canvas->Brush->Color = clNavy;
    StringGrid1->Canvas->Brush->Style = bsSolid;
    StringGrid1->Canvas->FillRect(Rect);
    }
    else
    {
    // Recherche de la zone image � copier pour tenir compte des d�calages
    // de la grille en fonction des barres de d�filement.
    //X = 0;
    //for(i = StringGrid1->FixedCols + 1; i <= ACol; i++) (X++, StringGrid1->ColWidths [i]);
    //{
    //Y = 0;
    //for(i = StringGrid1->FixedRows + 1; i <= ARow; i++) (Y++, StringGrid1->RowHeights[i]);
    //{
    if( ARow == 2 && ACol == 1)
    {
    R.Left = 1;
    R.Right = 1 + Rect.Right - Rect.Left;
    R.Top = 1;
    R.Bottom = 1 + Rect.Bottom - Rect.Top;
    // Dessin d'une partie de l'image
    Image1->Visible = false;
    // D:\\Copie_USB\\Sauvegarde mes documents C\\Mes images\\Massiv10\\Massiv10\\Bitmaps\\Arrow
    Image1->Picture->Bitmap->LoadFromFile("D:\\Copie_USB\\Sauvegarde mes documents C\\Mes images\\Massiv10\\Massiv10\\Bitmaps\\Arrow\\arcarrow1.bmp");
    // "C:\\Documents and Settings\\blondelle\\Mes documents\\Mes images\\Massiv10\\Massiv10\\Bitmaps\\Arrow\\arcarrow1.bmp"
    StringGrid1->Canvas->CopyRect(Rect, Image1->Picture->Bitmap->Canvas, R);
    StringGrid1->Canvas->Brush->Style = bsClear;
    }
    //}
    //}
    }
    // S�lection de la couleur de texte
    if(State.Contains(gdSelected))
    {
    SetTextColor(StringGrid1->Canvas->Handle, clWhite);
    }
    else
    {
    SetTextColor(StringGrid1->Canvas->Handle, clBlack);
    }
    // Dessin du texte en utilisant la fonction API
    DrawText(StringGrid1->Canvas->Handle, (StringGrid1->Cells[ACol][ARow]).c_str(), -1, &Rect, DT_NOPREFIX );
    }
    //---------------------------------------------------------------------------
    Ce qui est modifie est en rouge

  8. #8
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut
    Merci blondelle pour ton aide car j'ai r�ussi � ins�rer une image dans la cellule que je voulais !

    Je te sollicite encore pour savoir si tu pouvais m'aider � ins�rer une checkbox dans une cellule de mon stringgrid.
    J'ai essay� en m'inspirant des diff�rents post qui proposaient d'ins�rer une combobox mais sans succ�s ...

    Alors si quelqu'un pouvait encore me donner un petit coup de pouce !

  9. #9
    R�dacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Par d�faut
    Peut etre comme ceci pour l'affichage
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol,
          int ARow, bool &CanSelect)
    {
            if (ACol == 3 && ARow > 0)
            {
            TRect Rect;
            Rect = StringGrid1->CellRect(3, ARow);
            CheckBox1->Top = Rect.Top + StringGrid1->Top + CheckBox1->Height;
            CheckBox1->Left = Rect.Left + StringGrid1->Left + 2;
            }
    }

  10. #10
    Membre �m�rite
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Septembre 2005
    Messages
    401
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 52
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activit� : Ing�nieur d�veloppement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2005
    Messages : 401
    Par d�faut
    Hello,

    En utilisant la m�me m�thode que plus haut, tu peux ins�rer une image qui repr�sente la checkbox coch�e ou d�coch�e suivant le cas...
    Si ensuite tu veux g�rer le click sur la checkbox, tu v�rifies dans l'�v�nement OnClick du TStringGrid la cellule o� a eu lieu le clic
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    TCustomGrid* pGrd = (TCustomGrid*)Sender;
    POINT posSouris = pGrd->ScreenToClient(Mouse->CursorPos);
    // Ligne/colonne sur laquelle on a cliqué
    TGridCoord coordGrille = pGrd->MouseCoord(posSouris.x, posSouris.y);

  11. #11
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut
    D�sol� mais je ne comprend pas du tout comment je dois faire !!!

    J'ai essay� l'affichage de blondelle mais sans succ�s.
    Et pour le code de totoche76, je ne le comprend pas ...


  12. #12
    Membre �m�rite
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Septembre 2005
    Messages
    401
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 52
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activit� : Ing�nieur d�veloppement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2005
    Messages : 401
    Par d�faut
    Hello,

    Tu as r�ussi � afficher l'ic�ne que tu voulais dans la grille ? Si oui, tu dois assez facilement pouvoir afficher une image qui contiendra soit une case coch�e, soit une case d�coch�e.
    Dans un deuxi�me temps, tu pourras g�rer le fait de cocher et d�cocher la case d'un clic de souris.

  13. #13
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut
    oui, j'ai r�ussi � mettre dans la cellule que je voulais la case coch�e ou d�coch�e mais je ne sais pas comment g�rer le changement d'image avec OnClick lorsque l'on clique dans la cellule de la stringgrid !!!

  14. #14
    Membre �m�rite
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Septembre 2005
    Messages
    401
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 52
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activit� : Ing�nieur d�veloppement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2005
    Messages : 401
    Par d�faut
    Hello,

    Sur le OnClick de ta grille:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    void __fastcall TForm32::vGrd1Click(TObject *Sender)
    {
      TCustomGrid* pGrd = (TCustomGrid*)Sender;
      POINT posSouris = pGrd->ScreenToClient(Mouse->CursorPos);
      // Ligne/colonne sur laquelle on a cliqué
      TGridCoord coordGrille = pGrd->MouseCoord(posSouris.x, posSouris.y);
      // Inverse l'état du Checkbox
      if (coordGrille.X == XCheckbox && coordGrille.Y == YCheckbox)
      {
        etatCheckBox = !etatCheckBox;
        // Redessine la grille
        pGrd->Invalidate();
      }
    }

  15. #15
    Membre Expert

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    1 412
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 1 412
    Par d�faut
    Salut !

    Pour r�cup�rer la cellule depuis les coordonn�es de la souris, il y a plus simple :

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    void __fastcall TForm1::StringGrid1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y)
    {
    int ACol;
    int ARow;
    StringGrid1->MouseToCell(X, Y, ACol, ARow);
    //StringGrid1->Cells[ACol][ARow] ...
    }
    A plus !

  16. #16
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut
    Merci beaucoup mais je n'y arrive toujours pas ...

    Alors voil�, j'ai un stringgrid servant de journal d'alertes avec des lignes qui se rajoutent dynamiquement (la premi�re est fixe et comporte les titres) et 6 colonnes fixes.
    je souhaiterai avoir les images checkbox (coch�e ou d�coch�e selon le cas) se mettant toujours � la colonne 6.

    J'ai fait comme ceci :

    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
     
    void __fastcall TFormJournal::StringGridAlertesDrawCell(TObject *Sender,
    	  int ACol, int ARow, TRect &Rect, TGridDrawState State)
    {
     
     
    	AnsiString RepertoireApplication = ExtractFilePath(Application->ExeName);
     
    	AnsiString IconeChecked = RepertoireApplication + "checked.bmp";
    	AnsiString IconeUnchecked = RepertoireApplication + "unchecked.bmp";
     
     
     
     
    	TImage *Checked = new TImage (0);
     
     
    	TRect R;
     
     
    		if (ARow == 1 && ACol == 5)
    	{
    		R.Left = 0;
    		R.Right = Rect.Right - Rect.Left;
    		R.Top = 0;
    		R.Bottom = Rect.Bottom - Rect.Top;
     
     
    		Checked->Picture->Bitmap->LoadFromFile(IconeUnchecked);
     
     
     
    		StringGridAlertes->Canvas->CopyRect(Rect, Checked->Picture->Bitmap->Canvas, R);
    		StringGridAlertes->Canvas->Brush->Style = bsClear;
     
     
     
     
     
    	}
     
     
    	// Dessin du texte en utilisant la fonction API
    	DrawText(StringGridAlertes->Canvas->Handle, (StringGridAlertes->Cells[ACol][ARow]).c_str(), -1, &Rect, DT_NOPREFIX );
     
     
     
    }
    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
     
    void __fastcall TFormJournal::StringGridAlertesMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y)
    {
     
        AnsiString RepertoireApplication = ExtractFilePath(Application->ExeName);
     
    	AnsiString IconeChecked = RepertoireApplication + "checked.bmp";
    	AnsiString IconeUnchecked = RepertoireApplication + "unchecked.bmp";
     
     
            TImage *Checked = new TImage (0);
     
    		Checked->Picture->Bitmap->LoadFromFile(IconeChecked);
     
     
     
     
     
    	int ACol;
    	int ARow;
     
    	StringGridAlertes->MouseToCell(X, Y, ACol, ARow);
    	StringGridAlertes->Cells[ACol][ARow] = IconeChecked;
     
     
    }
    Au d�marrage de ma Form, j'ai mon image checkbox d�coch�e dans la bonne cellule.
    mais lorsque je clique sur cette cellule (et m�me dans toutes les cellules ... ) �a m'affiche le chemin o� se trouve l'image de ma checkbox coch�e !!!!!

    Je ne vois vraiment pas comment me d�patouiller ... blas� !

  17. #17
    Membre �m�rite
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Septembre 2005
    Messages
    401
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 52
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activit� : Ing�nieur d�veloppement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2005
    Messages : 401
    Par d�faut
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    	int ACol;
    	int ARow;
     
    	StringGridAlertes->MouseToCell(X, Y, ACol, ARow);
    	StringGridAlertes->Cells[ACol][ARow] = IconeChecked;
    mais lorsque je clique sur cette cellule (et m�me dans toutes les cellules ... ) �a m'affiche le chemin o� se trouve l'image de ma checkbox coch�e !!!!!
    Normal, non ?? Qu'est-ce que tu en penses ?????


    Dans le constructeur de ta fen�tre, initialisation:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    StringGridAlertes->Objects[5][1] = false;
    Dans le DrawCell:
    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
    void __fastcall TFormJournal::StringGridAlertesDrawCell(TObject *Sender,
    	  int ACol, int ARow, TRect &Rect, TGridDrawState State)
    {
      AnsiString RepertoireApplication = ExtractFilePath(Application->ExeName);
      AnsiString IconeChecked = RepertoireApplication + "checked.bmp";
      AnsiString IconeUnchecked = RepertoireApplication + "unchecked.bmp";
      TImage *Checked = new TImage (NULL);
      TRect R;
      if (ARow == 1 && ACol == 5)
      {
        R.Left = 0;
        R.Right = Rect.Right - Rect.Left;
        R.Top = 0;
        R.Bottom = Rect.Bottom - Rect.Top;
        if (StringGridAlertes->Objects[ACol][ARow] == false)
          Checked->Picture->Bitmap->LoadFromFile(IconeUnchecked);
        else
          Checked->Picture->Bitmap->LoadFromFile(IconeChecked);    
        StringGridAlertes->Canvas->CopyRect(Rect, Checked->Picture->Bitmap->Canvas, R);
        StringGridAlertes->Canvas->Brush->Style = bsClear;
      }
    	
      // Dessin du texte en utilisant la fonction API
      DrawText(StringGridAlertes->Canvas->Handle, (StringGridAlertes->Cells[ACol][ARow]).c_str(), -1, &Rect, DT_NOPREFIX );
    }
    Dans le MouseDown:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    void __fastcall TFormJournal::StringGridAlertesMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y)
    {
      int ACol;
      int ARow;
     
      StringGridAlertes->MouseToCell(X, Y, ACol, ARow);
      if (ARow == 1 && ACol == 5)
        StringGridAlertes->Objects[ACol][ARow] = (TObject*)(!StringGridAlertes->Objects[ACol][ARow]);
     
    }

  18. #18
    Membre Expert

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    1 412
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 1 412
    Par d�faut
    Salut !

    Quelque chose de simple qui n�cessite que les bitmaps soient stock�s dans un TImage (Visible sur false) :

    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
     
    Graphics::TBitmap *Images[2];
     
    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
    Images[0] = Image1->Picture->Bitmap; // OFF
    Images[1] = Image2->Picture->Bitmap; // ON
    //Initialisation du StringGrid, ici la colonne 4
    for(int j = 1; j < StringGrid1->RowCount; j++)
        {
        StringGrid1->Cells[4][j] = "0"; // OFF
        }
    }
     
     
    void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int Col,
          int Row, TRect &Rect, TGridDrawState State)
    {
    if( (Col == 4) && (Row > 0) )
        {
        int n = StringGrid1->Cells[Col][Row][1] & 1;
        StringGrid1->Canvas->Draw(Rect.Left+1,Rect.Top+1, Images[n]);
        }
    }
     
    void __fastcall TForm1::StringGrid1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y)
    {
    int ACol;
    int ARow;
    StringGrid1->MouseToCell(X,Y, ACol, ARow);
    if((ACol == 4) && (ARow > 0))
        {
        AnsiString N = StringGrid1->Cells[ACol][ARow];
        N[1] = (Byte)( N[1] ^ 1); // flip-flop
        StringGrid1->Cells[ACol][ARow] = N;
        }
    }
    A plus !

  19. #19
    Membre �clair�
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    508
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2008
    Messages : 508
    Par d�faut
    Bonjour et merci � tous !

    J'ai essay� la solution de Totoche76 et �a fonctionne !!!

    J'ai une derni�re question � vous poser : � la cr�ation de ma Form, je vais lire une valeur bool�enne dans un fichier .ini.
    Si cette valeur vaut 1 pour la ligne 1 (correspondant � une section), dans ma cellule [0][1] je mets l'ic�ne "Valider" et dans ma cellule [5][1] je mets l'ic�ne "checked", sinon � [0][1] je mets l'ic�ne "Alerte" et � [5][1] l'ic�ne "unchecked".
    Mais j'ai l'impression que dans mon traitement, �a ,e prend en compte que la valeur bool�enne de la premi�re section et �a s'applique � tout le StringGrid...

    Voil� la cr�ation de ma Form :
    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
     
    void __fastcall TFormJournal::FormCreate(TObject *Sender)
    {
     
    	FormJournal->JvStringGridAlertes->Objects[5][1] = false;
     
     
     
    	FormJournal->JvStringGridAlertes->Cells[0][0] = " Etat";
    	FormJournal->JvStringGridAlertes->Cells[1][0] = " Date";
    	FormJournal->JvStringGridAlertes->Cells[2][0] = " Heure";
    	FormJournal->JvStringGridAlertes->Cells[3][0] = " Seuil Défini";
    	FormJournal->JvStringGridAlertes->Cells[4][0] = " Dépassement";
    	FormJournal->JvStringGridAlertes->Cells[5][0] = " Alerte Lue";
     
     
     
     
     
     
    	AnsiString RepertoireApplication = ExtractFilePath(Application->ExeName);
     
    	AnsiString IconeValider = RepertoireApplication + "IconeValider.bmp";
    	AnsiString IconeAlerte = RepertoireApplication + "IconeAlerte.bmp";
    	AnsiString IconeChecked = RepertoireApplication + "checked.bmp";
    	AnsiString IconeUnchecked = RepertoireApplication + "unchecked.bmp";
    	TImage *Checked = new TImage (NULL);
     
    	AnsiString Journal = RepertoireApplication+"\\Alertes\\16B041.al";
    	FichierJournal = new TIniFile(Journal);
    	TStringList *ListeJournal = new TStringList();
     
     
    	struct tm *Time;
     
    	FichierJournal->ReadSections(ListeJournal);
    	for (int i = 0; i < ListeJournal->Count; i++)
    	{
    		//Lecture date et heure
    		time_t DataHeure = StrToInt(FichierJournal->ReadString(ListeJournal->Strings[i] ,"DateHeure",NULL));
    		Time = localtime(&DataHeure);
    		AnsiString Heure;
     
    		//Affichage dans le StringGrid
    		FormJournal->JvStringGridAlertes->Cells[1][i+1] = Heure.sprintf("%02d/%02d/%02d", Time->tm_mday, (Time->tm_mon+1) ,(Time->tm_year+1900));
    		FormJournal->JvStringGridAlertes->Cells[2][i+1] = Heure.sprintf("%02d:%02d:%02d", Time->tm_hour, Time->tm_min, Time->tm_sec);
    		FormJournal->JvStringGridAlertes->Cells[3][i+1] = "pH max : " + FichierJournal->ReadString(ListeJournal->Strings[i] ,"Seuil PH Max", NULL);
    		FormJournal->JvStringGridAlertes->Cells[4][i+1] = FichierJournal->ReadString(ListeJournal->Strings[i] ,"Dépassement", NULL);
     
    		Result = FichierJournal->ReadBool(ListeJournal->Strings[i], "Alerte", 1);
     
     
    		FormJournal->JvStringGridAlertes->RowCount = ListeJournal->Count+1;
    	}
     
    	delete (ListeJournal);
    	delete (FichierJournal);
     
     
     
    }
    et dans le drawcell :
    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
     
    void __fastcall TFormJournal::JvStringGridAlertesDrawCell(TObject *Sender,
    	  int ACol, int ARow, TRect &Rect, TGridDrawState State)
    {
     
    	AnsiString RepertoireApplication = ExtractFilePath(Application->ExeName);
    	AnsiString IconeValider = RepertoireApplication + "IconeValider.bmp";
    	AnsiString IconeAlerte = RepertoireApplication + "IconeAlerte.bmp";
    	AnsiString IconeChecked = RepertoireApplication + "checked.bmp";
    	AnsiString IconeUnchecked = RepertoireApplication + "unchecked.bmp";
    	TImage *Checked = new TImage (NULL);
    	TRect R;
     
    	if (ARow > 0 && ACol == 0)
    	{
     
    		R.Left = 0;
    		R.Right = Rect.Right - Rect.Left;
    		R.Top = 0;
    		R.Bottom = Rect.Bottom - Rect.Top;
     
    		if ((JvStringGridAlertes->Objects[ACol][ARow] == false) )
    			Checked->Picture->Bitmap->LoadFromFile(IconeValider);
    		else
    			Checked->Picture->Bitmap->LoadFromFile(IconeAlerte);
     
     
    		JvStringGridAlertes->Canvas->CopyRect(Rect, Checked->Picture->Bitmap->Canvas, R);
    		JvStringGridAlertes->Canvas->Brush->Style = bsClear;
      }
     
     
     
    	if (ARow > 0 && ACol == 5)
    	{
    		R.Left = 0;
    		R.Right = Rect.Right - Rect.Left;
    		R.Top = 0;
    		R.Bottom = Rect.Bottom - Rect.Top;
     
    		if (JvStringGridAlertes->Objects[ACol][ARow] == false)
    			Checked->Picture->Bitmap->LoadFromFile(IconeChecked);
    		else
    			Checked->Picture->Bitmap->LoadFromFile(IconeUnchecked);
     
     
    		JvStringGridAlertes->Canvas->CopyRect(Rect, Checked->Picture->Bitmap->Canvas, R);
    		JvStringGridAlertes->Canvas->Brush->Style = bsClear;
      }
     
      // Dessin du texte en utilisant la fonction API
      DrawText(JvStringGridAlertes->Canvas->Handle, (JvStringGridAlertes->Cells[ACol][ARow]).c_str(), 0, &Rect, DT_NOPREFIX );
     
     
     
    }

  20. #20
    Membre �m�rite
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Septembre 2005
    Messages
    401
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 52
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activit� : Ing�nieur d�veloppement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2005
    Messages : 401
    Par d�faut
    Question: que fais-tu de ta variable Result dans le constructeur ?? A quel moment affectes-tu la bonne valeur � Objects[][] ??

Discussions similaires

  1. [D�butant] Manipulation d'images : int�grer une image dans une image
    Par noscollections dans le forum VB.NET
    R�ponses: 2
    Dernier message: 17/10/2014, 11h51
  2. Comment ins�rer un JPG dans une image ind�pendante
    Par Claude_paul_louis dans le forum IHM
    R�ponses: 1
    Dernier message: 21/02/2012, 14h55
  3. Comment ins�rer des images dans une ComboBox HTML ?
    Par UiYuki dans le forum Balisage (X)HTML et validation W3C
    R�ponses: 2
    Dernier message: 29/08/2010, 15h35
  4. [MySQL] Comment ins�rer 6 lignes en une fois dans une base mysql avec du PHP ?
    Par Alexandrebox dans le forum PHP & Base de donn�es
    R�ponses: 2
    Dernier message: 10/02/2008, 14h39
  5. Comment ins�rer les valeurs d'une requete dans une variable tableau
    Par uptoditime dans le forum Requ�tes et SQL.
    R�ponses: 2
    Dernier message: 04/12/2007, 12h03

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