I am enjoying using G1ANT's ability to embed C# code in my scripts. However, I haven't been able to successfully code event handlers that work. Below is G1ANT code for a basic form with buttons and an edit box - but with no event handlers. (Note I'm not championing the use of G1ANT for creating forms, but the buttons constitute a good example of raising events.) Can anyone provide G1ANT code to handle these button events (anything, just a MsgBox would be more than adequate)? By the way, I've tried modifying scripts that run successfully in CS-Script , and programs that compile in VS 2019 and execute without complaint, but without luck.
addon core version 4.100.19170.929
addon language version 4.100.19170.929
♥macronamespaces = System, System.IO, System.Windows.Forms,System.Drawing,System.ComponentModel
♥concatenated = ‴Donald Trump‴
⊂
Form myForm = new Form();
Button button1;
Button button2;
TextBox tb1;
myForm.Height = 250;
myForm.Width = 400;
myForm.Text = "G1ANT FORM";
button1 = new Button();
button1.Size = new Size(80, 40);
button1.Location = new Point(30, 30);
button1.Text = "Click Me";
button2 = new Button();
button2.Size = new Size(80, 40);
button2.Location = new Point(120, 30);
button2.Text = "Font";
tb1 = new TextBox();
tb1.Size = new Size(920, 450);
tb1.Top = button1.Bottom + 5;
tb1.Left = 30;
tb1.Multiline = true;
tb1.Text = "Hello, Mr " + ♥concatenated + "!" + @"
Didn't I just see you at the White House yesterday?
";
myForm.Controls.Add(button1);
myForm.Controls.Add(button2);
myForm.Controls.Add(tb1);
myForm.Show()
The form looks like this.
Thanks in advance for all help, burque505
Yes, adding event handlers in G1ANT is possible. Here's an example that will work for you:
button1.Text = "Click Me";
button1.Click += new EventHandler(delegate (Object o, EventArgs a)
{
MessageBox.Show("test");
});