class WinControl : Control
The WinControl class represents a visual control that can own child controls and receive keyboard focus.
WinControl inherits from Control, Component, and Object. It is commonly used as a base class for forms, panels, group boxes, list boxes, edit controls, and other windowed controls.
Inheritance[edit]
| Class
|
Inherits From
|
Description
|
| WinControl
|
Control
|
Base class for controls that have a window handle, can contain child controls, and can receive focus.
|
| Control
|
Component
|
Base class for visual controls.
|
| Component
|
Object
|
Base class for owned components.
|
| Object
|
None
|
Base class for Lua-exposed objects.
|
Properties[edit]
| Property
|
Type
|
Description
|
| Handle
|
Integer
|
The internal Windows handle of the control.
|
| DoubleBuffered
|
Boolean
|
When enabled, graphical updates are first drawn to an offscreen bitmap and then shown on screen. This may reduce flickering.
|
| ControlCount
|
Integer
|
The number of child controls attached to this WinControl.
|
| Control[index]
|
Control
|
Array-style access to a child control.
|
| OnEnter
|
Function
|
Function to call when the WinControl gains focus.
|
| OnExit
|
Function
|
Function to call when the WinControl loses focus.
|
Methods[edit]
| Method
|
Return Type
|
Description
|
| getControlCount()
|
Integer
|
Returns the number of controls attached to this WinControl.
|
| getControl(index)
|
Control
|
Returns the child control at the specified index.
|
| getControlAtPos(x, y)
|
Control
|
Returns the child control at the given x and y position relative to the WinControl.
|
| canFocus()
|
Boolean
|
Returns true if the control can receive keyboard focus.
|
| focused()
|
Boolean
|
Returns true if the control currently has focus.
|
| setFocus()
|
void
|
Tries to set keyboard focus to the control.
|
| setShape(region)
|
void
|
Sets the specified Region object as the new shape for this WinControl.
|
| setShape(bitmap)
|
void
|
Sets the specified Bitmap object as the new shape for this WinControl.
|
| setOnEnter(function)
|
void
|
Sets the OnEnter event handler. The event is triggered when the WinControl gains focus.
|
| getOnEnter()
|
Function
|
Returns the current OnEnter event handler.
|
| setOnExit(function)
|
void
|
Sets the OnExit event handler. The event is triggered when the WinControl loses focus.
|
| getOnExit()
|
Function
|
Returns the current OnExit event handler.
|
| setLayeredAttributes(key, alpha, flags)
|
void
|
Sets layered window attributes for the control if possible. Flags can be a combination of LWA_ALPHA and/or LWA_COLORKEY.
|
Method Parameters[edit]
getControl[edit]
| Parameter
|
Type
|
Description
|
| index
|
Integer
|
The zero-based index of the child control.
|
getControlAtPos[edit]
| Parameter
|
Type
|
Description
|
| x
|
Integer
|
The x coordinate relative to the WinControl.
|
| y
|
Integer
|
The y coordinate relative to the WinControl.
|
setShape[edit]
| Parameter
|
Type
|
Description
|
| region
|
Region
|
The region object to use as the new shape.
|
| bitmap
|
Bitmap
|
The bitmap object to use as the new shape.
|
setOnEnter / setOnExit[edit]
| Parameter
|
Type
|
Description
|
| function
|
Function
|
The event handler function to assign.
|
setLayeredAttributes[edit]
| Parameter
|
Type
|
Description
|
| key
|
Integer
|
The color key value used when LWA_COLORKEY is included in the flags.
|
| alpha
|
Integer
|
The alpha value used when LWA_ALPHA is included in the flags.
|
| flags
|
Integer
|
A combination of layered attribute flags, such as LWA_ALPHA and/or LWA_COLORKEY.
|
setLayeredAttributes depends on operating system support. On Windows 7 and earlier, only forms are supported.
Examples[edit]
Get the handle of a WinControl[edit]
1 local form = createForm(false)
2 local button = createButton(form)
3
4 print("Button handle: " .. tostring(button.Handle))
5
6 form.destroy()
Enable DoubleBuffered on a panel[edit]
1 local form = createForm(false)
2 local panel = createPanel(form)
3
4 panel.DoubleBuffered = true
5
6 form.show()
Count child controls[edit]
1 local form = createForm(false)
2 createButton(form)
3 createEdit(form)
4
5 local count = form.ControlCount
6
7 print("Child controls: " .. tostring(count))
8
9 form.destroy()
Access child controls by index[edit]
1 local form = createForm(false)
2 createButton(form)
3 createEdit(form)
4
5 for i = 0, form.ControlCount - 1 do
6 local control = form.Control[i]
7 print(control.ClassName)
8 end
9
10 form.destroy()
Use getControlCount and getControl[edit]
1 local form = createForm(false)
2 createButton(form)
3 createEdit(form)
4
5 local count = form.getControlCount()
6
7 for i = 0, count - 1 do
8 local control = form.getControl(i)
9 print(control.ClassName)
10 end
11
12 form.destroy()
Get the control at a relative position[edit]
1 local form = createForm(false)
2 local button = createButton(form)
3 button.Left = 10
4 button.Top = 10
5
6 local control = form.getControlAtPos(15, 15)
7
8 if control ~= nil then
9 print("Control at position: " .. control.ClassName)
10 end
11
12 form.destroy()
Check whether a control can receive focus[edit]
1 local form = createForm(false)
2 local edit = createEdit(form)
3
4 if edit.canFocus() then
5 print("Edit can receive focus")
6 end
7
8 form.destroy()
Set keyboard focus[edit]
1 local form = createForm(false)
2 local edit = createEdit(form)
3
4 form.show()
5
6 if edit.canFocus() then
7 edit.setFocus()
8 end
Check whether a control is focused[edit]
1 local form = createForm(false)
2 local edit = createEdit(form)
3
4 print("Focused: " .. tostring(edit.focused()))
5
6 form.destroy()
Assign OnEnter and OnExit events through properties[edit]
1 local form = createForm(false)
2 local edit = createEdit(form)
3
4 edit.OnEnter = function(sender)
5 print("Focus entered")
6 end
7
8 edit.OnExit = function(sender)
9 print("Focus lost")
10 end
11
12 form.show()
Assign OnEnter and OnExit events through methods[edit]
1 local form = createForm(false)
2 local edit = createEdit(form)
3
4 edit.setOnEnter(function(sender)
5 print("Focus entered")
6 end)
7
8 edit.setOnExit(function(sender)
9 print("Focus lost")
10 end)
11
12 form.show()
Read assigned focus event handlers[edit]
1 local form = createForm(false)
2 local edit = createEdit(form)
3
4 edit.OnEnter = function(sender) print("Enter") end
5
6 local onEnter = edit.getOnEnter()
7 local onExit = edit.getOnExit()
8
9 print("OnEnter assigned: " .. tostring(onEnter ~= nil))
10 print("OnExit assigned: " .. tostring(onExit ~= nil))
11
12 form.destroy()
Set a Region as the shape[edit]
1 local form = createForm(false)
2 local region = createRegion()
3
4 form.Width = 300
5 form.setShape(region)
6
7 form.show()
Set layered alpha attributes[edit]
1 local form = createForm(false)
2 form.Width = 300
3 form.Height = 200
4 form.show()
5
6 form.setLayeredAttributes(0, 180, LWA_ALPHA)
Core Lua documentation entry points