我喜欢使用G1ANT将C#代码嵌入到我的脚本中。但是,我还不能成功地编写能够工作的事件处理程序。下面是一个具有按钮和编辑框的基本窗体的G1ANT代码-但没有事件处理程序。(注意,我并不支持使用G1ANT创建表单,但是这些按钮构成了引发事件的一个很好的例子。)有没有人能提供G1ANT代码来处理这些按钮事件(任何东西,只要一个MsgBox就足够了)?顺便说一句,我已经尝试修改了在CS-Script中成功运行的脚本,以及在VS2019中编译并执行的程序,但没有遇到任何问题。
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

发布于 2019-07-08 22:31:22
是的,在G1ANT中添加事件处理程序是可能的。下面是一个适用于您的示例:
button1.Text = "Click Me";
button1.Click += new EventHandler(delegate (Object o, EventArgs a)
{
MessageBox.Show("test");
});https://stackoverflow.com/questions/56907581
复制相似问题