AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi StringGrid-Zelle während dem editieren farbig?
Thema durchsuchen
Ansicht
Themen-Optionen

StringGrid-Zelle während dem editieren farbig?

Ein Thema von Jester · begonnen am 27. Okt 2002 · letzter Beitrag vom 5. Mär 2008
Antwort Antwort
Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: Unterhaching
11.420 Beiträge
 
Delphi 12 Athens
 
#1
  Alt 27. Okt 2002, 15:50
Ohne weiteres gar nicht.

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 Erstellung von Komponenten)

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].
Lizbeth W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:38 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