Autor Beitrag
SirDregan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17

WIN 2000, WinXP
D5 Prof
BeitragVerfasst: Di 24.05.05 15:33 
Hallo Leute!

Ich hab ein kleines Problem. Ist schwer zu erklären, ich versuche mal aufzuschreiben was ich machen will:

Ich habe 2 Label und ein StringGrid. Label 1 heisst L_1, hat clRed als Hintergrundfarbe. Label 2 heisst L_2 und hat clLime als Hintergrundfarbe.
Das Stringgrid SG_plan.

Wenn ich jetzt per Drag n Drop ein Label auf das StringGrid ziehe, wird der Name der Labelkomponente in das Feld des StringGrids geschrieben (Feld wird per MousetoCell ermittelt). Beim OnDraw des StringGrids soll jetzt der Text und der Hintergrund die Farbe des Labels annehmen.
Gelöst hab ich das so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
      If SG_plan.Cells[ACol,ARow] <> '' then begin
         with SG_plan do begin
            Canvas.Brush.Color := TLabel(Cells[ACol,ARow]).Color;
            Canvas.FillRect(Rect);
            Canvas.Font.Color := TLabel(Cells[ACol,ARow]).Color;
         end;
      end;


Das scheint auch zu funktionieren, er holt sich den Richtigen Komponentennamen etc. nur leider zieht er sich die Farbe aus dem Nirvana. Statt rot zieht er sich ein dunkles, statt Grün ein helles Lila.
Ich hab mir die Farbe auch schon per ColortoString ausgeben lassen -> ist der Hexwert dieses grässlichen Lila *argh*
Ich hab nun keine Ahnung woher er die Farbe zieht :(
Irgendjemand ne Idee?

Danke schonmal!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 24.05.05 20:08 
Hallo und :welcome:
bau das mal in der Art in deinen Code ein.
ausblenden Delphi-Quelltext
1:
Canvas.Brush.Color := TLabel(Form1.FindComponent(Cells[ACol,ARow])).Color;					

Und Canvas.Font.Color solltest Du auch Font.Color zuweisen. :wink:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
SirDregan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17

WIN 2000, WinXP
D5 Prof
BeitragVerfasst: Mi 25.05.05 08:31 
Ah danke! Das wars!
Heisst das ich muss die Form in der sich die Komponente befindet mit angeben, ansonsten macht er Mist? Weist du wieso das so is?

btw: das mit Font war schon richtig so, ich möchte nicht das man den Text in der Zelle sieht, der ist nur für mich gedacht :)

Vielen Dank!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 25.05.05 09:13 
Hallo,
user profile iconSirDregan hat folgendes geschrieben:
... die Form in der sich die Komponente befindet mit angeben, ansonsten macht er Mist? Weist du wieso das so is?...


Nehme an, das das an with SG_plan do liegt, daraus wird dann SG_plan.FindComponent.
Du musst die FindComponent-Methode mit dem Objekt aufrufen, auf dem die TLabels liegen.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )