<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.cheatengine.org/index.php?action=history&amp;feed=atom&amp;title=Lua%3AClass%3ACustomControl</id>
	<title>Lua:Class:CustomControl - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.cheatengine.org/index.php?action=history&amp;feed=atom&amp;title=Lua%3AClass%3ACustomControl"/>
	<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:Class:CustomControl&amp;action=history"/>
	<updated>2026-06-27T20:11:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>https://wiki.cheatengine.org/index.php?title=Lua:Class:CustomControl&amp;diff=8533&amp;oldid=prev</id>
		<title>Leunsel: Initial page creation.</title>
		<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:Class:CustomControl&amp;diff=8533&amp;oldid=prev"/>
		<updated>2026-06-27T01:12:49Z</updated>

		<summary type="html">&lt;p&gt;Initial page creation.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Lua]]&lt;br /&gt;
{{Class|'''class''' CustomControl ''':''' WinControl}}&lt;br /&gt;
&lt;br /&gt;
The CustomControl class represents a windowed control that exposes a Canvas for custom drawing.&lt;br /&gt;
&lt;br /&gt;
CustomControl inherits from [[Lua:Class:WinControl|WinControl]], [[Lua:Class:Control|Control]], [[Lua:Class:Component|Component]], and [[Lua:Class:Object|Object]].&lt;br /&gt;
&lt;br /&gt;
===Inheritance===&lt;br /&gt;
{|width=&amp;quot;85%&amp;quot; cellpadding=&amp;quot;10%&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Class&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Inherits From&lt;br /&gt;
!style=&amp;quot;width: 80%;background-color:white;&amp;quot; align=&amp;quot;left&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|CustomControl&lt;br /&gt;
|WinControl&lt;br /&gt;
|Base class for windowed controls that support custom painting.&lt;br /&gt;
|-&lt;br /&gt;
|WinControl&lt;br /&gt;
|Control&lt;br /&gt;
|Base class for controls that have a window handle, can contain child controls, and can receive focus.&lt;br /&gt;
|-&lt;br /&gt;
|Control&lt;br /&gt;
|Component&lt;br /&gt;
|Base class for visual controls.&lt;br /&gt;
|-&lt;br /&gt;
|Component&lt;br /&gt;
|Object&lt;br /&gt;
|Base class for owned components.&lt;br /&gt;
|-&lt;br /&gt;
|Object&lt;br /&gt;
|None&lt;br /&gt;
|Base class for Lua-exposed objects.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Properties ==&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;85%&amp;quot; cellpadding=&amp;quot;10%&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Property&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Type&lt;br /&gt;
!style=&amp;quot;width: 80%;background-color:white;&amp;quot; align=&amp;quot;left&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|Canvas&lt;br /&gt;
|[[Lua:Class:Canvas|Canvas]]&lt;br /&gt;
|Read-only canvas object used for drawing on the control.&lt;br /&gt;
|-&lt;br /&gt;
|OnPaint&lt;br /&gt;
|Function&lt;br /&gt;
|Event handler that can be assigned to perform custom painting.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Methods ==&lt;br /&gt;
&lt;br /&gt;
{|width=&amp;quot;85%&amp;quot; cellpadding=&amp;quot;10%&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Method&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Return Type&lt;br /&gt;
!style=&amp;quot;width: 80%;background-color:white;&amp;quot; align=&amp;quot;left&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|getCanvas()&lt;br /&gt;
|[[Lua:Class:Canvas|Canvas]]&lt;br /&gt;
|Returns the Canvas object for the object that inherited from CustomControl.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Method Parameters ==&lt;br /&gt;
&lt;br /&gt;
===getCanvas===&lt;br /&gt;
This method has no parameters.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
===Get the Canvas through the property===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;4&amp;quot;&amp;gt;&lt;br /&gt;
local form = createForm(false)&lt;br /&gt;
local paintBox = createPaintBox(form)&lt;br /&gt;
&lt;br /&gt;
local canvas = paintBox.Canvas&lt;br /&gt;
&lt;br /&gt;
print(canvas.ClassName)&lt;br /&gt;
&lt;br /&gt;
form.destroy()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get the Canvas through getCanvas===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;4&amp;quot;&amp;gt;&lt;br /&gt;
local form = createForm(false)&lt;br /&gt;
local paintBox = createPaintBox(form)&lt;br /&gt;
&lt;br /&gt;
local canvas = paintBox.getCanvas()&lt;br /&gt;
&lt;br /&gt;
print(canvas.ClassName)&lt;br /&gt;
&lt;br /&gt;
form.destroy()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assign an OnPaint event===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;4&amp;quot;&amp;gt;&lt;br /&gt;
local form = createForm(false)&lt;br /&gt;
local paintBox = createPaintBox(form)&lt;br /&gt;
&lt;br /&gt;
paintBox.OnPaint = function(sender)&lt;br /&gt;
  local canvas = sender.Canvas&lt;br /&gt;
  canvas.TextOut(10, 10, &amp;quot;Custom painting&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
form.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Draw a rectangle in OnPaint===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;4,6&amp;quot;&amp;gt;&lt;br /&gt;
local form = createForm(false)&lt;br /&gt;
local paintBox = createPaintBox(form)&lt;br /&gt;
&lt;br /&gt;
paintBox.OnPaint = function(sender)&lt;br /&gt;
  local canvas = sender.Canvas&lt;br /&gt;
  canvas.Rectangle(10, 10, 150, 80)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
form.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Draw text on the control===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;4,6&amp;quot;&amp;gt;&lt;br /&gt;
local form = createForm(false)&lt;br /&gt;
local paintBox = createPaintBox(form)&lt;br /&gt;
&lt;br /&gt;
paintBox.OnPaint = function(sender)&lt;br /&gt;
  local canvas = sender.Canvas&lt;br /&gt;
  canvas.TextOut(10, 10, &amp;quot;Hello Canvas&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
form.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use the same handler for multiple controls===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;8,9&amp;quot;&amp;gt;&lt;br /&gt;
local form = createForm(false)&lt;br /&gt;
local paintBox1 = createPaintBox(form)&lt;br /&gt;
local paintBox2 = createPaintBox(form)&lt;br /&gt;
&lt;br /&gt;
local function paintHandler(sender)&lt;br /&gt;
  sender.Canvas.TextOut(10, 10, sender.Name)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
paintBox1.OnPaint = paintHandler&lt;br /&gt;
paintBox2.OnPaint = paintHandler&lt;br /&gt;
&lt;br /&gt;
form.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use getCanvas inside a helper function===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;
local function drawCaption(control, text)&lt;br /&gt;
  local canvas = control.getCanvas()&lt;br /&gt;
  canvas.TextOut(10, 10, text)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local form = createForm(false)&lt;br /&gt;
local paintBox = createPaintBox(form)&lt;br /&gt;
&lt;br /&gt;
paintBox.OnPaint = function(sender)&lt;br /&gt;
  drawCaption(sender, &amp;quot;Drawn by helper&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
form.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Force repaint after changing state===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;6,11&amp;quot;&amp;gt;&lt;br /&gt;
local form = createForm(false)&lt;br /&gt;
local paintBox = createPaintBox(form)&lt;br /&gt;
local text = &amp;quot;Initial text&amp;quot;&lt;br /&gt;
&lt;br /&gt;
paintBox.OnPaint = function(sender)&lt;br /&gt;
  sender.Canvas.TextOut(10, 10, text)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
text = &amp;quot;Updated text&amp;quot;&lt;br /&gt;
&lt;br /&gt;
paintBox.repaint()&lt;br /&gt;
&lt;br /&gt;
form.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaSeeAlso}}&lt;br /&gt;
&lt;br /&gt;
{{Forms}}&lt;/div&gt;</summary>
		<author><name>Leunsel</name></author>
		
	</entry>
</feed>