procedure TFrm_main.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
myrect, myrect2, myrectTemp1, myrectTemp2: TRect;
str, strV, str2, str3: string;
i: integer;
begin
myrect := Rect;
myrect.Top := myrect.Top + 3;
myrect.Left := myrect.Left + 3;
myrect.Right := myrect.Right - 3;
try
with TStringGrid(Sender) do
begin
Canvas.Font := font;
str := cells[ACol, ARow];
if gdSelected in State then
begin
Canvas.Brush.Color := $00C07F3A;
Canvas.Font.Color := Clwhite;
end
else
if gdFixed in State then
begin
Canvas.Brush.Color := clbtnface;
Canvas.Font.Color := Clblack;
end
else
begin
Canvas.Brush.Color := Color;
Canvas.Font.Color := Clblack;
end;
Canvas.FillRect(Rect);
if arow < FixedRows then
drawtext(Canvas.Handle, pchar(str), -1, myrect, DT_CENTER)
else
begin
if acol < 1 then
begin
if isSend(str) then
begin
Canvas.Font.Color := Clred;
drawtext(Canvas.Handle, pchar(getComName(str)), -1, myrect, DT_RIGHT);
ImageList1.Draw(Canvas, (rect.left + rect.right - 0) div 2, (rect.top + rect.Bottom - 16) div 2, 3);
myrect.Right := rect.Left + (rect.left + rect.right) div 2 - 4;
drawtext(Canvas.Handle, pchar(inttostr(length(cells[1, ARow]) div 2)), -1, myrect, DT_RIGHT)
end
else
if isReceive(str) then
begin
Canvas.Font.Color := Clblue;
drawtext(Canvas.Handle, pchar(getComName(str)), -1, myrect, DT_LEFT);
ImageList1.Draw(Canvas, (rect.left + rect.right - 32) div 2, (rect.top + rect.Bottom - 16) div 2, 4);
myrect.Left := rect.Left + (rect.left + rect.right) div 2 + 4;
drawtext(Canvas.Handle, pchar(inttostr(length(cells[1, ARow]) div 2)), -1, myrect, DT_LEFT)
end
else
drawtext(Canvas.Handle, pchar(str), -1, myrect, DT_CENTER)
end
else
begin
if isSend(cells[ACol - 1, ARow]) or isReceive(cells[ACol - 1, ARow]) then
begin
if isSend(cells[ACol - 1, ARow]) then
Canvas.Font.Color := Clred
else
Canvas.Font.Color := Clblue;
case ComboBox1.ItemIndex of
0:
begin
myrectTemp2 := myrect;
for i := 1 to length(str) div 2 do
begin
str3 := copy(str, 2 * i - 1, 2);
str3 := trim(char(strtoint('$' + str3)));
drawtext(Canvas.Handle, pchar(str3), -1, myrectTemp2, DT_LEFT);
inc(myrectTemp2.Left, 9);
if myrectTemp2.Left > myrectTemp2.Right then
Break;
end;
end;
1:
begin
myrectTemp1 := myrect;
for i := 1 to length(str) div 2 do
begin
str3 := copy(str, 2 * i - 1, 2);
drawtext(Canvas.Handle, pchar(str3), -1, myrectTemp1, DT_LEFT);
inc(myrectTemp1.Left, 20);
if myrectTemp1.Left > myrectTemp1.Right then
Break;
end;
end;
2:
begin
myrectTemp1 := myrect;
myrectTemp2 := myrect;
inc(myrectTemp2.Top, 17);
Canvas.MoveTo(rect.Left, rect.Top + 17);
for i := 1 to length(str) div 2 do
begin
str3 := copy(str, 2 * i - 1, 2);
drawtext(Canvas.Handle, pchar(str3), -1, myrectTemp2, DT_LEFT);
str3 := trim(char(strtoint('$' + str3)));
drawtext(Canvas.Handle, pchar(str3), -1, myrectTemp1, DT_LEFT);
inc(myrectTemp1.Left, 20);
inc(myrectTemp2.Left, 20);
if myrectTemp2.Left > myrectTemp2.Right then
Break;
end;
// Canvas.Pen.Color := clblue;
Canvas.MoveTo(rect.Left, rect.Top + 16);
Canvas.LineTo(rect.Right, rect.Top + 16);
end;
end;
end
else
begin
drawtext(Canvas.Handle, pchar(str), -1, myrect, DT_LEFT);
end;
end;
end;
Canvas.Pen.Color := clblack;
if acol = 0 then
begin
Canvas.MoveTo(rect.Left, rect.Top);
Canvas.LineTo(rect.Left, rect.Bottom);
end;
if Arow = 0 then
begin
Canvas.MoveTo(rect.Left, rect.Top);
Canvas.LineTo(rect.Right, rect.Top);
end;
Canvas.MoveTo(rect.Left, rect.Bottom - 1);
Canvas.LineTo(rect.Right - 1, rect.Bottom - 1);
Canvas.LineTo(rect.Right - 1, rect.top - 1);
end;
except
;
end
end;