Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi tStringgrid und Zeilenfärben --> Verzweiflung (https://www.delphipraxis.net/98830-tstringgrid-und-zeilenfaerben-verzweiflung.html)

GreenHorn3600 2. Sep 2007 12:05


tStringgrid und Zeilenfärben --> Verzweiflung
 
Hallo zusammen,

ich hab 'n stringgrid und eine routine (hier aus dem forum) um die zeilen zu färben, aber der macht einfach nix... :gruebel: habt ihr eine ahnung an was es liegen könnt?

Zitat:

object Form1: TForm1
Left = 0
Top = 0
AlphaBlend = True
Caption = 'Form1'
ClientHeight = 216
ClientWidth = 426
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object sg: TStringGrid
Left = 0
Top = 0
Width = 426
Height = 216
Align = alClient
ColCount = 32
DefaultColWidth = 19
DefaultRowHeight = 16
TabOrder = 0
OnDrawCell = sgDrawCell
ColWidths = (
19
20
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19)
end
end
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  TForm1 = class(TForm)
    sg: TStringGrid;
    procedure sgDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.sgDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
 inherited;
 if not Odd(ARow) then
 begin
  Canvas.Brush.Color := clWebMintcream;
  Canvas.FillRect(Rect);
  Canvas.TextOut(Rect.Left+2, Rect.Top+2, (sender as tstringgrid).Cells[ACol, ARow]);
 end;
end;
bin für jede Hilfe dankbar.

DeddyH 2. Sep 2007 12:15

Re: tStringgrid und Zeilenfärben --> Verzweiflung
 
Überleg Dir mal, auf wessen Canvas Du zeichnest ;)
Delphi-Quellcode:
procedure TForm1.sgDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  inherited;
  if not Odd(ARow) then
    begin
      sg.Canvas.Brush.Color := clRed; //clWebMintCream kennt mein Delphi nicht
      sg.Canvas.FillRect(Rect);
      sg.Canvas.TextOut(Rect.Left+2, Rect.Top+2, (sender as tstringgrid).Cells[ACol, ARow]);
    end;
end;

GreenHorn3600 2. Sep 2007 13:03

Re: tStringgrid und Zeilenfärben --> Verzweiflung
 
hallo deddyh,

danke für die antwort, aber vielleicht hätte ich noch mit dazusagen sollen, dass acol und arow immer den gleichen wert, nämlich 0, haben. keine ahnung warum...

dank und gruss
und noch 'n schönen sonntag

Bernhard Geyer 2. Sep 2007 13:06

Re: tStringgrid und Zeilenfärben --> Verzweiflung
 
Zitat:

Zitat von GreenHorn3600
danke für die antwort, aber vielleicht hätte ich noch mit dazusagen sollen, dass acol und arow immer den gleichen wert, nämlich 0, haben. keine ahnung warum...

Eine Owner-draw-Funktion im Debugger zu untersuchen ist sehr problematisch das du ja immer dafür sorgst das die IDE wieder dein Fenster verdeckt und alles von anfang wieder durchgeführt werden muss.

Also entweder 2ten Monitor zulegen, Programm in VM ausführen oder dafür sorgen das IDE-Fenster dein Grid nicht verdecken.

GreenHorn3600 2. Sep 2007 13:06

Re: tStringgrid und Zeilenfärben --> Verzweiflung
 
ups, danke, war wohl etwas zu voreilig. das war es :-) :cheers: :cheers:

Delphi-Quellcode:
procedure TForm1.sgDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
 inherited;
 with (sender as tStringGrid) do
  if Odd(ARow) then
  begin
   Canvas.Brush.Color := clWebMintcream;
   Canvas.FillRect(Rect);
   Canvas.TextOut(Rect.Left+2, Rect.Top+2, (sender as tstringgrid).Cells[ACol, ARow]);
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:09 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