三国演义大全:C#中在两个窗体之间如何传递数值

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 06:18:18
大虾门,请问C#中在两个窗体之间如何传递数值,
我已经解决了这个问题.不过还是谢谢大家.

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();
}
}
}

C#跟JAVA根本就一样 还不如学JAVA