WinForm与Webform之间传值问题实例

winform 端:
System.Diagnostics.Process.Start(@"http://localhost:27389/Console.aspx?screencount=1"); //向指定webForm传值
webform 端:
int count = convert.toint32( Request.QueryString["screencount"]); //接受传过来的值


web 窗体 传值到 winform 窗体

Form.cs 文件:
public partial class Form : Form {
string name;
public Form(string str) {
InitializeComponent();
this.name = str;
}
private void Form_Load(object sender, EventArgs e)
{
this.button.Text = name;
}
}
Program.cs 文件:
namespace WindowsFormsApplication1

{
 static class Program { ///
 /// 应用程序的主入口点。
///  [STAThread]
static void Main(string [] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form(args[0]));
}
}
}
webForm.aspx.cs 文件内容
protected void Page_Load(object sender, EventArgs e) {
Process.Start(@"e:\testdemo.exe" "参数传值");

}


//Form1.Designer.cs

   ///


        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        ///

        private void InitializeComponent()
        {
            this.webBrowser2 = new System.Windows.Forms.WebBrowser();
            this.SuspendLayout();
            //
            // webBrowser2
            //
            this.webBrowser2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.webBrowser2.Location = new System.Drawing.Point(0, 0);
            this.webBrowser2.MinimumSize = new System.Drawing.Size(20, 20);
            this.webBrowser2.Name = "webBrowser2";
            this.webBrowser2.ScrollBarsEnabled = false;
            this.webBrowser2.Size = new System.Drawing.Size(331, 290);
            this.webBrowser2.TabIndex = 1;
            this.webBrowser2.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.webBrowser2_Navigated);
            //
            // Form2
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.ActiveCaption;
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.ClientSize = new System.Drawing.Size(331, 290);
            this.ControlBox = false;
            this.Controls.Add(this.webBrowser2);
            this.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Name = "Form2";
            this.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Text = "Form2";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_FormClosing);
            this.Load += new System.EventHandler(this.Form2_Load);
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form2_MouseDown);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form2_MouseMove);
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form2_MouseUp);
            this.ResumeLayout(false);

        }


你可能感兴趣的:(c#,.NET技术)