### Create Canvas Events

This is an example showing how to create an events for a circle placed on the canvas.
Example Draw Circle
Define a global Canvas variable:
`Sub Process_Globals
Private gcanCircle As Canvas
...
End Sub`
Create the Circle in Sub AppStart
`Sub AppStart (Form1 As Form, Args() As String)
'
gcanCircle.Initialize("gcanCircle")
gcanCircle.DrawCircle(0,0,100,fx.Colors.Blue,True,3)
MainForm.RootPane.AddNode(gcanCircle,0,0,200,200)
'
End Sub`
Define the Canvas Event
In this case the Mouse Clicked
`Sub gcanCircle_MouseClicked(EventData As MouseEvent)
Log("Clicked the Blue Circle on the Canvas!")
End Sub`
Example Draw Text
Private canvasText As Canvas
canvasText.Initialize("canText")
' Create the font for hello world
Dim f As Font
f = fx.CreateFont("Courier New", 32, True, False)
canvasText.DrawText("Hello World", 0, 150, f, fx.Colors.Red, "LEFT")
MainForm.RootPane.AddNode(canvas,0,0,200,200)
Example Draw Rectangle with Text
' Define the textbox as a canvas
Private textbox As Canvas
' Init the textbox
textbox.Initialize("textbox")
textbox.Width = 350
textbox.Height = 250
' Create the font for hello world
Dim f As Font
f = fx.CreateFont("Courier New", 32, True, False)
' Draw rectangle
textbox.Style="-fx-background-color:blue"
textbox.DrawRect(25,25,325,225,fx.Colors.Blue,True,5)
' Draw the text
textbox.DrawText("Hello World", 50, 100, f, fx.Colors.Red, "LEFT")
MainForm.RootPane.AddNode(textbox ,0,0,350,350)
Example Draw Rectangle with Text and save to Image File (png)
' Define the textbox as a canvas
Private textbox As Canvas
' Init the textbox
textbox.Initialize("textbox")
textbox.Width = 350
textbox.Height = 250
' Create the font for hello world
Dim f As Font
f = fx.CreateFont("Courier New", 32, True, False)
' Draw rectangle
textbox.Style="-fx-background-color:blue"
textbox.DrawRect(25,25,325,225,fx.Colors.Blue,True,5)
' Draw the text
textbox.DrawText("Hello World", 50, 100, f, fx.Colors.Red, "LEFT")
MainForm.RootPane.AddNode(textbox ,0,0,350,350)
' Save the image
Dim Out As OutputStream
Out = File.OpenOutput(File.DirApp,"helloworld.png",False)
textbox.Snapshot.WriteToStream(Out)
Out.Close

Changed: , Category: Canvas, File: T6C168M1240.htm, ID: 1240