Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Displaying text on a TProgressBar

Posted on 2002-04-23
4
Medium Priority
?
1,603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

609 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