Difference between revisions of "Lua:Class:ProgressBar"
Jump to navigation
Jump to search
Bronzdragon (talk | contribs) |
m (Syntax Highlighting.) |
||
| (7 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
| − | + | [[Category:Lua]] | |
| − | + | {{Class|'''class''' ProgressBar ''':''' WinControl}} | |
| − | + | The ProgressBar class represents a progress bar control. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | A ProgressBar inherits from WinControl, Control, Component, and Object. It can display progress within a defined minimum and maximum range. | |
| − | + | ||
| − | + | ===Inheritance=== | |
| − | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | |
| − | + | !align="left"|Class | |
| − | + | !align="left"|Inherits From | |
| − | + | !style="width: 80%;background-color:white;" align="left"|Description | |
| − | + | |- | |
| − | + | |ProgressBar | |
| + | |WinControl | ||
| + | |A visual progress bar control. | ||
| + | |- | ||
| + | |WinControl | ||
| + | |Control | ||
| + | |Base class for windowed controls. | ||
| + | |- | ||
| + | |Control | ||
| + | |Component | ||
| + | |Base class for visual controls. | ||
| + | |- | ||
| + | |Component | ||
| + | |Object | ||
| + | |Base class for components. | ||
| + | |} | ||
| + | |||
| + | ===Creation=== | ||
| + | {{CodeBox|'''function''' createProgressBar(''owner'') ''':''' ProgressBar}} | ||
| + | |||
| + | Creates a ProgressBar object that belongs to the given owner. | ||
| + | |||
| + | The owner can be any object inherited from WinControl. | ||
| + | |||
| + | ===Function Parameters=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Parameter | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |owner | ||
| + | |WinControl | ||
| + | |The owner of the progress bar. This can be any object inherited from WinControl. | ||
| + | |} | ||
| + | |||
| + | ===Returns=== | ||
| + | ProgressBar — The created ProgressBar object. | ||
| + | |||
| + | ===Properties=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Property | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |Min | ||
| + | |Integer | ||
| + | |The minimum position value the progress bar can have. The default is 0. | ||
| + | |- | ||
| + | |Max | ||
| + | |Integer | ||
| + | |The maximum position value the progress bar can have. The default is 100. | ||
| + | |- | ||
| + | |Position | ||
| + | |Integer | ||
| + | |The current position of the progress bar. | ||
| + | |- | ||
| + | |Step | ||
| + | |Integer | ||
| + | |The step size used when stepIt() is called. | ||
| + | |} | ||
| + | |||
| + | ===Methods=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Method | ||
| + | !align="left"|Return Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |stepIt() | ||
| + | |void | ||
| + | |Increases the current position by the Step value. | ||
| + | |- | ||
| + | |stepBy(integer) | ||
| + | |void | ||
| + | |Increases the current position by the given integer value. | ||
| + | |- | ||
| + | |getMax() | ||
| + | |Integer | ||
| + | |Returns the Max property. | ||
| + | |- | ||
| + | |setMax(integer) | ||
| + | |void | ||
| + | |Sets the Max property. | ||
| + | |- | ||
| + | |getMin() | ||
| + | |Integer | ||
| + | |Returns the Min property. | ||
| + | |- | ||
| + | |setMin(integer) | ||
| + | |void | ||
| + | |Sets the Min property. | ||
| + | |- | ||
| + | |getPosition() | ||
| + | |Integer | ||
| + | |Returns the current Position property. | ||
| + | |- | ||
| + | |setPosition(integer) | ||
| + | |void | ||
| + | |Sets the current Position property. | ||
| + | |- | ||
| + | |setPosition2(integer) | ||
| + | |void | ||
| + | |Sets the current Position property without the slow progress animation on Windows 7 and later. | ||
| + | |} | ||
| + | |||
| + | ===Examples=== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local form = createForm() | ||
| + | form.Caption = "ProgressBar Example" | ||
| + | form.Width = 400 | ||
| + | form.Height = 150 | ||
| + | |||
| + | local progressbar = createProgressBar(form) | ||
| + | progressbar.Parent = form | ||
| + | progressbar.Left = 20 | ||
| + | progressbar.Top = 20 | ||
| + | progressbar.Width = 340 | ||
| + | progressbar.Height = 24 | ||
| + | progressbar.Min = 0 | ||
| + | progressbar.Max = 100 | ||
| + | progressbar.Position = 25 | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local form = createForm() | ||
| + | form.Caption = "Step Example" | ||
| + | form.Width = 400 | ||
| + | form.Height = 150 | ||
| + | |||
| + | local progressbar = createProgressBar(form) | ||
| + | progressbar.Parent = form | ||
| + | progressbar.Left = 20 | ||
| + | progressbar.Top = 20 | ||
| + | progressbar.Width = 340 | ||
| + | progressbar.Height = 24 | ||
| + | progressbar.Min = 0 | ||
| + | progressbar.Max = 100 | ||
| + | progressbar.Step = 10 | ||
| + | |||
| + | local button = createButton(form) | ||
| + | button.Parent = form | ||
| + | button.Caption = "Step" | ||
| + | button.Left = 20 | ||
| + | button.Top = 60 | ||
| + | |||
| + | button.OnClick = function(sender) | ||
| + | progressbar.stepIt() | ||
| + | end | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local form = createForm() | ||
| + | form.Caption = "Timer Progress Example" | ||
| + | form.Width = 400 | ||
| + | form.Height = 150 | ||
| + | |||
| + | local progressbar = createProgressBar(form) | ||
| + | progressbar.Parent = form | ||
| + | progressbar.Left = 20 | ||
| + | progressbar.Top = 20 | ||
| + | progressbar.Width = 340 | ||
| + | progressbar.Height = 24 | ||
| + | progressbar.Min = 0 | ||
| + | progressbar.Max = 100 | ||
| + | progressbar.Position = 0 | ||
| + | |||
| + | local timer = createTimer(form) | ||
| + | timer.Interval = 100 | ||
| + | timer.OnTimer = function(sender) | ||
| + | progressbar.stepBy(1) | ||
| + | |||
| + | if progressbar.Position >= progressbar.Max then | ||
| + | sender.Enabled = false | ||
| + | end | ||
| + | end | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local progressbar = createProgressBar(getMainForm()) | ||
| + | |||
| + | progressbar.Min = 0 | ||
| + | progressbar.Max = 100 | ||
| + | progressbar.setPosition2(50) | ||
| + | |||
| + | print("Progress: " .. tostring(progressbar.getPosition())) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | {{LuaSeeAlso}} | ||
| + | |||
| + | {{Forms}} | ||
Latest revision as of 19:30, 25 June 2026
The ProgressBar class represents a progress bar control.
A ProgressBar inherits from WinControl, Control, Component, and Object. It can display progress within a defined minimum and maximum range.
Inheritance[edit]
| Class | Inherits From | Description |
|---|---|---|
| ProgressBar | WinControl | A visual progress bar control. |
| WinControl | Control | Base class for windowed controls. |
| Control | Component | Base class for visual controls. |
| Component | Object | Base class for components. |
Creation[edit]
Creates a ProgressBar object that belongs to the given owner.
The owner can be any object inherited from WinControl.
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| owner | WinControl | The owner of the progress bar. This can be any object inherited from WinControl. |
Returns[edit]
ProgressBar — The created ProgressBar object.
Properties[edit]
| Property | Type | Description |
|---|---|---|
| Min | Integer | The minimum position value the progress bar can have. The default is 0. |
| Max | Integer | The maximum position value the progress bar can have. The default is 100. |
| Position | Integer | The current position of the progress bar. |
| Step | Integer | The step size used when stepIt() is called. |
Methods[edit]
| Method | Return Type | Description |
|---|---|---|
| stepIt() | void | Increases the current position by the Step value. |
| stepBy(integer) | void | Increases the current position by the given integer value. |
| getMax() | Integer | Returns the Max property. |
| setMax(integer) | void | Sets the Max property. |
| getMin() | Integer | Returns the Min property. |
| setMin(integer) | void | Sets the Min property. |
| getPosition() | Integer | Returns the current Position property. |
| setPosition(integer) | void | Sets the current Position property. |
| setPosition2(integer) | void | Sets the current Position property without the slow progress animation on Windows 7 and later. |
Examples[edit]
1 local form = createForm()
2 form.Caption = "ProgressBar Example"
3 form.Width = 400
4 form.Height = 150
5
6 local progressbar = createProgressBar(form)
7 progressbar.Parent = form
8 progressbar.Left = 20
9 progressbar.Top = 20
10 progressbar.Width = 340
11 progressbar.Height = 24
12 progressbar.Min = 0
13 progressbar.Max = 100
14 progressbar.Position = 25
15
16 form.show()
1 local form = createForm()
2 form.Caption = "Step Example"
3 form.Width = 400
4 form.Height = 150
5
6 local progressbar = createProgressBar(form)
7 progressbar.Parent = form
8 progressbar.Left = 20
9 progressbar.Top = 20
10 progressbar.Width = 340
11 progressbar.Height = 24
12 progressbar.Min = 0
13 progressbar.Max = 100
14 progressbar.Step = 10
15
16 local button = createButton(form)
17 button.Parent = form
18 button.Caption = "Step"
19 button.Left = 20
20 button.Top = 60
21
22 button.OnClick = function(sender)
23 progressbar.stepIt()
24 end
25
26 form.show()
1 local form = createForm()
2 form.Caption = "Timer Progress Example"
3 form.Width = 400
4 form.Height = 150
5
6 local progressbar = createProgressBar(form)
7 progressbar.Parent = form
8 progressbar.Left = 20
9 progressbar.Top = 20
10 progressbar.Width = 340
11 progressbar.Height = 24
12 progressbar.Min = 0
13 progressbar.Max = 100
14 progressbar.Position = 0
15
16 local timer = createTimer(form)
17 timer.Interval = 100
18 timer.OnTimer = function(sender)
19 progressbar.stepBy(1)
20
21 if progressbar.Position >= progressbar.Max then
22 sender.Enabled = false
23 end
24 end
25
26 form.show()
1 local progressbar = createProgressBar(getMainForm())
2
3 progressbar.Min = 0
4 progressbar.Max = 100
5 progressbar.setPosition2(50)
6
7 print("Progress: " .. tostring(progressbar.getPosition()))