Solved

Displaying text on a TProgressBar

Posted on 2002-04-23
4
1,395 Views
Last Modified: 2008-02-01
Hi,

I would like to know how to display text on a TProgressBar in Delphi 4 Professional.  I was hoping to display some centred text such as "50% (10k of 20k) transferred" on the face of the TProgressBar.  However, there doesn't appear to be a Caption or Text property to specify the text.

I tried to position a label over it and use that to display the text, however the label always appears behind the TProgressBar, so this doesn't seem to work.

Any ideas?

Thanks in Advance,

Richard
0
Comment
Question by:Richard2000
4 Comments
 
LVL 1

Expert Comment

by:Alone
ID: 6963013
Try to set Transparent property of the label to True

WBR...
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6963301
use a TGauge instead... you'll find it on the Samples tab.


Good luck!!
0
 
LVL 2

Expert Comment

by:freshman3k
ID: 6963492
Hello!

Try any of these, they are gradient and it includes a caption property and its free.

Here is the link to downloads(all have what you want):
1)http://www.jazarsoft.com/cgi-bin/download.cgi?id=15
2)http://www.torry.net/vcl/indicat/meters/empggauge.zip
3)http://www.torry.net/vcl/indicat/meters/tprogr.zip
4)http://www.torry.net/vcl/indicat/meters/vlxprogress.zip

Good Luck!

0
 
LVL 8

Accepted Solution

by:
TOndrej earned 50 total points
ID: 6965404
Here's a quick example using TProgressBar:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls;

type
  TForm1 = class(TForm)
    ProgressBar1: TProgressBar;
    TrackBar1: TTrackBar;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
  private
    FProgressBarWndProc: TWndMethod;
    procedure ProgressBar1WndProc(var Message: TMessage);
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ProgressBar1WndProc(var Message: TMessage);
var
  Canvas: TCanvas;
  R: TRect;
  B: TBitmap;
begin
  case Message.Msg of
    WM_PAINT:
      with ProgressBar1 do
      begin
        Canvas := TCanvas.Create;
        try
          Canvas.Handle := GetDC(Handle);
          try
            // erase background
            R := ClientRect;
            Canvas.Brush.Color := Color;
            Canvas.FillRect(R);
            // let the progressbar paint itself
            FProgressBarWndProc(Message);
            // draw text
            B := TBitmap.Create;
            try
              B.Width := R.Right - R.Left;
              B.Height := R.Bottom - R.Top;
              B.Canvas.Brush.Color := clBlack;
              B.Canvas.FillRect(R);
              B.Canvas.Font := Self.Font;
              B.Canvas.Font.Color := clWhite;
              DrawText(B.Canvas.Handle, PChar(Format('%.0f%%',
                [100 * Position / Max])), -1, R, DT_NOCLIP or DT_CENTER);
              BitBlt(Canvas.Handle, 0, 0, B.Width, B.Height, B.Canvas.Handle, 0, 0, SRCINVERT);
            finally
              B.Free;
            end;
          finally
            ReleaseDC(Handle, Canvas.Handle);
          end;
        finally
          Canvas.Free;
        end;
      end;
    else
      FProgressBarWndProc(Message);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FProgressBarWndProc := ProgressBar1.WindowProc;
  ProgressBar1.WindowProc := ProgressBar1WndProc;
  ProgressBar1.Smooth := True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  ProgressBar1.WindowProc := FProgressBarWndProc;
  FProgressBarWndProc := nil;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  with Sender as TTrackBar do
    ProgressBar1.Position := Position;
end;

end.

HTH
TOndrej
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now