G1ANT 中的 C# 事件处理程序 - 需要正确的语法

C# event handlers in G1ANT - correct syntax needed

我很喜欢使用 G1ANT 将 C# 代码嵌入到我的脚本中的功能。但是,我无法成功地编写有效的事件处理程序代码。下面是带有按钮和编辑框的基本表单的 G1ANT 代码——但没有事件处理程序。 (请注意,我并不支持使用 G1ANT 创建表单,但按钮构成了引发事件的一个很好的例子。)任何人都可以提供 G1ANT 代码来处理这些按钮事件(任何东西,只要一个 MsgBox 就足够了)?顺便说一句,我已经尝试修改在 CS-Script 中成功 运行 的脚本,以及在 VS 2019 中编译并在没有投诉但没有运气的情况下执行的程序。

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()

表单如下所示。

在此先感谢您的帮助, burque505

是的,可以在 G1ANT 中添加事件处理程序。这是一个适合您的示例:

   button1.Text = "Click Me";
   button1.Click += new EventHandler(delegate (Object o, EventArgs a) 
   {
      MessageBox.Show("test");  
   });