Autor Beitrag
Constan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 80

Win XP, Suse 10.1
Delphi 7
BeitragVerfasst: Mi 05.07.06 14:25 
Ich weis einiege werden lachen aber ich bekomme das net hin.

Ich möchte gerne, dass wenn ein bestimmter Eintrag in der Listbox ist dieser sich färben tut
jedoch nur dieser alle anderen sollen weiter normal sein oder auch noch geprühft werden.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin  
  with TListBox(Control), Canvas do  
  begin
    if Listbox1.Items = 'hallo' then Font.Color:=clGreen;
    if Listbox1.Items = 'bye' then Font.Color:=clred;
  end;
end;



Beispiel :

ich
du
hallo
ciao
bye
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Mi 05.07.06 14:43 
user profile iconConstan hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin  
  with TListBox(Control), Canvas do  
  begin
    if Listbox1.Items = 'hallo' then Font.Color:=clGreen;
    if Listbox1.Items = 'bye' then Font.Color:=clred;
  end;
end;



bist schon auf dem richtigen Weg:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
{...}
  with TListBox(Control), Canvas do  
  begin
    if Listbox1.Items[Index] = 'hallo' then Font.Color:=clGreen;
    if Listbox1.Items[Index] = 'bye' then Font.Color:=clred;
  end;
end;
Constan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 80

Win XP, Suse 10.1
Delphi 7
BeitragVerfasst: Mi 05.07.06 15:12 
Danke erstmal für deine antwort. jetzt passiert endlich was aber alles irgendwie in weiß oder so
Die Listbox ist gefüllt aber in weiß.

habe das probiert geht auch leider nicht was mache ich noch falsch?

Habe den Style auch auf lbOwnerDrawFixed. :cry:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with TListBox(Control), Canvas do
  begin
    if Listbox1.Items[Index] = 'hallo' then Font.Color:=clGreen
    else Font.Color:=clblack;
    if Listbox1.Items[Index] = 'bye' then Font.Color:=clred
    else Font.Color:=clblack;
  end;
end;
Softchaos67
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 103

XP Prof
Delphi 7
BeitragVerfasst: Mi 05.07.06 15:18 
Ich denke du musst jetzt den Text auch selbst ausgeben:
ausblenden Delphi-Quelltext
1:
     Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top, Items[Index]);					

oder
ausblenden Delphi-Quelltext
1:
   Canvas.TextOut(Rect.left,rect.top,Items[Index]);					


So in der art...

_________________
cum grano salis
Constan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 80

Win XP, Suse 10.1
Delphi 7
BeitragVerfasst: Mi 05.07.06 15:32 
oha das wird bestimmt aufwendig und kompliziert für den zweck das es nur eine erleichterung in der bedienung sein soll
Softchaos67
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 103

XP Prof
Delphi 7
BeitragVerfasst: Mi 05.07.06 15:40 
Das schwierige hast du doch schon erledigt.
Nur noch den Text ausgeben!
Items[Index] ist der Text, Rect.left und rect.top sind auch verfügbar.
Die Lösung steht eigentlich schon da....

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with TListBox(Control), Canvas do
  begin
    if Listbox1.Items[Index] = 'hallo' then Font.Color:=clGreen
    else Font.Color:=clblack;
    if Listbox1.Items[Index] = 'bye' then Font.Color:=clred
    else Font.Color:=clblack;
    TextOut(Rect.left,Rect.top,Items[index]); // Das fehlt noch! 
    
  end;
end;

_________________
cum grano salis


Zuletzt bearbeitet von Softchaos67 am Do 06.07.06 07:04, insgesamt 1-mal bearbeitet
Constan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 80

Win XP, Suse 10.1
Delphi 7
BeitragVerfasst: Mi 05.07.06 16:31 
bei mir kommt immer nur Fehler, dabei ist ein ITEMS doch kein Integer oder?

[Fehler] Unit1.pas(93): Inkompatible Typen: 'Integer' und 'TRect'
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 05.07.06 16:32 
ich denke das komme sollte ein punkt sein
also
Rect.top ;)
Constan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 80

Win XP, Suse 10.1
Delphi 7
BeitragVerfasst: Do 06.07.06 00:38 
danke mit dem Punkt das wars. und danke noch mal an alle anderen die mitgeholfen haben.
Eine Frage hätte ich dann noch wie unterscheidet sich das ganze vom StringGrid.
habe es probiert aber geht net. :roll:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with TStringGrid(Control), Canvas do
  begin
    if StringGrid.Items[Index] = 'klappt' then Font.Color:=clGreen;
   // else Font.Color:=clblack;
    TextOut(Rect.left,Rect.top,Cell[index]);
end;
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Do 06.07.06 06:55 
StringGrid hat keine Items ;) da musst du dann via Cells[ACol, ARow] prüfen ;)
Softchaos67
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 103

XP Prof
Delphi 7
BeitragVerfasst: Do 06.07.06 07:01 
ausblenden Delphi-Quelltext
1:
2:
if StringGrid.Cells[ACol,ARow] = 'klappt' then Font.Color:=clGreen;
TextOut(Rect.left,Rect.top,StringGrid.Cells[ACol,ARow]);


so muss es gehen

_________________
cum grano salis
Constan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 80

Win XP, Suse 10.1
Delphi 7
BeitragVerfasst: Do 06.07.06 11:50 
Stimmt man sollte gucken dann fragen. da ich das net gelernt sondern selber mir versuche beizubringen finde ich das noch in ordnung sone fehler zu machen.

lol jetzt kommt der nächste satz

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with TStringGrid(Control), Canvas do //144
  begin
if TStringGrid.Cells[ACol,ARow] = 'Besetzt' then Brush.Color:=clRed; //146
TextOut(Rect.left,Rect.top,StringGrid1.Cells[ACol,ARow]);
  end;
end;


[Fehler] Unit1.pas(144): Undefinierter Bezeichner: 'Control'
[Fehler] Unit1.pas(146): Methodenbezeichner erwartet

Ich als newbie wüsste nicht was an Control falsch sein sollte "Control" ist für mich nur eine Anweisung das er das Kontrollieren soll was der TStringGrid macht. oder?
Sy-
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177



BeitragVerfasst: Do 06.07.06 12:05 
schau mal in die Procedure
....(Sender: TObject; ACol, ARow: Integer
da ist kein Control

Versuchs mal mit Sender
Softchaos67
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 103

XP Prof
Delphi 7
BeitragVerfasst: Do 06.07.06 12:16 
Zitat:

Ich als newbie wüsste nicht was an Control falsch sein sollte "Control" ist für mich nur eine Anweisung das er das Kontrollieren soll was der TStringGrid macht. oder?

Ganz und gar nicht.
TStringGrid(Control) ist ein Typecast. es wird erzwungen Control, dass von irgendeinem Typ ist, als TStringGrid zu behandeln. Mit kontrollieren hat das gar nichts zu tun.
In deiner Procedur wird aber gar kein Control übergeben.
ausblenden Delphi-Quelltext
1:
2:
3:
   With (Sender as TStringGrid) do begin
      if Cells[ACol,ARow] ='blabla' then Machwas 
   end;

so wirds besser gehen.

_________________
cum grano salis
Constan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 80

Win XP, Suse 10.1
Delphi 7
BeitragVerfasst: Do 06.07.06 13:02 
Danke hat funktioniert, aber ich glaube bevor ich mit meinen mini projekt weiter mache sollte ich nochmal den satzaufbau von Delphi lernen da habe ich glaube am meisten schwierigkeiten, das mit dem verständnis was er wie machen soll eher weniger.

Danke nochmal für die Geduld

EDIT : Hier noch mal für jeden den es interresiert der komplette code

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with (Sender as TStringGrid), Canvas do
  begin
if Cells[ACol,ARow] = 'Besetzt' then Brush.Color:=clRed;
StringGrid1.Canvas.FillRect(Rect);
TextOut(Rect.left,Rect.top,StringGrid1.Cells[ACol,ARow]);
  end;
end;