Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

centriranje teksta u celiji StringGrid-a

[es] :: C/C++ programiranje :: centriranje teksta u celiji StringGrid-a

[ Pregleda: 1691 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

brenas
srem

Član broj: 50753
Poruke: 110
*.adsl-a-1.sezampro.yu.



Profil

icon centriranje teksta u celiji StringGrid-a07.12.2008. u 09:45 - pre 187 meseci
Naslov teme kaze (pita) sve!
Treba mi ideja (ili jos bolje kod) kako da centriram tekst (po horizontali) upisan u celiju StringGrid-a.
Jel postoj neko elegantno resenje ili (pade mi na pamet) nekako preko sirine kolone?
 
Odgovor na temu

X Files
Vladimir Stefanovic
Pozarevac

SuperModerator
Član broj: 15100
Poruke: 4902
*.dynamic.sbb.rs.

Jabber: xfiles@elitesecurity.org


+638 Profil

icon Re: centriranje teksta u celiji StringGrid-a07.12.2008. u 11:00 - pre 187 meseci
Ovo je neki osnovni kod:
Code:

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
    int x;
    AnsiString Str;
    Str = StringGrid1->Cells[ACol][ARow];
    x = ( ( Rect.Right - Rect.Left ) / 2 ) - ( Canvas->TextWidth( Str ) / 2 );
    SetTextAlign( StringGrid1->Canvas->Handle, TA_CENTER + TA_TOP );
    StringGrid1->Canvas->TextRect( Rect, Rect.Left + x, Rect.Top + 2, Str );
}

... kasnije ga treba modifikovati za ciljanje posebnioh kolona, redova i sl, sve po potrebi.
 
Odgovor na temu

X Files
Vladimir Stefanovic
Pozarevac

SuperModerator
Član broj: 15100
Poruke: 4902
*.dynamic.sbb.rs.

Jabber: xfiles@elitesecurity.org


+638 Profil

icon Re: centriranje teksta u celiji StringGrid-a07.12.2008. u 14:16 - pre 187 meseci
Ili, malo drugacije:
Code:

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
       if (State.Contains(gdFixed)) 
       {
           StringGrid1->Canvas->Brush->Color = clBtnFace; 
           StringGrid1->Canvas->Font->Color = clWindowText; 
           StringGrid1->Canvas->FillRect(Rect); 
           Frame3D(StringGrid1->Canvas, Rect, clBtnHighlight, clBtnShadow, 1); 
       } 
       else if (State.Contains(gdSelected))
       { 
           StringGrid1->Canvas->Brush->Color = clHighlight; 
           StringGrid1->Canvas->Font->Color = clHighlightText; 
           StringGrid1->Canvas->FillRect(Rect); 
       } 
       else 
       { 
           StringGrid1->Canvas->Brush->Color = StringGrid1->Color; 
           StringGrid1->Canvas->Font->Color = StringGrid1->Font->Color; 
           StringGrid1->Canvas->FillRect(Rect); 
       } 

       RECT R = RECT(Rect); 

       UINT format = DT_SINGLELINE | DT_VCENTER;

       // Prva kolona DESNO, druga kolona CENTRIRANO, ostalo LEVO
       if (ACol == 1)
              format = format | DT_RIGHT;
       else if (ACol == 2)
              format = format | DT_CENTER;
       else
              format = format | DT_LEFT;


       AnsiString text = StringGrid1->Cells[ACol][ARow];

       DrawText(StringGrid1->Canvas->Handle, text.c_str(), text.Length(), &R, format);
}
 
Odgovor na temu

brenas
srem

Član broj: 50753
Poruke: 110
*.adsl-a-1.sezampro.yu.



Profil

icon Re: centriranje teksta u celiji StringGrid-a07.12.2008. u 14:23 - pre 187 meseci
Ok! Hvala ti na detaljnom odgovoru.

Negde na forumu (cini mi se Delphi) videh jednu dobru stvar:

for (int i=0; i<1000;i++)
{
ShowMessage("Hvala XFiles");
}
 
Odgovor na temu

[es] :: C/C++ programiranje :: centriranje teksta u celiji StringGrid-a

[ Pregleda: 1691 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.