?
Solved

Displaying text on a TProgressBar

Posted on 2002-04-23
4
Medium Priority
?
1,552 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

764 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