3个回答
展开全部
Form1.cs
private void button1_Click(object sender, System.EventArgs e)
{
string Name = textBox1.Text;
string Subject = comboBox1.SelectedItem.ToString();
string Symbol = comboBox2.SelectedItem.ToString();
AnotherForm form = new AnotherForm(Name, Subject, Symbol);
//form.Show(); // To show the form modelessly
form.ShowDialog(); // To show the form modally
}
============================================
AnotherForm.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsApplication12
{
/// <summary>
/// Summary description for AnotherForm.
/// </summary>
public class AnotherForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private string studentName;
private string studentSubject;
private string studentSymbol;
public AnotherForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
public AnotherForm(string N, string Sub, string Symbol)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
studentName = N;
studentSubject = Sub;
studentSymbol = Symbol;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(184, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 40);
this.label1.TabIndex = 0;
this.label1.Text = "RESULTS";
//
// label2
//
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label2.Location = new System.Drawing.Point(64, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(360, 160);
this.label2.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 264);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 32);
this.button1.TabIndex = 2;
this.button1.Text = "Close";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// AnotherForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(488, 326);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "AnotherForm";
this.Text = "AnotherForm";
this.Load += new System.EventHandler(this.AnotherForm_Load);
this.ResumeLayout(false);
}
#endregion
private void AnotherForm_Load(object sender, System.EventArgs e)
{
string disp = "";
disp = studentName;
if ((studentSubject.Equals("Mathematics")) && (studentSymbol.CompareTo("C") <= 0))
{
disp += " is conditionally accepted to study IT at CPUT";
}
else
{
disp += " is NOT accepted to study IT at CPUT";
}
label2.Text = disp;
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Dispose();
}
}
}
private void button1_Click(object sender, System.EventArgs e)
{
string Name = textBox1.Text;
string Subject = comboBox1.SelectedItem.ToString();
string Symbol = comboBox2.SelectedItem.ToString();
AnotherForm form = new AnotherForm(Name, Subject, Symbol);
//form.Show(); // To show the form modelessly
form.ShowDialog(); // To show the form modally
}
============================================
AnotherForm.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsApplication12
{
/// <summary>
/// Summary description for AnotherForm.
/// </summary>
public class AnotherForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private string studentName;
private string studentSubject;
private string studentSymbol;
public AnotherForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
public AnotherForm(string N, string Sub, string Symbol)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
studentName = N;
studentSubject = Sub;
studentSymbol = Symbol;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(184, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 40);
this.label1.TabIndex = 0;
this.label1.Text = "RESULTS";
//
// label2
//
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label2.Location = new System.Drawing.Point(64, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(360, 160);
this.label2.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 264);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 32);
this.button1.TabIndex = 2;
this.button1.Text = "Close";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// AnotherForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(488, 326);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "AnotherForm";
this.Text = "AnotherForm";
this.Load += new System.EventHandler(this.AnotherForm_Load);
this.ResumeLayout(false);
}
#endregion
private void AnotherForm_Load(object sender, System.EventArgs e)
{
string disp = "";
disp = studentName;
if ((studentSubject.Equals("Mathematics")) && (studentSymbol.CompareTo("C") <= 0))
{
disp += " is conditionally accepted to study IT at CPUT";
}
else
{
disp += " is NOT accepted to study IT at CPUT";
}
label2.Text = disp;
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Dispose();
}
}
}
参考资料: http://zhidao.baidu.com/question/10651785.html?si=2
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
就可以了,这属于窗体间参数传递,有很多的方法!
其中一个
A窗口
在A:窗口中public string PublicString;
B窗口
调用A
A a=new A();
a.PublicString="自定义变两";
a.show();
其中一个
A窗口
在A:窗口中public string PublicString;
B窗口
调用A
A a=new A();
a.PublicString="自定义变两";
a.show();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询