Lua:Class:CustomControl

From Cheat Engine
Revision as of 01:12, 27 June 2026 by Leunsel (talk | contribs) (Initial page creation.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

{} Class

class CustomControl : WinControl

The CustomControl class represents a windowed control that exposes a Canvas for custom drawing.

CustomControl inherits from WinControl, Control, Component, and Object.

Inheritance[edit]

Class Inherits From Description
CustomControl WinControl Base class for windowed controls that support custom painting.
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
Canvas Canvas Read-only canvas object used for drawing on the control.
OnPaint Function Event handler that can be assigned to perform custom painting.

Methods[edit]

Method Return Type Description
getCanvas() Canvas Returns the Canvas object for the object that inherited from CustomControl.

Method Parameters[edit]

getCanvas[edit]

This method has no parameters.

Examples[edit]

Get the Canvas through the property[edit]

1 local form = createForm(false)
2 local paintBox = createPaintBox(form)
3 
4 local canvas = paintBox.Canvas
5 
6 print(canvas.ClassName)
7 
8 form.destroy()

Get the Canvas through getCanvas[edit]

1 local form = createForm(false)
2 local paintBox = createPaintBox(form)
3 
4 local canvas = paintBox.getCanvas()
5 
6 print(canvas.ClassName)
7 
8 form.destroy()

Assign an OnPaint event[edit]

1 local form = createForm(false)
2 local paintBox = createPaintBox(form)
3 
4 paintBox.OnPaint = function(sender)
5   local canvas = sender.Canvas
6   canvas.TextOut(10, 10, "Custom painting")
7 end
8 
9 form.show()

Draw a rectangle in OnPaint[edit]

1 local form = createForm(false)
2 local paintBox = createPaintBox(form)
3 
4 paintBox.OnPaint = function(sender)
5   local canvas = sender.Canvas
6   canvas.Rectangle(10, 10, 150, 80)
7 end
8 
9 form.show()

Draw text on the control[edit]

1 local form = createForm(false)
2 local paintBox = createPaintBox(form)
3 
4 paintBox.OnPaint = function(sender)
5   local canvas = sender.Canvas
6   canvas.TextOut(10, 10, "Hello Canvas")
7 end
8 
9 form.show()

Use the same handler for multiple controls[edit]

 1 local form = createForm(false)
 2 local paintBox1 = createPaintBox(form)
 3 local paintBox2 = createPaintBox(form)
 4 
 5 local function paintHandler(sender)
 6   sender.Canvas.TextOut(10, 10, sender.Name)
 7 end
 8 
 9 paintBox1.OnPaint = paintHandler
10 paintBox2.OnPaint = paintHandler
11 
12 form.show()

Use getCanvas inside a helper function[edit]

 1 local function drawCaption(control, text)
 2   local canvas = control.getCanvas()
 3   canvas.TextOut(10, 10, text)
 4 end
 5 
 6 local form = createForm(false)
 7 local paintBox = createPaintBox(form)
 8 
 9 paintBox.OnPaint = function(sender)
10   drawCaption(sender, "Drawn by helper")
11 end
12 
13 form.show()

Force repaint after changing state[edit]

 1 local form = createForm(false)
 2 local paintBox = createPaintBox(form)
 3 local text = "Initial text"
 4 
 5 paintBox.OnPaint = function(sender)
 6   sender.Canvas.TextOut(10, 10, text)
 7 end
 8 
 9 text = "Updated text"
10 
11 paintBox.repaint()
12 
13 form.show()

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Form Related Classes