Autor Beitrag
Thunder
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: Mi 21.01.04 14:01 
Moin,

In meinem aktuellem Proggi AutoHG (siehe Freeware Projekte) habe ich eine TListbox und eine Prozedur von irgendeinem, das ich dort Bitmaps einbasteln kann. Die Bitmaps nutze ich, um Trennungsbalken da reinzubringen. Funzt alles.

Hier ma der Code
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
Bitmaps in einer TListbox


{ Create a TImage on your Formular and assign a bitmap } 
{ Create a TListbox on your Formular } 

type 
  TForm1 = class(TForm) 
    ListBox1: TListBox; 
    Image1: TImage; 
    procedure FormCreate(Sender: TObject); 
    procedure ListBox1DrawItem(Control: TWinControl; Index: Integer; 
      Rect: TRect; State: TOwnerDrawState); 
    procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer; 
      var Height: Integer); 
  private 
    {...} 
  public 
    {...} 
  end; 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
  with ListBox1.Items do 
  begin 
    Clear; 
    ListBox1.Style := lbOwnerDrawVariable; 
    AddObject('Bitmap1', Image1.Picture.Bitmap); 
    AddObject('Bitmap2', Image2.Picture.Bitmap); 
    AddObject('Bitmap3', Image3.Picture.Bitmap); 
  end; 
end; 

procedure CenterText(Cnv: TCanvas; Rect: TRect; S: string); 
var  
  X, Y: Integer; 
begin 
  X := (Rect.Right + Rect.Left - Cnv.TextWidth(S)) div 2; 
  Y := (Rect.Bottom + Rect.Top - Cnv.TextHeight(S)) div 2; 
  Cnv.TextOut(X, Y, S); 
end; 

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; 
  Rect: TRect; State: TOwnerDrawState); 
var  
  Bitmap: TBitmap; 
begin 
  with ListBox1 do 
  begin 
    Canvas.FillRect(Rect); 
    if Items.Objects[Index] <> nil then 
    begin 
      Bitmap := Items.Objects[Index] as TBitmap; 
      Canvas.BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, 
        Bitmap.Width, Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width, 
        Bitmap.Height), Bitmap.Canvas.Pixels[0, Bitmap.Height - 1]); 
    end; 
    Rect.Left   := Rect.Left + Bitmap.Width + 4; 
    Rect.Bottom := Rect.Top + Bitmap.Height + 4; 
    CenterText(Canvas, Rect, Items.Strings[Index]); 
  end; 
end; 

procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer; 
  var Height: Integer); 
begin 
  if Index = 0 then Height := Image1.Height + 4; 
end;


So. Es werden ALLE Einträge zentriert! Jetz möchte ich einige Beiträge fettschreiben und einige Beiträge sollen NICHT zentriert sein. Das is aber nich so wichtig. AM WICHTIGSTEN is ne Prozedur um einige Beiträge NICHT ALLE fettzuschreiben.

Wie mach ich das??

Und noch nebenbei:
Wie kann ich verhindern, das ein bestimmter Eintrag z.b. mit ItemIndex 2 nicht angeklickt bzw. dadurch nicht markiert werden kann??? Wäre son optischer Schönheitsfleck, da die Bitmaps nich markiert werden sollen können.

Vielen Dank schonma,
Gruß
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Mi 21.01.04 14:22 
Titel: Re: Manche Einträge in TListbox zentrieren und/oder fett sch
Thunder hat folgendes geschrieben:

So. Es werden ALLE Einträge zentriert! Jetz möchte ich einige Beiträge fettschreiben und einige Beiträge sollen NICHT zentriert sein. Das is aber nich so wichtig. AM WICHTIGSTEN is ne Prozedur um einige Beiträge NICHT ALLE fettzuschreiben.

Wie mach ich das??

programmieren ;) ?
du hast doch schon was, wie du den text ausgibst. fett schreiben kannst du, indem du canvas.fonst.style:=[fsbold] setzt. Welche Items das dann sind, muß du selbst eintscheiden. Du bekommst mit index, das zu zeichnende Item-nr übergeben, eine if-Abfrage kann dann wohl nicht das große Ding sein.

Zitat:

Und noch nebenbei:
Wie kann ich verhindern, das ein bestimmter Eintrag z.b. mit ItemIndex 2 nicht angeklickt bzw. dadurch nicht markiert werden kann???

geht nicht direkt mit listbox. du könntest gugst bei onklick nachguggn, welches Item selektiert ist und dann dort das nächste mögliche, bzw gewünschte Item auswählen

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Thunder Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: Mi 21.01.04 16:52 
den code habe ich ja nich selber geschrieben und hab da bis jetz noch nich so durchgeblickt.

das mit onclick hab ich schon probiert...funzt net so
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 22.01.04 09:10 
Thunder hat folgendes geschrieben:
den code habe ich ja nich selber geschrieben und hab da bis jetz noch nich so durchgeblickt.

wo denn genau nicht? der großteil der Befehle ist in der Onlinehilfe erklärt.
such doch auch mal im Forum nach drawitem für weiter Codebeispiele. ansonsten frag gezielt nach.

Zitat:

das mit onclick hab ich schon probiert...funzt net so

du hast einen Fehler gemacht :roll:
Zitat:

funzt net so

kein code von dir, keine beschreibung was genau nicht geht, kommen fehlermeldungen etc .... wie soll man dir da helfen???

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Thunder Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: Do 22.01.04 14:09 
Entschuldigung Keldorn. hier genau:

Ich war bis jetzt zu faul den Code genau durchzukramen.

Ich habe das so...is nich kopiert...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure OnClick ....
begin
  If Listbox.ItemIndex = 2 then Listbox.ItemIndex := -1;
end;


Aber dann war Eintrag zwei immernoch so gepunktet umrandet und er wqar für kurze Zeit blau markiert. Da soll ja ÜBERHAUPT NIX passieren beim klicken.

hatte dann noch so sachen probiert wie:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
begin
  If Listbox.ItemIndex = 2 then Listbox.ItemIndex := -1;
  Listbox.Enabled := False;
  Listbox.Enabled := True;
end;


Und sowas wie Listbox.Repaint; oder Refresh oder so..

Aber immer das gleiche Ergebnis. Es war kurz blau und dann noch umrandet...
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 22.01.04 14:30 
Zitat:

If Listbox.ItemIndex = 2 then Listbox.ItemIndex := -1;

Der Rahmen, der zurückbleibt, ist der fokus. setze den Fokus auf ein anderes control (in der größten Not ein unsichtbares Panel (panel1.setfocus) )

allerdings so wie du das machst, wäre das nicht benutzerfreundlich. Wenn du mit den cursortasten arbeitest, kannst du nich nicht mehr durch die liste arbeiten. Für mich wäre besser, wenn du den möglichen Eintrag markierst und die Sache noch so gestaltest, das wenn du die cursortasten drückst, immer der mögliche vorige oder nachfolgende eintrag markiert wird.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Thunder Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: Do 22.01.04 21:57 
gute Idee danke.