33.模态对话框
所谓模态对话框,就是指当有个对话框弹出的时候,用户必须在对话框中做出响应的操作,在退出对话框之前,鼠标不能单击对话框以外的位置。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication23
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.n_text = this.Text;
form2.n_color = this.BackColor;
form2.ShowDialog();
if ( form2.DialogResult == DialogResult.OK )
{
this.Text = form2.n_text;
this.BackColor = form2.n_color;
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication23
{
public partial class Form2 : Form
{
private Color color;
private string text;
public Form2()
{
InitializeComponent();
}
public Color n_color
{
get
{
return color;
}
set
{
this.color = value;
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
if ( color == Color.Red )
radioButton1.Checked = true;
if ( color == Color.Yellow )
radioButton2.Checked = true;
if ( color == Color.Blue )
radioButton3.Checked = true;
}
}
public string n_text
{
get
{
return text;
}
set
{
this.text = value;
textBox1.Text = text;
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if ( radioButton1.Checked )
color = Color.Red;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if ( radioButton2.Checked )
color = Color.Yellow;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
color = Color.Blue;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
text = textBox1.Text;
}
}
}