![]() |
Fragen rund ums Stringgrid
Hy community.
Ich baste momentan mal wieder ein bissl mit dem Stringgrid herum und stehe vor einem Problem. Ich möchte von
Delphi-Quellcode:
bis
Stringgrid1.colcount
Delphi-Quellcode:
einen dickeren Rahmen.
Stringgrid1.colcount-8
Wie geht das? habe schon die Hilfe, sowie google und MC SuFu befragt, aber nichts gefunden. |
Re: Im Stringgrid bestimmte Zellen Markieren (Rahmen)
Hi,
dazu musst du einen event handler für das Ereignis OnDrawCell() schreiben. Darin prüfst du, ob und welchen Rahmentyp (Ecke, Gerade, ...) du gerade benötigst. Grüße vom marabu |
Re: Im Stringgrid bestimmte Zellen Markieren (Rahmen)
Ich habe das mit dem Rahmen jetzt mal gelassen und ein Problem mit der farbe:
Delphi-Quellcode:
wenn ich dies jetzt so habe färbt er immer nur ein teil des Stringrids mit der gewünschten farbe, und der rest färbt sich erst, wenn ich mit der maus über die Zelle fahre.
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, Menus; type TForm1 = class(TForm) ... private { Private-Deklarationen } public { Public-Deklarationen } farbe:tcolor; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin farbe:=clyellow; stringgrid1.Ondrawcell:= StringGrid1DrawCell; stringgrid2.Ondrawcell:= StringGrid2DrawCell; end; procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if not Odd(Arow) and not (gdFixed in State) then with StringGrid1 do begin Canvas.Brush.Color := farbe; Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left+2, Rect.Top+2, Cells[Acol, ARow]); end; end; procedure TForm1.StringGrid2DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if not Odd(Arow) and not (gdFixed in State) then with StringGrid2 do begin Canvas.Brush.Color := farbe; Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left+2, Rect.Top+2, Cells[Acol, ARow]); end; end; procedure TForm1.Farbe1Click(Sender: TObject); begin if colordialog1.execute then farbe:=colordialog1.Color; stringgrid1.OnDrawCell:=StringGrid1DrawCell; stringgrid2.OnDrawCell:=StringGrid2DrawCell; end; end. woran liegt das? ![]() |
Re: Im Stringgrid bestimmte Zellen Markieren (Rahmen/farbe)
Die Zuweisung von OnDrawCell() kannst du ruhig im Object Inspector vornehmen - und einmal genügt auch. Außerdem kannst du beiden StringGrids die gleiche Routine zuweisen, wenn du eine kleine Änderung machst. Und das Neuzeichnen könnte so funktionieren:
Delphi-Quellcode:
Getippt und nicht getestet.
// ...
procedure TForm1.FormCreate(Sender: TObject); begin farbe := clYellow; end; procedure TForm1.StringGridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if not Odd(ARow) and not (gdFixed in State) then // so funktioniert der shared event handler with Sender as TStringGrid do begin Canvas.Brush.Color := farbe; Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left+2, Rect.Top+2, Cells[ACol, ARow]); end; end; procedure TForm1.Farbe1Click(Sender: TObject); begin with ColorDialog1 do if Execute then farbe := Color; // Neuzeichnen bei nächster Gelegenheit StringGrid1.Invalidate; StringGrid2.Invalidate; end; end. Grüße vom marabu |
Re: Im Stringgrid bestimmte Zellen Markieren (Rahmen/farbe)
danke hat wunder bar funktioniert. :thumb:
|
Re: Im Stringgrid bestimmte Zellen Markieren (Rahmen/farbe)
Hai,
da die nächste Frage nichts mehr mit dem Ursprünglichen zu tun hatte habe ich daraus einen eigenen Thread gemacht. ![]() Bitte pro Frage einen eigenen Thread aufmachen. Danke :-D |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:10 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