![]() |
onDrawCell überschreibt Caption vom Formular
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:
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... :(
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;
Code:
Grüße
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]; Christof |
AW: onDrawCell überschreibt Caption vom Formular
Passiert das auch, wenn Du das with weglässt und den Rect-Parameter in z.B. ARect umbenennst?
|
AW: onDrawCell überschreibt Caption vom Formular
Zitat:
|
AW: onDrawCell überschreibt Caption vom Formular
Dann versuch es mal ohne with z.B. in dem du eine gecastete loakle Variable verwendest
|
AW: onDrawCell überschreibt Caption vom Formular
Sag ich doch :)
|
AW: onDrawCell überschreibt Caption vom Formular
Zitat:
|
AW: onDrawCell überschreibt Caption vom Formular
Was ist denn Text überhaupt? Fehlt da evtl. eine lokale Variable?
[edit]So sieht das bei mir aus, als sei es so gewollt:
Delphi-Quellcode:
[/edit]
procedure TForm.DrawTerminart(Sender: TObject; ACol, ARow: Integer;
ARect: TRect; State: TGridDrawState); var outRect: TRect; G: TStringGrid; Text: string; //<-- das machen wir mal lieber lokal begin //und das with kommt auch sicherheitshalber weg G := Sender as TStringGrid; if (ACol > 1) And (ARow >= 1) then begin Text := G.Cells[ACol, ARow]; outRect := ARect; G.Canvas.Brush.Color := clWhite; G.Canvas.Fillrect(ARect); G.Canvas.Font.Name := 'Wingdings 2'; G.Canvas.Font.Size := 14; if ACol = 9 then G.Canvas.Font.Color := clGray else G.Canvas.Font.Color := clBlack; outRect.Top := outRect.Top + 2; DrawText(G.Canvas.Handle, PChar(Text), length(Text), outRect, DT_Center or DT_SingleLine); end; end; |
AW: onDrawCell überschreibt Caption vom Formular
Zitat:
Achje, danke fürs mitschauen, also manchmal....:-D |
AW: onDrawCell überschreibt Caption vom Formular
Wenn Du durchsteppst, dann merkst Du, dass <Text> bei
Delphi-Quellcode:
auf die Form zugreift.
Text := G.Cells[ACol, ARow];
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:08 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz