Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Fragen rund ums Stringgrid (https://www.delphipraxis.net/78177-fragen-rund-ums-stringgrid.html)

Noobinator 30. Sep 2006 12:28


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:
Stringgrid1.colcount
bis
Delphi-Quellcode:
Stringgrid1.colcount-8
einen dickeren Rahmen.
Wie geht das?
habe schon die Hilfe, sowie google und MC SuFu befragt, aber nichts gefunden.

marabu 30. Sep 2006 12:33

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

Noobinator 30. Sep 2006 17:37

Re: Im Stringgrid bestimmte Zellen Markieren (Rahmen)
 
Ich habe das mit dem Rahmen jetzt mal gelassen und ein Problem mit der farbe:

Delphi-Quellcode:
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.
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.
woran liegt das?

bild

marabu 30. Sep 2006 18:15

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:
// ...

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.
Getippt und nicht getestet.

Grüße vom marabu

Noobinator 30. Sep 2006 18:30

Re: Im Stringgrid bestimmte Zellen Markieren (Rahmen/farbe)
 
danke hat wunder bar funktioniert. :thumb:

Sharky 1. Okt 2006 13:13

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.

Hier geht es weiter.

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