berikut contoh komponen progress bar.
unit ProBar; { - Created by Hasan - } { - 11-08-1998 - } {$R-,T-,H+,X+} interface uses Windows, Messages, SysUtils, Controls, Classes, Graphics, Forms; TProgress = Class(TCustomControl) private FStep: Real; FBarMax, FBarPos: Integer; FBarColor: TColor; FStepIt: Boolean; procedure SetBarMax(Value: Integer); procedure SetBarPos(Value: Integer); procedure SetBarColor(Value: TColor); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure StepIt; procedure Paint; override; procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND; published property Color; property Font; property BarColor: TColor read FBarColor write SetBarColor; property BarMax: Integer read FBarMax write SetBarMax; property BarPos: Integer read FBarPos write SetBarPos; end; procedure Register; implementation procedure Register; begin RegisterComponents('Hasan', [TProgress] ); end; ( -------------- TProgress ------------- ) ( -------------------------------------- ) constructor TProgress.Create(AOwner: TComponent); begin inherited Create( AOwner ); ParentFont := False; ParentColor := False; BevelInner := bvLowered; BevelKind := bkTile; FBarColor := clBlue; FBarMax := 100; FBarPos := 0; FStepIt := False; end; destructor TProgress.Destroy; begin inherited Destroy; end; procedure TProgress.WMEraseBkgnd(var Message: TWmEraseBkgnd); var R: TRect; begin if Canvas<>nil then begin R := ClientRect; if FStepIt then begin R.Left := (R.Right div 2) + 20; R.Right := round(FBarPos FStep); if (R.Right <= R.Left) then begin R.Left := R.Left - 40; R.Right := R.Left + 40; Canvas.Brush.Color := Color; Canvas.FillRect( R ); end; end else begin Canvas.Brush.Color := Color; Canvas.FillRect( R ); if (csDesigning in ComponentState) then Paint; end; end; Message.Result := 1; end; procedure TProgress.SetBarColor(Value: TColor); begin if FBarColor <> Value then begin FBarColor := Value; Invalidate; end; end; procedure TProgress.SetBarMax(Value: Integer); begin if FBarMax <> Value then begin if (Value>0) then begin FBarMax := Value; if FBarPos > FBarMax then FBarPos := FBarMax; Invalidate; end; end; end; procedure TProgress.SetBarPos(Value: Integer); begin if FBarPos <> Value then begin if (Value>=0) and (Value<=FBarMax) then begin FStepIt := False; FBarPos := Value; Refresh; end; end; end; procedure TProgress.StepIt; begin if FBarPos < FBarMax then begin FStepIt := True; inc(FBarPos); Refresh; end; end; procedure TProgress.Paint; var R: TRect; cPersen: String; begin FStep := (ClientWidth / FBarMax); R := ClientRect; R.Left := 0; R.Right := round(FBarPos FStep); Canvas.Brush.Color := FBarColor; Canvas.FillRect( R ); R.Left := 1; R.Right := ClientWidth-1; Canvas.Font := Font; Canvas.Brush.Style := bsClear; cPersen := IntToStr( round((FBarPos * 100) / FBarMax) ) + '%'; R.Top := ((R.Bottom - Canvas.TextHeight(cPersen)) div 2); R.Bottom := R.Top + Canvas.TextHeight( cPersen ); DrawText( Canvas.Handle, pChar(cPersen), -1, R, DT_CENTER ); end; end.
[ red: penulis hanya menuliskan kode program saja, tanpa memberikan intro]
Random Articles
- Check MySQL Service on Our PC
- Menutup Aplikasi Lain
- Tip compile di Lazarus ke target CPU 64 Bit (Mac Only)
- Contoh Unit Untuk Block Keyboard Keys,.,.,.,.
- Lazarus Release 2.0.10
- POC: Smarter Lazarus/FreePascal with OpenAI and FastPlaz
- Membuat random angka tanpa ada data kembar
- Komponen --> Progress Bar
- ADO QUERY
- Mengganti ekstensi namafile otomatis di dialog FileSaveAs
Last Articles
Recent Topic
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #5: UX: Research, Design and Engineer
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #4: Obrolan Ringan Seputar IT
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #2: Membuat Sendiri SMART HOME
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #3: RADically Fast and Easy Mobile Apps Development with Delphi
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #1: Pemanfaatan Artificial Intelligence di Masa Covid-19
by LuriDarmawan in Tutorial & Community Project more 4 years ago - Tempat Latihan Posting
by LuriDarmawan in OOT more 4 years ago - Archive
- Looping lagi...
by idhiel in Hal umum tentang Pascal Indonesia more 12 years ago - [ask] koneksi ke ODBC user Dsn saat runtime dengan ado
by halimanh in FireBird more 12 years ago - Validasi menggunakan data tanggal
by mas_kofa in Hal umum tentang Pascal Indonesia more 12 years ago