Difference between revisions of "Lua:Class:ProgressBar"
Jump to navigation
Jump to search
m (moved ProgressBar to Lua:Class:ProgressBar) |
(Major overhaul of the post.) |
||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | ProgressBar | + | {{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=== | ||
| + | <pre> | ||
| + | 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() | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | 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() | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | 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() | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | local progressbar = createProgressBar(getMainForm()) | ||
| + | |||
| + | progressbar.Min = 0 | ||
| + | progressbar.Max = 100 | ||
| + | progressbar.setPosition2(50) | ||
| + | |||
| + | print("Progress: " .. tostring(progressbar.getPosition())) | ||
| + | </pre> | ||
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| + | |||
| + | {{Forms}} | ||
Revision as of 00:41, 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
| 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
Creates a ProgressBar object that belongs to the given owner.
The owner can be any object inherited from WinControl.
Function Parameters
| Parameter | Type | Description |
|---|---|---|
| owner | WinControl | The owner of the progress bar. This can be any object inherited from WinControl. |
Returns
ProgressBar — The created ProgressBar object.
Properties
| 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
| 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
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()
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()
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()
local progressbar = createProgressBar(getMainForm())
progressbar.Min = 0
progressbar.Max = 100
progressbar.setPosition2(50)
print("Progress: " .. tostring(progressbar.getPosition()))