Einzelnen Beitrag anzeigen

tofse

Registriert seit: 6. Jun 2011
Ort: Saarlouis
131 Beiträge
 
Delphi XE Professional
 
#1

onDrawCell überschreibt Caption vom Formular

  Alt 14. Feb 2012, 10:17
Hallo,

ich steh total auf'm Schlauch. Was stimmt an diesem Code unten nicht?
Wenn ich das im onDrawCell eines TStringGrid's drinnen lasse, dann wird bei einem onSelectCell der Inhalt der Zelle in die Titelleiste des Formulars geschrieben.



Code:
procedure TForm.DrawTerminart(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var outRect:TRect;
begin
  if (ACol > 1) And (ARow >= 1) then
  begin
    with sender as TStringGrid do
    begin
      Text := Cells[ACol, ARow];
      outRect:=Rect;
      Canvas.Brush.Color:=clWhite;
      Canvas.Fillrect(Rect);
      Canvas.Font.Name:='Wingdings 2';
      Canvas.Font.Size:=14;
      if ACol=9 then
        Canvas.Font.Color:=clGray
      else
        Canvas.Font.Color:=clBlack;

      outRect.Top:=outRect.Top + 2;
      DrawText(Canvas.Handle,
           PChar(Text),
           length(Text),
           outRect,
           DT_Center
           or
           DT_SingleLine);
    end;
  end;
end;
Ich habe das schon zig Mal verwendet. Für mich der einzige Unterschied ist, dass ich das StringGrid erst zur Laufzeit erzeuge, aber auch hier fällt mir nichts auf...
Code:
  G:=TStringGrid.Create(TabControl);
  G.Parent:=TabControl;
  G.FixedRows:=1;
  G.FixedCols:=0;
  G.ColCount:=11;
  G.RowCount:=2;
  G.Top:=25;
  G.Left:=2;
  G.Cells[0,0]:='Bezeichnung';
  G.Cells[1,0]:='Dauer';
  G.Cells[2,0]:='Mo';
  G.Cells[3,0]:='Di';
  G.Cells[4,0]:='Mi';
  G.Cells[5,0]:='Do';
  G.Cells[6,0]:='Fr';
  G.Cells[7,0]:='Sa';
  G.Cells[8,0]:='So';
  G.ScrollBars:=ssVertical;
  G.Width:=TabControl.Width - 7;
  G.Height:=TabControl.Height - 25;
  G.ColWidths[0]:=310;
  G.ColWidths[1]:=60;
  G.ColWidths[2]:=20;
  G.ColWidths[3]:=20;
  G.ColWidths[4]:=20;
  G.ColWidths[5]:=20;
  G.ColWidths[6]:=20;
  G.ColWidths[7]:=20;
  G.ColWidths[8]:=20;
  G.ColWidths[9]:=20;
  G.ColWidths[10]:=0;
  G.OnDrawCell:=DrawTerminart;
  G.OnSelectCell:=SelectTerminart;
  G.OnKeyDown:=KeyDownTerminart;
  G.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goTabs];
Grüße
Christof
  Mit Zitat antworten Zitat