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
Seite 1 von 2  1 2      
Jester

Registriert seit: 27. Okt 2002
5 Beiträge
 
#1

StringGrid-Zelle während dem editieren farbig?

  Alt 27. Okt 2002, 14:46
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.
  Mit Zitat antworten Zitat
Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: München
11.412 Beiträge
 
Delphi 11 Alexandria
 
#2
  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].
Daniel W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
Jester

Registriert seit: 27. Okt 2002
5 Beiträge
 
#3
  Alt 27. Okt 2002, 16:10
Es funzt, vielen Danek, total genial!!!
  Mit Zitat antworten Zitat
MisterEd

Registriert seit: 14. Jan 2003
7 Beiträge
 
#4
  Alt 15. Jan 2003, 13:36
hmm k ich glaube ich habe die komponente erfolgreich installiert nur wie benutze ich die jetzt
  Mit Zitat antworten Zitat
lodda

Registriert seit: 6. Dez 2002
65 Beiträge
 
Delphi 5 Standard
 
#5
  Alt 15. Jan 2003, 13:43
Was heißt du "glaubst"
  Mit Zitat antworten Zitat
Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: München
11.412 Beiträge
 
Delphi 11 Alexandria
 
#6
  Alt 15. Jan 2003, 13:54
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).
Daniel W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
Maiky

Registriert seit: 14. Nov 2006
54 Beiträge
 
#7

Re: StringGrid-Zelle während dem editieren farbig?

  Alt 4. Mär 2008, 14:54
@sakura
Super und vielen Dank! Genau das habe ich gesucht. Gibt es eventuell noch die Möglichkeit der Textausrichtung im TInplaceEdit?
  Mit Zitat antworten Zitat
s-off
(Gast)

n/a Beiträge
 
#8

Re: StringGrid-Zelle während dem editieren farbig?

  Alt 4. Mär 2008, 15:56
Zitat von Maiky:
Gibt es eventuell noch die Möglichkeit der Textausrichtung im TInplaceEdit?
Nein,

das machst Du in der DrawCell Methode unter Angabe des Textformates (z.B. DT_CENTER) als Argument an DrawText.
  Mit Zitat antworten Zitat
Maiky

Registriert seit: 14. Nov 2006
54 Beiträge
 
#9

Re: StringGrid-Zelle während dem editieren farbig?

  Alt 4. Mär 2008, 16:00
Das klappt so leider nicht, damit richte ich bereits meinen Text aus und dies hat keine Auswirkung auf die Textausrichtung beim editieren.
  Mit Zitat antworten Zitat
s-off
(Gast)

n/a Beiträge
 
#10

Re: StringGrid-Zelle während dem editieren farbig?

  Alt 4. Mär 2008, 16:47
Ups, da habe ich Dich wohl falsch verstanden.
Dann schau Dir doch einfach mal den InplaceEditor genauer an.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


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 08:04 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