![]() |
Datenbank: Firebird • Version: 2.5 • Zugriff über: FireDac
Alternierende Farben in TDBGrid
Hallo
Ich habe mit Delphi XE7 ein alternierendes DBGrid gebastelt und wollte wissen ob man das noch verbessern kann.
Delphi-Quellcode:
Ach ja fast vergessen
type TDBGrid=Class(Vcl.DBGrids.TDBGrid) procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL; end;
procedure TDBGrid.WMVScroll(var Message: TWMVScroll); begin Self.Invalidate; inherited; end; procedure TForm1.DBGrid1MouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); begin if Sender is TDBGrid then (Sender as TDBGrid).Invalidate; end; procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); const MyRowColors : array[Boolean] of TColor = (clLime, clMoneyGreen); var RowNo : Integer; OddRow : Boolean; begin if Sender is TDBGrid then begin with (Sender as TDBGrid) do begin if (gdSelected in State) then begin // Farbe für die Zelle mit dem Focus // color of the focused row Canvas.Brush.Color := clblue; end else begin // Weil das mit RecCount leider nicht mehr geht // habe ich mir dies einfallen lassen // and it works RowNo := Rect.Top div (Rect.Bottom - Rect.Top); OddRow := Odd(RowNo); Canvas.Brush.Color := MyRowColors[OddRow]; // Font-Farbe immer schwarz // font color always black Canvas.Font.Color := clBlack; Canvas.FillRect(Rect); // Denn Text in der Zelle ausgeben // manualy output the text if Column.Field <> nil then Canvas.TextOut(Rect.Left + 2, Rect.Top + 1, Column.Field.AsString); end; end end; end; Frohe Weihnachten |
AW: Alternierende Farben in TDBGrid
Hallo,
in 2010 hatte ich ein ähnliches Problem . Schau dir mal unter 'ZuGriff auf dyn.Komponente' (von 'wendelin') meine Frage an. Allerdings war die Sache komplizierter, da ich den INHALT eines DBGrid's via Quickreport ausgeben wollte.(hier in alternierenden Farben).Was auch eleganter wäre. Alle Antworten waren nicht OK. Mittlerweile ist diese Sache gelöst. Momentan habe ich wenig Zeit, aber heute nachmittag/oder Abend werde ich den Source-Code mit wichtigen Tip's in DELPHI-Praxis stellen. wendelin |
AW: Alternierende Farben in TDBGrid
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,
Hier mein Source-Code:
Delphi-Quellcode:
Ich weiss allerdings nicht ob sich QuickReport mit Deinem Delphi XE Verträgt!
unit QRNeu;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, QuickRpt, QRCtrls, DBGrids, nuetzlFunctions1, QRExport; type TGridReport = class(TForm) GridRep : TQuickRep; DetailBand1: TQRBand; QRTextFilter1: TQRTextFilter; QRCSVFilter1: TQRCSVFilter; QRHTMLFilter1: TQRHTMLFilter; procedure GridRepPreview(Grid : TDBGrid); procedure DetailBand1BeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean); private { Private declarations } public { Public declarations } end; var GridReport: TGridReport; implementation uses DataMod2, DataMod1; {$R *.dfm} (******************************************************************************) procedure TGridReport.GridRepPreview(Grid : TDBGrid); (******************************************************************************) var i, CurrentLeft, CurrentTop : integer; MySQLString : STRING; begin GridRep.Dataset:=Grid.DataSource.DataSet; if not GridRep.Bands.HasColumnHeader then // NEU GridRep.Bands.HasColumnHeader:=true; if not GridRep.Bands.HasDetail then // wird normalerweise NICHT GridRep.Bands.HasDetail:=true; // benötigt !! if not GridRep.Bands.HasPageFooter then // NEU GridRep.Bands.HasPageFooter := TRUE; MySQLString := DataModule2.IBQ1.Text; // NEU GridRep.Bands.ColumnHeaderBand.Height:= Abs(Grid.TitleFont.Height) + 10; GridRep.Bands.DetailBand.Height := Abs(Grid.Font.Height) + 10; GridRep.Bands.PageFooterBand.Height := Abs(Grid.Font.Height) + 10; CurrentLeft := 12; CurrentTop := 4; // 6 Grid.DataSource.DataSet.DisableControls; // don't flicker !! try for i:=0 to Grid.FieldCount - 1 do begin if (CurrentLeft + Canvas.TextWidth(Grid.Columns[i].Title.Caption)) > (GridRep.Bands.ColumnHeaderBand.Width) then begin CurrentLeft := 12; CurrentTop := CurrentTop + Canvas.TextHeight('A') + 6; GridRep.Bands.ColumnHeaderBand.Height := GridRep.Bands.ColumnHeaderBand.Height + (Canvas.TextHeight('A') + 10); GridRep.Bands.DetailBand.Height := GridRep.Bands.DetailBand.Height + (Canvas.TextHeight('A') + 10); end; {Create Header with QRLabels} with TQRLabel.Create(GridRep.Bands.ColumnHeaderBand) do begin Parent := GridRep.Bands.ColumnHeaderBand; Color := GridRep.Bands.ColumnHeaderBand.Color; Left := CurrentLeft; Top := CurrentTop - 10; // korr. ! Caption := Grid.Columns[i].Title.Caption; Font.Style := [fsBold,fsUnderline]; end; {Create Detail with QRDBText} with TQRDBText.Create(GridRep.Bands.DetailBand) do begin Parent := GridRep.Bands.DetailBand; Color := GridRep.Bands.DetailBand.Color; Transparent := TRUE; // NEU für Farbwechsel des DetailBandes Left := CurrentLeft; Top := CurrentTop; Alignment := taLeftJustify; // NEU / Alt -> Grid.Columns[i].Alignment; AutoSize := FALSE; AutoStretch := FALSE; // korr. ! WordWrap := FALSE; // NEU Width := Grid.Columns[i].Width; Dataset := GridRep.Dataset; DataField := Grid.Fields[i].FieldName; CurrentLeft := CurrentLeft + (Grid.Columns[i].Width) + 15; end; end; {Create SysData / Datum-Zeit} with TQRSysData.Create(GridRep.Bands.PageFooterBand) do begin Parent := GridRep.Bands.PageFooterBand; Color := clWhite; Left := 10; Top := CurrentTop; Alignment := taLeftJustify; Data := qrsDateTime; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Name := 'Arial'; Font.Style := [fsBold]; end; {Create Label / SQL-Statement} with TQRLabel.Create(GridRep.Bands.PageFooterBand) do begin Parent := GridRep.Bands.PageFooterBand; Color := clWhite; Left := 170; Top := CurrentTop; Alignment := taLeftJustify; Caption := MySQLString; // akt. SQLSTRING Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Size := 6; Font.Name := 'Small Fonts'; Font.Style := [fsBold]; // [fsBold,fsUnderline]; end; {Create Label / Seite :} with TQRLabel.Create(GridRep.Bands.PageFooterBand) do begin Parent := GridRep.Bands.PageFooterBand; Color := clWhite; Left := 948; Top := CurrentTop; Alignment := taLeftJustify; Caption := 'SEITE :'; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Name := 'Arial'; Font.Style := [fsBold]; end; {Create SysData / Seitennummer} with TQRSysData.Create(GridRep.Bands.PageFooterBand) do begin Parent := GridRep.Bands.PageFooterBand; Color := clWhite; Left := 1024; Top := CurrentTop; Alignment := taLeftJustify; Data := qrsPageNumber; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Name := 'Arial'; Font.Style := [fsBold]; end; {After all, call the QuickRep preview method} GridRep.Preview; {or PreviewModal if you prefer} finally // After all, FREE it NEU! GridRep.Bands.ColumnHeaderBand.Free; // wichtig sonst eListError GridRep.Bands.DetailBand.DestroyComponents; // SEHR WICHTIG !! GridRep.Bands.PageHeaderBand.Free; // wichtig sonst eListError GridRep.Bands.PageFooterBand.Free; // sonst Darstellungsfehler with Grid.DataSource.DataSet do begin EnableControls; end; end; end; (******************************************************************************) procedure TGridReport.DetailBand1BeforePrint(Sender: TQRCustomBand; (******************************************************************************) var PrintBand: Boolean); begin If GridReport.DetailBand1.Color = clMoneyGreen THEN GridReport.DetailBand1.Color := clWhite ELSE GridReport.DetailBand1.Color := clMoneyGreen; end; end. Wenn nicht schreib mir, ich werde dann versuchen Dein Problem mit dem DB-Grid zu lösen. Frohe Weihnachten Wendelin |
AW: Alternierende Farben in TDBGrid
Danke Wendelin
das schau ich mir mal an. Ich habe gesehen das man das nun auch mit dem Themes machen kann, das ist ja echt cool, nur mit dem Haken das man die Bitmaps, Skins nur kompliziert mit einem externen Grafikprogramm ändern kann. Gibt es da ein Programm um die styles.bmp komfortabel zu ändern. Guten Rutsch Martin Michael |
AW: Alternierende Farben in TDBGrid
Hallo Martin,
mit Themes und Skins kenne ich mich überhaupt nicht aus. Da kann ich Dir also gar nicht helfen. Eine Frage aber: Was hat das mit alternierenden Farben im DB-Grid zu tun ? Ein frohes neues Jahr wünscht Dir Wendelin |
AW: Alternierende Farben in TDBGrid
Zitat:
Also ich finde das Konzept relativ einfach. Verglichen mit dem alten Konzept auf Basis der .msstyles-DLLs ist es m. E. primitiv einfach. Du hat eine große Bitmap und definierst welcher Teil davon jetzt die Buttons, Checkboxen, ... darstellt. Einem Designer musst du auch nur diese kleine Datei mitgeben wenn du nur die Bilder ändern willst. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:30 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