本文共 3753 字,大约阅读时间需要 12 分钟。
private void Form2_Load(object sender, EventArgs e) { comboBox1.SelectedIndex = 0; textBox3.Text = ""; textBox1.Focus(); } |
public void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "") { MessageBox.Show("姓名,或者邮件信息禁止为空!", "信息提示"); } else { this.Hide(); Form3 childForm3 = new Form3(this.textBox1.Text, this.textBox2.Text, this.comboBox1.SelectedItem.ToString()); childForm3.Show(); } } |
public partial class Form3 : Form { private string _name; private string _emailId; private string _subject; private string _feedBack; //注意:在对Form3定义时候,明确指定了相关的参数。 public Form3(string varName, string varEmail, string varSubject, string varFeedBack) { InitializeComponent(); // 在 private 变量中存储值 this._name = varName; this._emailId = varEmail; this._subject = varSubject; this._feedBack = varFeedBack; // 在列表框中放置实例化后传来的参数值 listBox1.Items.Add("姓名:" + this._name); listBox1.Items.Add("邮件地址:" + this._emailId); listBox1.Items.Add("信息主题:" + this._subject); listBox1.Items.Add("反馈意见:" + this._feedBack); } //定义了关闭按钮鼠标单击事件 private void button1_Click(object sender, EventArgs e) { MessageBox.Show("感谢您输入的反馈!"); this.Close(); } } |
private void button1_Click_1(object sender, EventArgs e) { Form2 fm2 = new Form2(); Fm2.Show(); this.Close(); } |
public void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "") { MessageBox.Show("姓名,或者邮件信息禁止为空!", "信息提示"); } else { this.Hide(); Form3 childForm3 = new Form3(this.textBox1.Text, this.textBox2.Text, this.comboBox1.SelectedItem.ToString()); //上面为实例化Form3窗体,利用窗体参数传输数据。 //原来的代码内容:childForm3.Show(); //下面是更改后的代码内容 childForm3.MdiParent = this.MdiParent; //使得打开的窗体和当前窗体共同指向同一个父窗体 childForm3.Show(); } } |
private void button1_Click_1(object sender, EventArgs e) { Form2 fm2 = new Form2(); Fm2.MdiParent = this.MdiParent; //修改后的代码 Fm2.Show(); this.Close(); } |
private void menuItem3_Click(object sender, EventArgs e) { //直接检测是否已经打开此MDI窗体 // 是否已经打开了?(用循环来判断) foreach (Form childrenForm in this.MdiChildren) { //检测是不是当前子窗体名称 if (childrenForm.Name == "Formcc1") { //是的话就是把它显示 childrenForm.Visible = true; //并激活该窗体 childrenForm.Activate(); return; } } //下面是打开子窗体 Form2 Mdichild = new Form2();//首先实例化Form2对象,命名为Mdichild Mdichild.MdiParent = this; //其次指定即将打开的Form2对象的MdiParent,即Form2对象的MDI父窗口,为当前的主MDI窗口。 Mdichild.Show();//显示Form2对象的MDI父窗口 } |