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



BeitragVerfasst: Mo 18.02.08 15:02 
Hallo Leute,
wir haben ein BibliotheksPorgramm entworfen, bei dem Delphi das Rückgabedatum berechnet, dieses beim Starten mit dem heutigen vergleicht und dann die Message ausgibt, "Ausleihedatum überschritten". Nun wollen wir noch, dass die überschrittenen Daten, die in der ListBox stehen, rot markiert werden. Habt ihr eine Idee, wie das geht?


Moderiert von user profile iconjasocul: Topic aus Sonstiges (Delphi) verschoben am Mo 18.02.2008 um 15:35
Xong
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

WIN 2000
Borland Developer Studio 2006
BeitragVerfasst: Mo 18.02.08 15:21 
Dein Problem ist zu allgemein!
Wo hakt es denn?
Wenn du weißt, welche Einträge einem überschrittenem Ausleihdatum zugeordnet sind, dann gib denen doch einen roten Hintergrund.
Alpha_Wolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Mo 18.02.08 16:19 
@Xong Aber coocky weiss ja nicht wie und darum gehts hier ;)

Ich habe bisher nur die Schrift in ihrer Farbe verändert..:

Im OnCreate oder im Objektinstpektor setzen
ausblenden Delphi-Quelltext
1:
  ListBox1.Style := lbOwnerDrawFixed;					


Im OnDrawItem deiner Listbox folgendes einsetzen
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 Control as TListBox do begin
    Canvas.FillRect(Rect);
    Canvas.Font.Color := TColor(Items.Objects[Index]);
    Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
  end;
end;


Und dann natürlich noch Items hinzufügen mit der gewünschten Farbe
ausblenden Delphi-Quelltext
1:
2:
  ListBox1.Items.AddObject('Roter Eintrag', Pointer(clRed));
  ListBox1.Items.AddObject('Grüner Eintrag', Pointer(clGreen));


Vielleicht hilft ja das auch weiter ;)

_________________
Diskutiere nie mit einem Irren - er zieht dich auf sein Niveau und schlägt dich mit seiner Erfahrung.
Xong
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

WIN 2000
Borland Developer Studio 2006
BeitragVerfasst: Mo 18.02.08 16:24 
user profile iconAlpha_Wolf hat folgendes geschrieben:
@Xong Aber coocky weiss ja nicht wie und darum gehts hier ;)

Kann sein, kann nicht sein! =)
Ich glaube eher, er weiß nicht, wie er entscheidet, ob das jeweilige Item einen roten Hintergrund bekommt oder nicht.

Und da frag ich doch lieber nochmal nach, als Unmengen von Code zu posten. ^^
coocky Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Mo 18.02.08 18:54 
Also Alpha_Wolf hat das Problem schon richtig verstanden ^^
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 21.02.08 17:36 
Kann man das auch irgendwie machen, wenn das Item schon drin ist? (Wie oben beschrieben geht es ja nur beim Hinzufügen)
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Do 21.02.08 18:03 
Du kannst mit

ausblenden Delphi-Quelltext
1:
ListView1.Selected.Data = Pointer(Farbe);					

das gleiche machen. Prüfe aber auf jeden Fall vorher, ob Selected nicht nil ist.

Edit: Sorry, ich hab gedacht, du verwendest TListView. user profile iconNarses hat die entsprechende Lösung für eine ListBox gepostet.


Zuletzt bearbeitet von Yogu am Do 21.02.08 18:06, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 21.02.08 18:04 
Moin!

user profile iconHendi48 hat folgendes geschrieben:
Kann man das auch irgendwie machen, wenn das Item schon drin ist? (Wie oben beschrieben geht es ja nur beim Hinzufügen)
Klar, einfach das zugehörige .Objects[] mit dem Farbwert beschreiben. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Popov
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1655
Erhaltene Danke: 13

WinXP Prof.
Bei Kleinigkeiten D3Pro, bei größeren Sachen D6Pro oder D7
BeitragVerfasst: Do 21.02.08 18:08 
user profile iconcoocky hat folgendes geschrieben:
Hallo Leute,
wir haben ein BibliotheksPorgramm entworfen, bei dem Delphi das Rückgabedatum berechnet, dieses beim Starten mit dem heutigen vergleicht und dann die Message ausgibt, "Ausleihedatum überschritten". Nun wollen wir noch, dass die überschrittenen Daten, die in der ListBox stehen, rot markiert werden. Habt ihr eine Idee, wie das geht?


Moderiert von user profile iconjasocul: Topic aus Sonstiges (Delphi) verschoben am Mo 18.02.2008 um 15:35


Guck dir das an. Eigentlich wird in meinem Beitrag alles wichtige behandelt. Wie der Beitrag von Mathias vor meinen kam weiß ich nicht, aber die Beiträge haben nichts zusammen zu tun:

www.delphi-library.d....php?p=128875#128875

_________________
Popov
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 21.02.08 19:44 
Hm, irgendwas passt da noch nicht. Wenn ich direkt clRed zuweise wird es rot, aber wenn ich Canvas.Brush.Color := TColor(Items.Objects[Index]); mache und die Farbe so zuweise: LinkBox.Items.Objects[i] := Pointer(clRed);
Dann wird es schwarz statt rot...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 21.02.08 22:04 
Moin!

user profile iconHendi48 hat folgendes geschrieben:
Wenn ich direkt clRed zuweise wird es rot, aber wenn ich Canvas.Brush.Color := TColor(Items.Objects[Index]); mache und die Farbe so zuweise: LinkBox.Items.Objects[i] := Pointer(clRed); Dann wird es schwarz statt rot...
:gruebel: Was auch immer du da tust... :nixweiss:

Das hier geht, grade getestet: ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  with Control as TListBox do begin
    Canvas.Brush.Color := TColor(Items.Objects[Index]);
    Canvas.FillRect(Rect);
    Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Items.AddObject('Roter Eintrag', Pointer(clRed));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ListBox1.Items.AddObject('Grüner Eintrag', Pointer(clLime));
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Sa 23.02.08 11:02 
Ja, bei mir auch. Nur ich will die Farbe ja verändern wenn das Item schon drin ist und nicht beim Hinzufügen.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 23.02.08 16:35 
Moin!

user profile iconHendi48 hat folgendes geschrieben:
Ja, bei mir auch.
Gut, das klappt also. ;)

user profile iconHendi48 hat folgendes geschrieben:
Nur ich will die Farbe ja verändern wenn das Item schon drin ist und nicht beim Hinzufügen.
Aber wo soll denn da das Problem sein? :gruebel: Farbe in das zugehörige .Objects[] und die Kompo neu zeichnen, fertig. :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Sa 23.02.08 17:10 
Dann mach mal bitte ein Beispiel wie man es macht wenn man das bei einem existierenden Item machen will, ich versteh nicht was du jetzt genau meinst. Ich hatte es ja so probiert LinkBox.Items.Objects[i] := Pointer(clRed); Nur dann wird es Schwarz statt rot.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 23.02.08 17:57 
Moin!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  ListBox1.Items.AddObject('Roter Eintrag', Pointer(clRed)); 
end; 

procedure TForm1.Button2Click(Sender: TObject);
begin
  ListBox1.Items.Objects[ListBox1.ItemIndex] := Pointer(clLime);
  ListBox1.Items.Strings[ListBox1.ItemIndex] := 'Grüner Eintrag';
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Sa 23.02.08 20:00 
Ok, jetzt gehts, nur am Anfang ist das Item schwarz, und wenn ich ihm weiß zuweise und es markiere is kein Text mehr da (wird vom weiß überdeckt). Was ist denn die Standard-Farbe?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 23.02.08 23:39 
Moin!

Du musst in der DrawItem-Methode halt auch die Auswahl-Stati unterscheiden. Schau mal hier ein bischen nach Code im Forum, gibt´s sicher auch schon irgendwo ne Vorlage. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.