![]() |
StringGrid-Zelle während dem editieren farbig?
Hallo,
ich habe ein Stringgrid, wo die aktuelle Zelle farbig unterlegt ist. Wenn ich jetzt aber in die Zelle was schreiben will, wird sie weiß. Hat jemand eine Idee, wie die Zelle farbig bleibt, während ich sie editiere. Danke schon mal im Vorraus. |
Ohne weiteres gar nicht. :evil:
Der Editor wird durch die (versteckte) Komponente TInplaceEditor dargestellt. An diese kannst Du nur herankommen, indem Du eine neue Komponente (sowohl vom Grid, als auch vom InplaceEditor) erstellst. Anschließend kannst Du auf die verschiedenen Eigenschaften zugreifen. Folgender Quellcode ist eine Unit, welche je eine neue Komponente für das StringGrid und für das DrawGrid erstellen. Diese haben je zwei neue Eigenschaften (EditorColor, EditorFontColor). Diese kannst Du nutzen, um Deine Wünsche zu erfüllen. Unit unter dem Namen ExtStringGrid.pas speichern und über das Menü Komponenten installieren. (Mehr dazu im Tutorial ![]()
Code:
[color=#000080][i]{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * Unit Name : ExtStringGrid * Autor : Daniel Wischnewski * Copyright : Copyright © 2001, 2002 by gate(n)etwork. All Rights Reserved. * Urheber : Daniel Wischnewski * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}[/i][/color] [b]unit[/b] ExtStringGrid; [b]interface[/b] [b]uses[/b] Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids; [b]type[/b] TExtInplaceEdit = [b]class[/b](TInplaceEdit) [b]private[/b] [b]protected[/b] [b]public[/b] [b]published[/b] [b]end[/b]; TExtStringGrid = [b]class[/b](TStringGrid) [b]private[/b] FEditorColor: TColor; FEditorFontColor: TColor; [b]procedure[/b] SetEditorColor([b]const[/b] Value: TColor); [b]procedure[/b] SetEditorFontColor([b]const[/b] Value: TColor); [b]procedure[/b] UpdateEditor(aEditor: TInplaceEdit); [b]protected[/b] [b]function[/b] CreateEditor: TInplaceEdit; [b]override[/b]; [b]public[/b] [b]constructor[/b] Create(AOwner: TComponent); [b]override[/b]; [b]published[/b] [b]property[/b] EditorColor: TColor [b]read[/b] FEditorColor [b]write[/b] SetEditorColor [b]default[/b] clWindow; [b]property[/b] EditorFontColor: TColor [b]read[/b] FEditorFontColor [b]write[/b] SetEditorFontColor [b]default[/b] clWindowText; [b]end[/b]; TExtDrawGrid = [b]class[/b](TDrawGrid) [b]private[/b] FEditorColor: TColor; FEditorFontColor: TColor; [b]procedure[/b] SetEditorColor([b]const[/b] Value: TColor); [b]procedure[/b] SetEditorFontColor([b]const[/b] Value: TColor); [b]procedure[/b] UpdateEditor(aEditor: TInplaceEdit); [b]protected[/b] [b]function[/b] CreateEditor: TInplaceEdit; [b]override[/b]; [b]public[/b] [b]constructor[/b] Create(AOwner: TComponent); [b]override[/b]; [b]published[/b] [b]property[/b] EditorColor: TColor [b]read[/b] FEditorColor [b]write[/b] SetEditorColor [b]default[/b] clWindow; [b]property[/b] EditorFontColor: TColor [b]read[/b] FEditorFontColor [b]write[/b] SetEditorFontColor [b]default[/b] clWindowText; [b]end[/b]; [b]procedure[/b] [b]Register[/b]; [b]implementation[/b] [b]procedure[/b] [b]Register[/b]; [b]begin[/b] RegisterComponents([color=#000080]'gate(n)etwork'[/color], [TExtStringGrid, TExtDrawGrid]); [b]end[/b]; [color=#000080][i]{ TExtStringGrid }[/i][/color] [b]constructor[/b] TExtStringGrid.Create(AOwner: TComponent); [b]begin[/b] [b]inherited[/b]; FEditorColor := clWindow; FEditorFontColor := clWindowText; [b]end[/b]; [b]function[/b] TExtStringGrid.CreateEditor: TInplaceEdit; [b]begin[/b] [color=#000080][i]// inherited;[/i][/color] Result := TExtInplaceEdit.Create(Self); UpdateEditor(Result); [b]end[/b]; [b]procedure[/b] TExtStringGrid.SetEditorColor([b]const[/b] Value: TColor); [b]begin[/b] FEditorColor := Value; UpdateEditor(InplaceEditor); [b]end[/b]; [b]procedure[/b] TExtStringGrid.SetEditorFontColor([b]const[/b] Value: TColor); [b]begin[/b] FEditorFontColor := Value; UpdateEditor(InplaceEditor); [b]end[/b]; [b]procedure[/b] TExtStringGrid.UpdateEditor(aEditor: TInplaceEdit); [b]begin[/b] [b]if[/b] aEditor <> [b]nil[/b] [b]then[/b] [b]if[/b] aEditor [b]is[/b] TExtInplaceEdit [b]then[/b] [b]with[/b] TExtInplaceEdit(aEditor) [b]do[/b] [b]begin[/b] Color := FEditorColor; Font.Color := FEditorFontColor; [b]end[/b]; [b]end[/b]; [color=#000080][i]{ TExtDrawGrid }[/i][/color] [b]constructor[/b] TExtDrawGrid.Create(AOwner: TComponent); [b]begin[/b] [b]inherited[/b]; FEditorColor := clWindow; FEditorFontColor := clWindowText; [b]end[/b]; [b]function[/b] TExtDrawGrid.CreateEditor: TInplaceEdit; [b]begin[/b] [color=#000080][i]// inherited;[/i][/color] Result := TExtInplaceEdit.Create(Self); UpdateEditor(Result); [b]end[/b]; [b]procedure[/b] TExtDrawGrid.SetEditorColor([b]const[/b] Value: TColor); [b]begin[/b] FEditorColor := Value; UpdateEditor(InplaceEditor); [b]end[/b]; [b]procedure[/b] TExtDrawGrid.SetEditorFontColor([b]const[/b] Value: TColor); [b]begin[/b] FEditorFontColor := Value; UpdateEditor(InplaceEditor); [b]end[/b]; [b]procedure[/b] TExtDrawGrid.UpdateEditor(aEditor: TInplaceEdit); [b]begin[/b] [b]if[/b] aEditor <> [b]nil[/b] [b]then[/b] [b]if[/b] aEditor [b]is[/b] TExtInplaceEdit [b]then[/b] [b]with[/b] TExtInplaceEdit(aEditor) [b]do[/b] [b]begin[/b] Color := FEditorColor; Font.Color := FEditorFontColor; [b]end[/b]; [b]end[/b]; [b]end[/b]. |
Es funzt, vielen Danek, total genial!!!
|
hmm k ich glaube ich habe die komponente erfolgreich installiert nur wie benutze ich die jetzt :?:
|
Was heißt du "glaubst" :?:
|
Wenn die Installation geklappt hat, dann siehst Du in Deiner Komponentenpalette einen neuen Reiter gate(n)etwork. Dort siehst Du die beiden Komponenten. Diese kannst Du jetzt wie ein normales Stringgrid bzw. Drawgrid nutzen. Du hast lediglich zwei zusätzliche Eigenschaften für den Editor (Farbe und Schrift).
|
Re: StringGrid-Zelle während dem editieren farbig?
@sakura
Super und vielen Dank! Genau das habe ich gesucht. Gibt es eventuell noch die Möglichkeit der Textausrichtung im TInplaceEdit? |
Re: StringGrid-Zelle während dem editieren farbig?
Zitat:
das machst Du in der DrawCell Methode unter Angabe des Textformates (z.B. DT_CENTER) als Argument an DrawText. |
Re: StringGrid-Zelle während dem editieren farbig?
Das klappt so leider nicht, damit richte ich bereits meinen Text aus und dies hat keine Auswirkung auf die Textausrichtung beim editieren.
|
Re: StringGrid-Zelle während dem editieren farbig?
Ups, da habe ich Dich wohl falsch verstanden.
Dann schau Dir doch einfach mal den InplaceEditor genauer an. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:52 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 by Thomas Breitkreuz