Example of inserting progress bars in the status bar

xiaoxiao2021-03-06  39

Status strip inserts visual controls

-------------------------------------------------- ------------------------------

First, place a status bar control Status in the FROM. Adjust Status.Panels where three state strip panels are inserted. Set the parameter style of the second panel to PSOWNERDRAW. This is very important. If you don't do this, you will never display something outside the text. Then insert a line statusdrawRect: = Rect in the onDrawpanel event in the status bar; the record parameter style is set to the coordinates of the panel of PSOWNERDRAW. In the second step, a TProgressBar type variable prograices are declared in the Private of from Private. The CREATE method is then built during a menu message response, and then sets the status strip to the parent window of the process strip, and then set some of the necessary parameters of the process strip. For example: maximum, minimum, origin coordinate, height, and width, etc. Finally, compile the program, you will find a motion-in-sports process strip in the status bar. Similarly, you can also insert other visual controls in the status bar, such as: button, bitmap, and animation control, etc. The following is an example program: Unit demo1; Interface Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Comctrls, Menus

type TForm1 = class (TForm) status: TStatusBar; MainMenu1: TMainMenu; File1: TMenuItem; insertprocressbar1: TMenuItem; exit1: TMenuItem; procedure StatusDrawPanel (StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect); procedure exit1Click (Sender: TObject ); Procedure InsertProcressbar1click (Sender: TOBJECT); Procedure Formcreate (Sender: TOBJECT);

Proscate {private declarations}: tprogressbar; colorindex: integer; bookopen: boolean; ssbmp: tbitmap; statusdrawRect: TRECT; // Record the coordinate range to insert

Public {public declarations} END;

Var Form1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TForm1.statusdrawpanel (Statusbar: TSTATUSBAR; Panel: TSTATUSPANEL; Const Rect: TRECT); begin statusDrawRect: = Rect; // Record the scope of the coordinate range to implement status stunts;

Procedure TFORM1.EXIT1CLICK (Sender: TOBJECT); begin close;

procedure TForm1.insertprocressbar1Click (Sender: TObject); var i, count: integer; staPanleWidth: integer; begin progress: = TProgressbar.create (form1); count: = 3000; // process bar maximum staPanleWidth: = status.Panels .Items [2] .width; // Due to the wide process strip, it is necessary to change the width of the status strip panel, here to save its width. status.Panels.Items [2] .width: = 150; // change the width status.repaint; with progress do begin top: = StatusDrawRect.top; left: = StatusDrawRect.left; width: = StatusDrawRect.right-StatusDrawRect.left Height: = statusdrawrect.bottom-statusdrawRect.top; // Setting the width and height of the process strip Visible: = true; try parent: = status; // The owner of the process strip is Status min: = 0; Max: = count; // process strip's maximum and minimum step: = 1; // process strip of the step for i: = 1 to count do stepit; // Accumulate Procedure ShowMessage ('Now, process strips will be from The memory is released in memory '); Finally Free; // Release Processes end; // Try end; // with status.panels.items [2] .width: = stapanlewidth; // Restore the status strip panel of the width END; // beginprocedure TFORM1.FORMCREATE (Sender: TOBJECT); Begin

END;

The final effect is shown in the figure:

转载请注明原文地址:https://www.9cbs.com/read-55186.html

New Post(0)