Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   StringGrid roter Rahmen (https://www.delphipraxis.net/189081-stringgrid-roter-rahmen.html)

strom 1. Mai 2016 16:57

StringGrid roter Rahmen
 
hallo,
möchte gerne einen roten rahmen im StringGrid haben, also die markierte Zeile soll einen rahmen haben.

Delphi-Quellcode:
  if gdSelected in State then
   StringGrid1.Canvas.Brush.Color := clMenu;
   StringGrid1.Canvas.FillRect( Rect );
   StringGrid1.Canvas.TextRect( Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow] );

   Stringgrid1.Canvas.Pen.Color:=clRed;
   Stringgrid1.Canvas.Rectangle(Rect.Left, Rect.Top, Rect.Right StringGrid1.cells[aCol, aRow]); // was ist hier falsch?

EWeiss 1. Mai 2016 17:12

AW: StringGrid roter Rahmen
 
Fehlt da nicht ein begin\end?

gruss

strom 1. Mai 2016 17:20

AW: StringGrid roter Rahmen
 
hey,

ist nur ein Ausschnitt! :-)

Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
   StringGrid1.Canvas.Font.Color := clblack;

  if StringGrid1.Cells[0, ARow] = '1' then
   begin
    StringGrid1.Canvas.Brush.Color := $004080FF;
   end else
  if StringGrid1.Cells[0, ARow] = '2' then
   begin
    StringGrid1.Canvas.Brush.Color := $004080FF;
   end else
  if StringGrid1.Cells[0, ARow] = '3' then
   begin
    StringGrid1.Canvas.Brush.Color := $004080FF;
   end else
  if StringGrid1.Cells[0, ARow] = '11' then
   begin
    StringGrid1.Canvas.Brush.Color := $004080FF;
   end else
  if StringGrid1.Cells[0, ARow] = '4' then
   begin
    StringGrid1.Canvas.Brush.Color := clYellow;
   end else
  if StringGrid1.Cells[0, ARow] = '5' then
   begin
    StringGrid1.Canvas.Brush.Color := clyellow;
   end else
  if StringGrid1.Cells[0, ARow] = '6' then
   begin
    StringGrid1.Canvas.Brush.Color := clYellow;
   end else
  if StringGrid1.Cells[0, ARow] = '7' then
   begin
    StringGrid1.Canvas.Brush.Color := clYellow;
   end else
  if StringGrid1.Cells[0, ARow] = '8' then
   begin
    StringGrid1.Canvas.Brush.Color := clYellow;
   end else
  if StringGrid1.Cells[0, ARow] = '9' then
   begin
    StringGrid1.Canvas.Brush.Color := clYellow;
   end else
  if StringGrid1.Cells[0, ARow] = '10' then
   begin
    StringGrid1.Canvas.Brush.Color := clYellow;
   end;
  if gdSelected in State then
   StringGrid1.Canvas.Brush.Color := clMenu;
   StringGrid1.Canvas.FillRect( Rect );
   StringGrid1.Canvas.TextRect( Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow] );

   Stringgrid1.Canvas.Pen.Color:=clRed;
   //Stringgrid1.Canvas.Rectangle(Rect.Left, Rect.Top, Rect.Right StringGrid1.cells[aCol, aRow]); // was ist hier falsch?
end;

markus5766h 1. Mai 2016 17:32

AW: StringGrid roter Rahmen
 
Liste der Anhänge anzeigen (Anzahl: 1)
... ich glaube, der Markierungsrahmen wird in der Komplimentärfarbe zum Canvas.Brush gezeichnet :
versuch' mal Folgendes nach dem TextOut :
Delphi-Quellcode:
StringGrid1.Canvas.Brush.Color := clTeal;
if gdFocused in State then StringGrid1.Canvas.DrawFocusRect(Rect);

strom 1. Mai 2016 18:20

AW: StringGrid roter Rahmen
 
Super ! Danke

Blup 2. Mai 2016 08:57

AW: StringGrid roter Rahmen
 
Zitat:

Zitat von strom (Beitrag 1337248)
hey,

ist nur ein Ausschnitt! :-)

Dann ist an dieser Stelle der Quelltext aber falsch eingerückt.
Ich würde auch viel mehr Unterfunktionen verwenden.
Damit bleibt der Quelltext z.B. für spätere Fehlersuche oder Änderungen lesbar.
Delphi-Quellcode:
function TForm1.GetColorForValue(AValue: Integer): TColor;
begin
  case AValue of
    1..3, 11: Result := $004080FF;
    4..10:   Result := clYellow;
  else       Result := clBlack;
  end;
end;

function TForm1.GetColorForCell(AState: TGridDrawState; AValue: Integer): TColor;
begin
  if gdSelected in AState then
    Result := clMenu
  else
    Result := GetColorForValue(AValue, 0);
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with StringGrid1 do
  begin
    {Hintergrund und Text, TextRect füllt auch den Hintergrund}
    Canvas.Brush.Color := GetColorForCell(State, IntToStrDef(Cells[0, ARow], 0));
    Canvas.TextRect(Rect, Rect.Left, Rect.Top, Cells[ACol, ARow]);

    {Markierung}
    if gdFocused in State then
    begin
      Canvas.Brush.Color := clTeal;
      Canvas.DrawFocusRect(Rect);
    end;
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:24 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz