我很享受使用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
答案 0 :(得分:1)
是的,可以在G1ANT中添加事件处理程序。这是一个适合您的示例:
button1.Text = "Click Me";
button1.Click += new EventHandler(delegate (Object o, EventArgs a)
{
MessageBox.Show("test");
});