Autor Beitrag
DiamondDog
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Sa 11.10.08 09:52 
Hallo Leute,
ich hab da folgendes:
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:
procedure TfrmMain.FormCreate(Sender: TObject);
var z,x : Integer;
    bmp : TBitMap;
    bmp1 : TBitMap;
begin
  PageControl1.ActivePage:=TabSheet1;
  ComboBox2.Style := csOwnerDrawVariable;
  bmp := TBitMap.Create;
  bmp1 := TBitMap.Create;
  try
  bmp.LoadFromFile(ExtractFilePath(ParamStr(0))+'Plugins\ProzessXStat\XStatPics\xstatuses_alpha.bmp');
  x := bmp.Height;
  bmp1.Height := x;
  bmp1.Width := x;
  bmp1.Canvas.Font.Style:= [fsBold];
  bmp1.Canvas.Font.Size:= 9;
  bmp1.Canvas.TextOut(4,0,'x');
  for z := 0 to (bmp.Width div x) do
  ComboBox2.Items.Add('');
  ImageList1.AddMasked(bmp1,clNone);
  ImageList1.AddMasked(bmp,clNone);
  finally
   bmp.Free;
   bmp1.Free;
  end;
end;

{***********************************************************}
procedure TfrmMain.ComboBox2DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  ComboBox2.Canvas.Brush.Color := clWindow;
  ComboBox2.Canvas.FillRect(Rect);
  ImageList1.Draw(ComboBox2.Canvas, Rect.Left+2, Rect.Top+2, Index);
end;
Jetzt hätte ich es aber gerne so das vor jedem Bild, noch der Itemindex angezeigt wird.
Beispiel:
0 = Bild0
1 = Bild1
2 = Bild2
usw.
Kann mir jemand sagen, wie ich das hinbekomme?

Danke schone mal.

Mfg Dog


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Sa 11.10.2008 um 20:13
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 11.10.08 10:09 
Wo soll das angezeigt werden? In der ComboBox? Da du als Style csOwnerDrawVariable angegeben hast musst du ja deinen Zeichencode nur entsprechend erweitern.

ComboBox2.Canvas.TextOut sollte das sein was du suchst.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Sa 11.10.08 10:58 
Habs jetzt so gemacht:
ausblenden 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:
  PageControl1.ActivePage:=TabSheet1;
  {*** X-Status}
  ComboBox2.Style := csOwnerDrawVariable;
  bmp := TBitMap.Create;
  bmp1 := TBitMap.Create;
  try
  bmp.LoadFromFile(ExtractFilePath(ParamStr(0))+'Plugins\ProzessXStat\XStatPics\xstatuses_alpha.bmp');
  x := bmp.Height;
  //in diesem Fall muss die Größe gesetzt werden,
  bmp1.Height := x;
  bmp1.Width := x;
  bmp1.Canvas.Font.Style:= [fsBold];
  bmp1.Canvas.Font.Size:= 9;
  bmp1.Canvas.TextOut(4,0,'x');
  bmp.Canvas.TextOut(0,0,'1='); // <<Eingefügt
  for z := 0 to (bmp.Width div x) do
  ComboBox2.Items.Add('');
  ImageList1.AddMasked(bmp1,clNone);
  ImageList1.AddMasked(bmp,clNone);
  finally
   bmp.Free;
   bmp1.Free;
  end;
hier ist aber das Problem das der Text, auf das Bild gestzt wird und nicht da vor.
Ach ja und es fehlt natürlich das Itemindex +1, damit er das bei jedem Bild macht.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 11.10.08 11:04 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
In der ComboBox? Da du als Style csOwnerDrawVariable angegeben hast musst du ja deinen Zeichencode nur entsprechend erweitern.
Die Anzeige erzeugst du doch für jeden Eintrag in ComboBox2DrawItem, und da musst du natürlich auch Änderungen in er Anzeige unterbringen...
In diesem Fall dann das Bild etwas weiter rechts zeichnen, davor den ImageIndex ausgeben und danach den Text.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Sa 11.10.08 11:37 
Oh man... ich versteh nur noch Bahnhof,
kannst mir vll mal die entsprechneden Stellen makieren die du meinst?
Hab hab das was du mir sagen willst zwar verstanden, aber weiß es nicht ganz umzusetzen.

Bin noch nicht so Delphi fitt
und versteh das ganze deswegn noch nicht so gut.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 11.10.08 11:43 
user profile iconDiamondDog hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TfrmMain.ComboBox2DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  ComboBox2.Canvas.Brush.Color := clWindow;
  ComboBox2.Canvas.FillRect(Rect);
  ImageList1.Draw(ComboBox2.Canvas, Rect.Left+2, Rect.Top+2, Index);
end;
Was machst du denn mit diesem Quelltext? Wenn du nicht weißt, was dein Quelltext macht, dann frag was du nicht verstehst und kopier nicht einfach von irgendwo. :roll:
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Sa 11.10.08 11:55 
Also was ich davon weiß ist:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TfrmMain.ComboBox2DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  ComboBox2.Canvas.Brush.Color := clWindow; //Hintergrundfarbe
  ComboBox2.Canvas.FillRect(Rect);
  ImageList1.Draw(ComboBox2.Canvas, Rect.Left+2, Rect.Top+2, Index); // Fürs Bild, von Links, von Rechts, und welchen Index es hat(glaube ich)
end;
Und wofür FillRect ist weiß ich nicht.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 11.10.08 12:04 
Aber dir ist klar, dass du an der Stelle den mit Index angegebenen Eintrag zeichnest? Dann müsstest du ja auch wissen, dass du dort auch die zusätzlichen Zeichenoperationen ausführen musst.
user profile iconDiamondDog hat folgendes geschrieben Zum zitierten Posting springen:
Und wofür FillRect ist weiß ich nicht.
Dann schau in die Hilfe, was FillRect und ImageList1.Draw macht musst du wissen, und dann musst du das in Verbindung mit TextOut entsprechend verändern (also die Position des gezeichneten Bildes nach rechts verschieben, Index davor zeichnen, Text dahinter zeichnen).
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Sa 11.10.08 12:27 
Ok hab mal in die Hilfe angesehn und da steht:
FillRect: Diese Methode füllt das in Rect definierte Rechteck mit der aktuellen Pinselfarbe.
Also das schein wohl unwichtig für meinen Zweck zu sein.

Draw: Diese Methode zeichnet die in Graphic angegebene Grafik an der Postion (X,Y) auf der Druckerzeichenfläche.
Also mit draw wird das Bild in die Combobox eingefügt.

Das heist ich müste da vor noch:
ComboBox2.Canvas.TextOut
einfügen damit es dann per draw mit in die Box kommt.

Also so ist es schon fast richtig:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TfrmMain.ComboBox2DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  ComboBox2.Canvas.Brush.Color := clWindow;
  ComboBox2.Canvas.FillRect(Rect);
  ComboBox2.Canvas.TextOut(Rect.Left+0,Rect.Top+0,inttostr(Index)+' =');
  ImageList1.Draw(ComboBox2.Canvas, Rect.Left+25, Rect.Top+2, Index);
end;
Mir ist noch aufgefallen sobald ich in der Combo rauf und runter gehe,
verschwindet der Text an der Stelle die Gerade makiert ist.
Kann man das irgend wie ändern das er nicht verschwindet?

Edit:
Weiß war nicht ob es so 100% richtig ist, aber hab den Eintrag jetzt gelöscht:
ausblenden Delphi-Quelltext
1:
ComboBox2.Canvas.Brush.Color := clWindow;					
und so gehst es auf jeden fall.
Ich weiß auch das es da drann liegt das man weiße Schrift auf weißem Grund nit lesen kann.