diff options
Diffstat (limited to 'doc/classes/Button.xml')
-rw-r--r-- | doc/classes/Button.xml | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/doc/classes/Button.xml b/doc/classes/Button.xml index de05cfcd13..e0ccda957f 100644 --- a/doc/classes/Button.xml +++ b/doc/classes/Button.xml @@ -6,7 +6,8 @@ <description> Button is the standard themed button. It can contain text and an icon, and will display them according to the current [Theme]. [b]Example of creating a button and assigning an action when pressed by code:[/b] - [codeblock] + [codeblocks] + [gdscript] func _ready(): var button = Button.new() button.text = "Click me" @@ -15,8 +16,24 @@ func _button_pressed(): print("Hello world!") - [/codeblock] + [/gdscript] + [csharp] + public override void _Ready() + { + var button = new Button(); + button.Text = "Click me"; + button.Connect("pressed", this, nameof(ButtonPressed)); + AddChild(button); + } + + private void ButtonPressed() + { + GD.Print("Hello world!"); + } + [/csharp] + [/codeblocks] Buttons (like all Control nodes) can also be created in the editor, but some situations may require creating them from code. + See also [BaseButton] which contains common properties and methods associated with this node. </description> <tutorials> </tutorials> |