by
ru
en
by

Avemey

logo
FilesMainLinksPhotosAnime

Code examples for ZColorStringGrid and ZCLabel

ZColorStringGrid Tested with: Delphi 7, 2005-XE2; C++Builder 6.
ZCLabel Tested with:
  • Lazarus 0.9.28.2 (FPC 2.2.4 + Debian 5.0 + KDE3.5), Lazarus 0.9.30.2 (FPC 2.4.4 + Debian 6.0.3 + GNOME / Windows)
  • Delphi 7, 2005-XE2
  • C++Builder 6

Examples of use ZColorStringGrid:

Cell style

ZColorStringGrid cell style

Code example for Delphi Code example for C++Builder
procedure TfrmMain.FormCreate(Sender: TObject);
var
  i, j: integer;

begin
  //Fill grid
  for i := 1 to ZColorStringGrid1.ColCount - 1 do
  for j := 1 to ZColorStringGrid1.RowCount - 1 do
    ZColorStringGrid1.Cells[i, j] := IntToStr(i * j);

  //Background color
  ZColorStringGrid1.CellStyle[1, 1].BGColor := clYellow;
  ZColorStringGrid1.CellStyle[2, 1].BGColor := clGreen;
  ZColorStringGrid1.CellStyle[3, 1].BGColor := clLime;

  //Change the style of the column
  ZColorStringGrid1.CellStyleCol[1, false] := ZColorStringGrid1.CellStyle[1, 1];
  ZColorStringGrid1.CellStyleCol[2, true] := ZColorStringGrid1.CellStyle[2, 1];

  //Change the style of a row
  ZColorStringGrid1.CellStyleRow[3, false] := ZColorStringGrid1.CellStyle[3, 1];

  //Font
  ZColorStringGrid1.CellStyle[2, 3].Font.Size := 12;
  ZColorStringGrid1.CellStyle[2, 3].Font.Name := 'Tahoma';
  ZColorStringGrid1.CellStyle[2, 3].Font.Style := [fsBold, fsItalic];
  ZColorStringGrid1.CellStyle[2, 2].Font.Color := clWhite;

  //Cells border
  ZColorStringGrid1.CellStyle[3, 3].BorderCellStyle := sgLowered;
  ZColorStringGrid1.CellStyle[4, 3].BorderCellStyle := sgRaised;
end;
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
  int i = 0;
  int j = 0;
  //Fill grid
  for (i = 0; i < ZColorStringGrid1->ColCount; i++)
  for (j = 0; j < ZColorStringGrid1->RowCount; j++)
  {
    ZColorStringGrid1->Cells[i][j] = IntToStr(i * j);
  }

  //Background color
  ZColorStringGrid1->CellStyle[1][1]->BGColor = clYellow;
  ZColorStringGrid1->CellStyle[2][1]->BGColor = clGreen;
  ZColorStringGrid1->CellStyle[3][1]->BGColor = clLime;

  //Change the style of the column
  ZColorStringGrid1->CellStyleCol[1][false] = ZColorStringGrid1->CellStyle[1][1];
  ZColorStringGrid1->CellStyleCol[2][true] = ZColorStringGrid1->CellStyle[2][1];

  //Change the style of a row
  ZColorStringGrid1->CellStyleRow[3][false] = ZColorStringGrid1->CellStyle[3][1];

  //Font
  ZColorStringGrid1->CellStyle[2][3]->Font->Size = 12;
  ZColorStringGrid1->CellStyle[2][3]->Font->Name = "Tahoma";
  ZColorStringGrid1->CellStyle[2][3]->Font->Style = 
    TFontStyles() << fsBold << fsItalic;
  ZColorStringGrid1->CellStyle[2][2]->Font->Color = clWhite;

  //Cells border
  ZColorStringGrid1->CellStyle[3][3]->BorderCellStyle = sgLowered;
  ZColorStringGrid1->CellStyle[4][3]->BorderCellStyle = sgRaised;
}

Using the alignment and indentation

ZColorStringGrid Using the alignment and indentation

Code example for Delphi Code example for C++Builder
procedure TfrmMain.FormCreate(Sender: TObject);
var
  i, j, r: byte;

begin
  //Alignment: horizontal - left, vertical - center
  ZColorStringGrid1.Cells[1, 0] := 'H:L + V:C';
  //Alignment: horizontal - right vertical - center
  ZColorStringGrid1.Cells[2, 0] := 'H:R + V:C';
  //Alignment: horizontal - left, vertical - from the top
  ZColorStringGrid1.Cells[3, 0] := 'H:L + V:T';
  //Alignment: horizontal - in the center, vertical - from the bottom
  ZColorStringGrid1.Cells[4, 0] := 'H:C + V:D';
  for i := 0 to 5 do
  begin
    r := i + 1;
    for j := 1 to 4 do
    begin
      ZColorStringGrid1.Cells[j, r] := IntToStr(i);
      //The indentation in the horizontal
      ZColorStringGrid1.CellStyle[j, r].IndentH := i;
    end;
    //Right
    ZColorStringGrid1.CellStyle[2, r].HorizontalAlignment := taRightJustify;
    //Top
    ZColorStringGrid1.CellStyle[3, r].VerticalAlignment := vaTop;
    //Center
    ZColorStringGrid1.CellStyle[4, r].HorizontalAlignment := taCenter;
    //Bottom
    ZColorStringGrid1.CellStyle[4, r].VerticalAlignment := vaBottom;

    //The indentation in the vertical
    for j := 3 to 4 do
      ZColorStringGrid1.CellStyle[j, r].IndentV := i;
  end;
end;
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
  //Alignment: horizontal - left, vertical - center
  ZColorStringGrid1->Cells[1][0] = "H:L + V:C";
  //Alignment: horizontal - right vertical - center
  ZColorStringGrid1->Cells[2][0] = "H:R + V:C";
  //Alignment: horizontal - left, vertical - from the top
  ZColorStringGrid1->Cells[3][0] = "H:L + V:T";
  //Alignment: horizontal - in the center, vertical - from the bottom
  ZColorStringGrid1->Cells[4][0] = "H:C + V:D";
  int i = 0;
  int j = 0;
  int r = 0;
  for (i = 0; i <= 5; i++)
  {
    r = i + 1;
    for (j = 1; j < 5; j++)
    {
      ZColorStringGrid1->Cells[j][r] = IntToStr(i);
      //The indentation in the horizontal
      ZColorStringGrid1->CellStyle[j][r]->IndentH = i;
    }
    //Right
    ZColorStringGrid1->CellStyle[2][r]->HorizontalAlignment = taRightJustify;
    //Top
    ZColorStringGrid1->CellStyle[3][r]->VerticalAlignment = vaTop;
    //Center
    ZColorStringGrid1->CellStyle[4][r]->HorizontalAlignment = taCenter;
    //Bottom
    ZColorStringGrid1->CellStyle[4][r]->VerticalAlignment = vaBottom;

    //The indentation in the vertical
    for (j = 3; j < 5; j++)
      ZColorStringGrid1->CellStyle[j][r]->IndentV = i;
  }
}

Merging Cells

ZColorStringGrid Merging Cells

Code example for Delphi Code example for C++Builder
procedure TfrmMain.FormCreate(Sender: TObject);
var
  Rct: TRect;
  res: integer;

begin
  //merge for fixed cells
  res := ZColorStringGrid1.MergeCells.AddRectXY(1, 0, 3, 0);
  if (res <> 0) then
  begin
    {If you can not merge cells}
  end;
  ZColorStringGrid1.Cells[1, 0] := 'Merged cell';
  Rct.Top := 1;
  Rct.Left := 0;
  Rct.Right := 0;
  Rct.Bottom := 3;
  ZColorStringGrid1.MergeCells.AddRect(Rct);
  ZColorStringGrid1.Cells[0, 1] := 'Text';

  //Attempt to merge the fixed cells with non-fixed
  res := ZColorStringGrid1.MergeCells.AddRectXY(0, 4, 3, 5);
  if (res <> 0) then
    ZColorStringGrid1.Cells[0, 4] := 'Fail'
  else
    ZColorStringGrid1.Cells[0, 4] := 'Ok!';

  //Check the merge is not required
  ZColorStringGrid1.MergeCells.AddRectXY(2, 1, 4, 4);
  ZColorStringGrid1.Cells[2, 1] := ZColorStringGrid1.Cells[1, 0];
end;
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
  int res = 0;
  //merge for fixed cells
  res = ZColorStringGrid1->MergeCells->AddRectXY(1, 0, 3, 0);
  if (res != 0)
  {
    /* If you can not merge cells */
  }
  ZColorStringGrid1->Cells[1][0] = "Merged cell";

  TRect Rct;
  Rct.Top = 1;
  Rct.Left = 0;
  Rct.Right = 0;
  Rct.Bottom = 3;
  ZColorStringGrid1->MergeCells->AddRect(Rct);
  ZColorStringGrid1->Cells[0][1] = "Text";

  //Attempt to merge the fixed cells with non-fixed
  res = ZColorStringGrid1->MergeCells->AddRectXY(0, 4, 3, 5);
  if (res != 0)
    {ZColorStringGrid1->Cells[0][4] = "Fail";}
  else
    {ZColorStringGrid1->Cells[0][4] = "Ok!";};

  //Check the merge is not required
  ZColorStringGrid1->MergeCells->AddRectXY(2, 1, 4, 4);
  ZColorStringGrid1->Cells[2][1] = ZColorStringGrid1->Cells[1][0];
}

Rotate text in cells

NOTE: To rotate text can only use TrueType fonts!
ZColorStringGrid Rotating text

Code example for Delphi Code example for C++Builder
procedure TfrmMain.FormCreate(Sender: TObject);
var
  i, j: integer;

begin
  //Set all the cells TrueType font
  for i := 0 to ZColorStringGrid1.ColCount - 1 do
  for j := 0 to ZColorStringGrid1.RowCount - 1 do
  begin
    ZColorStringGrid1.CellStyle[i, j].Font.Name := 'Tahoma';
    ZColorStringGrid1.CellStyle[i, j].Font.Size := 12;
  end;
  //Set rotate for merged cells
  ZColorStringGrid1.MergeCells.AddRectXY(0, 1, 0, 4);
  ZColorStringGrid1.CellStyle[0, 1].Rotate := 90;
  ZColorStringGrid1.Cells[0, 1] := 'Rotate' + sLineBreak +
    'text' + sLineBreak + '90 degrees';

  ZColorStringGrid1.MergeCells.AddRectXY(1, 0, 3, 0);
  ZColorStringGrid1.CellStyle[1, 0].Rotate := 180;
  ZColorStringGrid1.Cells[1, 0] := 'Rotate 180 degrees';

  ZColorStringGrid1.MergeCells.AddRectXY(2, 1, 4, 6);
  ZColorStringGrid1.CellStyle[2, 1].Rotate := 60;
  ZColorStringGrid1.CellStyle[2, 1].Font.Size := 16;
  ZColorStringGrid1.CellStyle[2, 1].HorizontalAlignment := taCenter;
  ZColorStringGrid1.Cells[2, 1] := 'Rotating' + sLineBreak +
    'multi-line' + sLineBreak + 'text at' +
    sLineBreak + '60 degrees';

  //Rotate in cells
  ZColorStringGrid1.CellStyle[1, 1].Rotate := 180;
  ZColorStringGrid1.Cells[1, 1] := 'Text';
end;
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
  int i = 0;
  int j = 0;
  //Set all the cells TrueType font
  for (i = 0; i < ZColorStringGrid1->ColCount; i++)
  for (j = 0; j < ZColorStringGrid1->RowCount; j++)
  {
    ZColorStringGrid1->CellStyle[i][j]->Font->Name = "Tahoma";
    ZColorStringGrid1->CellStyle[i][j]->Font->Size = 12;
  }
  //Set rotate for merged cells
  ZColorStringGrid1->MergeCells->AddRectXY(0, 1, 0, 4);
  ZColorStringGrid1->CellStyle[0][1]->Rotate = 90;
  ZColorStringGrid1->Cells[0][1] = String("Rotate") +  sLineBreak +
	String("text") + sLineBreak + String("90 degrees");

  ZColorStringGrid1->MergeCells->AddRectXY(1, 0, 3, 0);
  ZColorStringGrid1->CellStyle[1][0]->Rotate = 180;
  ZColorStringGrid1->Cells[1][0] = "Rotate 180 degrees";

  ZColorStringGrid1->MergeCells->AddRectXY(2, 1, 4, 6);
  ZColorStringGrid1->CellStyle[2][1]->Rotate = 60;
  ZColorStringGrid1->CellStyle[2][1]->Font->Size = 16;
  ZColorStringGrid1->CellStyle[2][1]->HorizontalAlignment = taCenter;
  ZColorStringGrid1->Cells[2][1] = String("Rotating") + sLineBreak +
	String("multi-line") + sLineBreak + String("text at") +
	sLineBreak + String("60 degrees");

  //Rotate in cells
  ZColorStringGrid1->CellStyle[1][1]->Rotate = 180;
  ZColorStringGrid1->Cells[1][1] = "Text";
}

Examples of use ZCLabel:

Alignment and text rotation


To successfully run on the form must be placed 15 ZClabel-s, set them TrueType font, set the width and height (80 and 70).
ZCLabel Alignment and text rotation

Code example for Lazarus/Delphi Code example for C++Builder
procedure TfrmMain.FormCreate(Sender: TObject);
var
  i: integer;
  num: integer;
  ZCL: TZCLabel;
  s: string;
  ang: integer;
  sEOL: string;

begin
  num := 0;
  ang := 0;
  {$IFDEF FPC}
  sEOL := LineEnding;
  {$ELSE}
  sEOL := sLineBreak;
  {$ENDIF}

  s := 'Text example' + sEOL + 'smttext.';
  //Iterate through the components
  for i := 0 to ComponentCount - 1 do
    if (Components[i] is TZCLabel) then
    begin
      ZCL := Components[i] as TZCLabel;
      ZCL.Font.Size := 10;
      ZCL.Caption := s;
      inc(num);
      if (num mod 5 in [1, 2, 3]) then
      begin
        ZCL.Transparent := false;
        ZCL.Color := clYellow;
      end else
      begin
        ZCL.Font.Size := 14;
        inc(ang, 50);
        //Set rotate angle
        ZCL.Rotate := ang;
      end;
      //Horizontal alignment
      ZCL.AlignmentHorizontal := num mod 3;
      //Vertical alignment
      ZCL.AlignmentVertical := num mod 5;
    end; //if  
end;
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
  int num = 0;
  int ang = 0;
  int t;
  TZCLabel * ZCL;
  String s = String("Text example") + sLineBreak + String("smttext.");
  //Iterate through the components
  int i = 0;
  for (i = 0; i < ComponentCount; i++)
  {
    if (ZCL = dynamic_cast<TZCLabel *>(Components[i]))
    {
      ZCL->Font->Size = 10;
      ZCL->Caption = s;
      num++;
      t = num % 5;
      if ((t > 0) && (t < 4))
      {
        ZCL->Transparent = false;
        ZCL->Color = clYellow;
      } else
      {
        ZCL->Font->Size = 14;
        ang += 50;
        //Set rotate angle
        ZCL->Rotate = ang;
      }
      //Horizontal alignment
      ZCL->AlignmentHorizontal = num % 3;
      //Vertical alignment
      ZCL->AlignmentVertical = num % 5;
    }
  }
}

Drawing on any canvas



ZCLabel Drawing on any canvas

Code example for Lazarus/Delphi Code example for C++Builder
procedure TfrmMain.FormCreate(Sender: TObject);
var
  Rct: TRect;
  i: integer;
  t: byte;
  Cl: TColor;
  sEOL, s: string;

begin
  {$IFDEF FPC}
  sEOL := LineEnding;
  {$ELSE}
  sEOL := sLineBreak;
  {$ENDIF}

  ZCLabel1.Visible := false;

  Image1.Canvas.Brush.Color := clWhite;
  Image1.Canvas.Brush.Style := bsSolid;
  Image1.Canvas.Rectangle(0, 0, Image1.Width, Image1.Height);

  Rct.Left := 0;
  Rct.Top := 0;
  Rct.Right := 120;
  Rct.Bottom := 50;
  for i := 1 to 5 do
  begin
    ZCLabel1.Font.Size := 10 + i;
    //Draws the text on canvas using font color
    ZCLabel1.DrawTextOn(Image1.Canvas, 'Some text', Rct, false);
    Rct.Top := Rct.Top + 10;
    Rct.Bottom := Rct.Bottom + 10;
    Rct.Left := Rct.Left + 1;
    Rct.Right := Rct.Right + 1;
  end;

  Rct.Left := 0;
  Rct.Right := Image1.Width;
  Rct.Top := 0;
  Rct.Bottom := Image1.Height;
  
  i := 0;
  ZCLabel1.AlignmentVertical := 2;
  ZCLabel1.AlignmentHorizontal := 0;
  t := 255;
  while (i <= 90) do
  begin
    ZCLabel1.Rotate := i;
    cl := t shl 8;
    //Draws the text on canvas using color cl
    ZCLabel1.DrawTextOn(Image1.Canvas, 'Some text', Rct, cl, false);
    inc(i, 5);
    dec(t, 14);
  end;

  //Alignment
  ZCLabel1.AlignmentVertical := 0;
  ZCLabel1.AlignmentHorizontal := 2;
  i := 0;
  while (i <= 90) do
  begin
    ZCLabel1.Rotate := i;
    ZCLabel1.DrawTextOn(Image1.Canvas, 'Some text', Rct, false);
    inc(i, 10);
  end;

  ZCLabel1.Font.Size := 20;

  ZCLabel1.Rotate := -30;
  ZCLabel1.AlignmentVertical := 1;
  ZCLabel1.AlignmentHorizontal := 1;
  
  //The distance between lines
  ZCLabel1.LineSpacing := -10;

  s := 'ZClabel' + sEOL + 'example drawing' + sEOL +
       'on other canvas';
  ZCLabel1.DrawTextOn(Image1.Canvas, s, Rct, clGreen, false);

  //Save picture to file
  Image1.Picture.Bitmap.SaveToFile({some_path}'1.bmp');
end;
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
  ZCLabel1->Visible = false;

  TRect Rct;
  Rct.Left = 0;
  Rct.Top = 0;
  Rct.Right = 120;
  Rct.Bottom = 50;
  Graphics::TCanvas *CNV;

  CNV = Image1->Canvas;
  CNV->Brush->Color = clWhite;
  CNV->Brush->Style = bsSolid;
  CNV->Rectangle(0, 0, Image1->Width, Image1->Height);
  CNV->TextOut(10, 10, "dasd");
  String z = "Some text";

  int i = 0;
  for (i = 1; i < 6; i++)
  {
    ZCLabel1->Font->Size = 10 + i;
    //Draws the text on canvas using font color
    ZCLabel1->DrawTextOn(CNV, z, Rct, false);

    Rct.Top += 10;
    Rct.Bottom += 10;
    Rct.Left += 1;
    Rct.Right +=  + 1;
  }

  Rct.Left = 0;
  Rct.Right = Image1->Width;
  Rct.Top = 0;
  Rct.Bottom = Image1->Height;

  i = 0;
  ZCLabel1->AlignmentVertical = 2;
  ZCLabel1->AlignmentHorizontal = 0;
  int t = 255;
  TColor cl = clBlack;
  while (i <= 90)
  {
    ZCLabel1->Rotate = i;
    cl = t << 8;
    //Draws the text on canvas using color cl
    ZCLabel1->DrawTextOn(CNV, "Some text", Rct, cl, false);
    i += 5;
    t -= 14;
  }

  //Alignment
  ZCLabel1->AlignmentVertical = 0;
  ZCLabel1->AlignmentHorizontal = 2;
  i = 0;
  while (i <= 90)
  {
    ZCLabel1->Rotate = i;
    ZCLabel1->DrawTextOn(CNV, "Some text", Rct, false);
    i += 10;
  }

  ZCLabel1->Font->Size = 20;

  ZCLabel1->Rotate = -30;
  ZCLabel1->AlignmentVertical = 1;
  ZCLabel1->AlignmentHorizontal = 1;

  //The distance between lines
  ZCLabel1->LineSpacing = -10;

  String s = String("ZClabel") + sLineBreak + String("example drawing") +
     sLineBreak + String("on other canvas");
  ZCLabel1->DrawTextOn(CNV, s, Rct, clGreen, false);

  //Save picture to file
  Image1->Picture->Bitmap->SaveToFile(/* some_path */"1.bmp");
}
FilesMainLinksPhotosAnime

Copyright © 2006-2012 Ruslan V. Neborak