Help & Manual authoring tool
How to remove the frame (border) of a progress bar?

Progress bar without a frame

Por Vladimir S. <shvetadvipa@mtu-net.ru>

InstallAWARE - MSI without rocket science

Delphi's ProgressBar always have a frame. If you wish to place it on a StatusBar it looks not beautifully. You can do small change in the component and you'll get the new one without a frame.

Look the picture (progress.gif). You can see three ProgressBars. One is a standard Delphi's component with a frame and the rest of them a component with a new property. Now you can drive a ProgressBar's frame.

unit NewProgress;

// By Vladimir S. <shvetadvipa@mtu-net.ru>

interface

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

type
  TNProgressBar = class(TProgressBar)
    procedure WMNCPAINT(var Msg: TMessage); message WM_NCPAINT;
  private
    FShowFrame: boolean;
    procedure SetShowFrame(Value: boolean);
  public
    constructor Create(AOwner: TComponent); override;
  published
    property ShowFrame: boolean read FShowFrame write SetShowFrame;
  end;

procedure Register;

implementation

{ TNProgressBar  }

constructor TNProgressBar.Create(AOwner: TComponent);
begin
  inherited;
  FShowFrame := True;
end;

procedure TNProgressBar.SetShowFrame(Value: boolean);
begin
  if FShowFrame <> Value then begin
    FShowFrame:= Value;
    RecreateWnd;
  end;
end;

procedure TNProgressBar.WMNCPAINT(var Msg: TMessage);
var
  DC: HDC;
  RC: TRect;
begin
  if ShowFrame then begin
    inherited;
    Invalidate;
  end else begin
    DC := GetWindowDC(Handle);
    try
      Windows.GetClientRect(Handle, RC);
      with RC do begin
        Inc(Right, 2);
        Inc(Bottom, 2);
      end;
      Windows.FillRect(DC, RC, Brush.Handle);
    finally
      ReleaseDC(Handle, DC);
    end;
  end;
end;

procedure Register;
begin
  RegisterComponents('Controls', [TNProgressBar]);
end;

end.
JfControls Library - for Delphi and C++ Builder
Copyright © 2000/2006 Ernesto De Spirito.   All rights reserved.