AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Gauge OnKlick

Ein Thema von Van HelF · begonnen am 18. Feb 2007 · letzter Beitrag vom 18. Feb 2007
 
Hawkeye219

Registriert seit: 18. Feb 2006
Ort: Stolberg
2.227 Beiträge
 
Delphi 2010 Professional
 
#8

Re: Gauge OnKlick

  Alt 18. Feb 2007, 12:35
Hi,

wäre es nicht einfacher, auf die Gauge-Controls zu verzichten und die ListBox-Einträge selbst zu zeichnen? Dazu mußt du lediglich die Eigenschaft Delphi-Referenz durchsuchenTListBox.Style auf den Wert lbOwnerDrawFixed setzen und einen geeigneten Wert für Delphi-Referenz durchsuchenTListBox.ItemHeight eintragen. Das Zeichnen der Elemente übernimmt eine Behandlungsroutine für das Ereignis Delphi-Referenz durchsuchenTListBox.OnDrawItem.

Delphi-Quellcode:
// Zeichnet eine Fortschrittanzeige
procedure DrawProgress (aCanvas: TCanvas; const aRect: TRect; aPercent: Integer;
  aText: string = '');
var
  tx, ty : Integer;
  R : TRect;
begin
  if (aText <> '') then
    aText := aText + ' ';
  aText := aText + Format('(%d%%)', [aPercent]);
  with aCanvas do
    begin
      tx := (aRect.Left + aRect.Right - TextWidth(aText)) div 2;
      ty := (aRect.Top + aRect.Bottom - TextHeight(aText)) div 2;
      // Hintergrund (linker Teil)
      R := aRect;
      R.Right := aRect.Left + MulDiv(aRect.Right - aRect.Left, aPercent, 100);
      Brush.Color := clNavy;
      FillRect (R);
      // Text (linker Teil)
      Font.Color := clWhite;
      TextRect (R, tx, ty, aText);
      // Hintergrund (rechter Teil)
      R.Left := R.Right;
      R.Right := aRect.Right;
      Brush.Color := RGB(240, 240, 240);
      FillRect (R);
      // Text (rechter Teil)
      Font.Color := clBlack;
      TextRect (R, tx, ty, aText);
    end;
end;

procedure TForm1.FormCreate (Sender: TObject);
begin
  ListBox1.Style := lbOwnerDrawFixed; // kann auch im OI
  ListBox1.ItemHeight := 20; // vorgenommen werden
end;

procedure TForm1.ListBox1DrawItem (Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with ListBox1 do
    begin
      if (odSelected in State) then
        Canvas.Brush.Color := clRed
      else
        Canvas.Brush.Color := clWindow;
      Canvas.FillRect (Rect);
      InflateRect(Rect, -2, -2);
      DrawProgress (Canvas, Rect, Integer(Items.Objects[Index]), Items[Index]);
    end;
end;

// zum Testen:
procedure TForm1.Button1Click (Sender: TObject);
begin
  with ListBox1.Items do
    AddObject(Format('item #%d', [Count + 1]), TObject(Random(100)));
end;
Gruß Hawkeye
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:24 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz