using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using PaxScript.Net; namespace CallMethod { public class CallMethodTest : System.Windows.Forms.Form { private System.ComponentModel.IContainer components; private PaxScript.Net.PaxScripter paxScripter1; private System.Windows.Forms.Button btnCallMethod; private System.Windows.Forms.TextBox tbState; private System.Windows.Forms.Label lbState; private System.Windows.Forms.Button btnReset; private System.Windows.Forms.RichTextBox rtbScript; private System.Windows.Forms.Label label1; public CallMethodTest() { InitializeComponent(); tbState.Text = paxScripter1.State.ToString(); } protected override void Dispose (bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.paxScripter1 = new PaxScript.Net.PaxScripter(this.components); this.btnCallMethod = new System.Windows.Forms.Button(); this.tbState = new System.Windows.Forms.TextBox(); this.lbState = new System.Windows.Forms.Label(); this.btnReset = new System.Windows.Forms.Button(); this.rtbScript = new System.Windows.Forms.RichTextBox(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // paxScripter1 // this.paxScripter1.OnChangeState += new PaxScript.Net.ChangeStateHandler(this.paxScripter1_OnChangeState); // // btnCallMethod // this.btnCallMethod.Location = new System.Drawing.Point(24, 64); this.btnCallMethod.Name = "btnCallMethod"; this.btnCallMethod.Size = new System.Drawing.Size(128, 23); this.btnCallMethod.TabIndex = 0; this.btnCallMethod.Text = "Call method"; this.btnCallMethod.Click += new System.EventHandler(this.button1_Click); // // tbState // this.tbState.Location = new System.Drawing.Point(24, 208); this.tbState.Name = "tbState"; this.tbState.TabIndex = 1; this.tbState.Text = ""; // // lbState // this.lbState.Location = new System.Drawing.Point(24, 176); this.lbState.Name = "lbState"; this.lbState.TabIndex = 2; this.lbState.Text = "Scripter state"; // // btnReset // this.btnReset.Location = new System.Drawing.Point(24, 24); this.btnReset.Name = "btnReset"; this.btnReset.Size = new System.Drawing.Size(128, 23); this.btnReset.TabIndex = 3; this.btnReset.Text = "Reset scripter"; this.btnReset.Click += new System.EventHandler(this.btnReset_Click); // // rtbScript // this.rtbScript.Location = new System.Drawing.Point(216, 48); this.rtbScript.Name = "rtbScript"; this.rtbScript.Size = new System.Drawing.Size(296, 200); this.rtbScript.TabIndex = 5; this.rtbScript.Text = "using System;\n\npublic class Demo\n{\n\tpublic static int X = 0;\n\n\tpub" + "lic static int Increase()\n\t{\n\t\treturn ++X;\n\t}\n\n\tpublic static voi" + "d Main(){}\n}"; // // label1 // this.label1.Location = new System.Drawing.Point(216, 16); this.label1.Name = "label1"; this.label1.TabIndex = 6; this.label1.Text = "Script"; // // CallMethodTest // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(528, 266); this.Controls.Add(this.label1); this.Controls.Add(this.rtbScript); this.Controls.Add(this.btnReset); this.Controls.Add(this.lbState); this.Controls.Add(this.tbState); this.Controls.Add(this.btnCallMethod); this.Name = "CallMethodTest"; this.Text = "Call method test"; this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new CallMethodTest()); } private void button1_Click(object sender, System.EventArgs e) { object result = paxScripter1.Invoke(RunMode.Run, null, "Demo.Increase"); MessageBox.Show("X = " + result); } private void btnReset_Click(object sender, System.EventArgs e) { paxScripter1.Reset(); } private void paxScripter1_OnChangeState(PaxScript.Net.PaxScripter sender, PaxScript.Net.ChangeStateEventArgs e) { tbState.Text = e.NewState.ToString(); if (e.OldState == ScripterState.Init) { sender.AddModule("1"); sender.AddCode("1", rtbScript.Text); } else if (sender.HasErrors) { MessageBox.Show(sender.Error_List[0].Message); } } } }