Solved

Displaying text on a TProgressBar

Posted on 2002-04-23
4
1,410 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

21 Experts available now in Live!

Get 1:1 Help Now