Difference between revisions of "Lua:Class:Button"

From Cheat Engine
Jump to navigation Jump to search
(Update inheritence link)
m (Examples: Syntax Highlight.)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''Button Class''': (Inheritance: ''[[Lua:Class:ButtonControl|ButtonControl]]'' > ''[[WinControl]]'' > ''[[Control]]'' > ''[[Component]]'' > ''[[Object]]'')
+
{{NeedWork}}
 +
{{Class|'''class''' Button ''':''' ButtonControl}}
  
<span style="color:red; font-weight:bold; font-style:italic;">WARNING: This page may be incomplete.</span>
+
The Button class represents a clickable button control.
  
== Description ==
+
A Button inherits from ButtonControl, WinControl, Control, Component, and Object. It can be created with createButton and must belong to an owner inherited from WinControl.
  
The button class is a visual component in the shape of a button.
+
===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
 +
|-
 +
|Button
 +
|ButtonControl
 +
|A clickable button control.
 +
|-
 +
|ButtonControl
 +
|WinControl
 +
|Base class for button-like controls.
 +
|-
 +
|WinControl
 +
|Control
 +
|Base class for windowed controls.
 +
|-
 +
|Control
 +
|Component
 +
|Base class for visual controls.
 +
|-
 +
|Component
 +
|Object
 +
|Base class for components.
 +
|}
  
== Creation ==
+
===Creation===
 +
{{CodeBox|'''function''' createButton(''owner'') ''':''' Button}}
  
; createButton(''owner'') &#58; ''Button''
+
Creates a Button object that belongs to the given owner.
: Creates a Button class object which belongs to the given owner. Owner can be any object inherited from WinControl.
 
  
== Properties ==
+
The owner can be any object inherited from WinControl.
  
; ModalResult &#58; ''ModalResult''
+
===Function Parameters===
: The result this button will give the modalform when clicked.
+
{|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 button. This can be any object inherited from WinControl.
 +
|}
  
== Methods ==
+
===Properties===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Property
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|ModalResult
 +
|ModalResult
 +
|The result this button will give the modal form when clicked.
 +
|}
  
; getModalResult(''button'') &#58; ''ModalResult''
+
===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
 +
|-
 +
|getModalResult(button)
 +
|ModalResult
 +
|Returns the ModalResult value of the specified button.
 +
|-
 +
|setModalResult(button, mr)
 +
|void
 +
|Sets the ModalResult value of the specified button.
 +
|}
  
; setModalResult(''button'', ''mr'')
+
===Examples===
:
+
<syntaxhighlight lang="lua" line>
 +
local form = createForm()
 +
form.Caption = "Button Example"
 +
 
 +
local button = createButton(form)
 +
button.Parent = form
 +
button.Caption = "Close"
 +
button.Left = 20
 +
button.Top = 20
 +
button.Width = 100
 +
 
 +
button.ModalResult = mrOK
 +
 
 +
form.showModal()
 +
form.destroy()
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
local form = createForm()
 +
form.Caption = "Button Example"
 +
 
 +
local button = createButton(form)
 +
button.Parent = form
 +
button.Caption = "OK"
 +
 
 +
setModalResult(button, mrOK)
 +
 
 +
print("ModalResult: " .. tostring(getModalResult(button)))
 +
 
 +
form.destroy()
 +
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
 
=== Related Classes ===
 
* [[Lua:Class:ButtonControl|ButtonControl]]
 

Latest revision as of 00:44, 27 June 2026

⚠️ Work Needed

This page still needs significant improvements.

Please help by expanding or correcting this article where possible.

For suggestions or discussion, see the talk page.

{} Class

class Button : ButtonControl

The Button class represents a clickable button control.

A Button inherits from ButtonControl, WinControl, Control, Component, and Object. It can be created with createButton and must belong to an owner inherited from WinControl.

Inheritance[edit]

Class Inherits From Description
Button ButtonControl A clickable button control.
ButtonControl WinControl Base class for button-like controls.
WinControl Control Base class for windowed controls.
Control Component Base class for visual controls.
Component Object Base class for components.

Creation[edit]

<> Lua API Reference

function createButton(owner) : Button

Creates a Button 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 button. This can be any object inherited from WinControl.

Properties[edit]

Property Type Description
ModalResult ModalResult The result this button will give the modal form when clicked.

Methods[edit]

Method Return Type Description
getModalResult(button) ModalResult Returns the ModalResult value of the specified button.
setModalResult(button, mr) void Sets the ModalResult value of the specified button.

Examples[edit]

 1 local form = createForm()
 2 form.Caption = "Button Example"
 3 
 4 local button = createButton(form)
 5 button.Parent = form
 6 button.Caption = "Close"
 7 button.Left = 20
 8 button.Top = 20
 9 button.Width = 100
10 
11 button.ModalResult = mrOK
12 
13 form.showModal()
14 form.destroy()
 1 local form = createForm()
 2 form.Caption = "Button Example"
 3 
 4 local button = createButton(form)
 5 button.Parent = form
 6 button.Caption = "OK"
 7 
 8 setModalResult(button, mrOK)
 9 
10 print("ModalResult: " .. tostring(getModalResult(button)))
11 
12 form.destroy()

Main Pages

Core Lua documentation entry points

Lua
Script Engine