24.非模态对话框
所谓非模态对话框,是指当前对话框被弹出后,一直保留在屏幕上,用户可以进行其他的操作。
模态对话框使用ShowDialog()来显示,而非模态对话框使用Show()来显示。
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 WindowsFormsApplication24
{
public partial class Form1 : Form
{
private Form2 MdlessDlg;
public Form1()
{
InitializeComponent();
MdlessDlg = new Form2();
MdlessDlg.n_text = this.Text;
MdlessDlg.n_color = this.BackColor;
MdlessDlg.Owner = this;
}
private void button1_Click(object sender, EventArgs e)
{
if (MdlessDlg.Visible)
{
MdlessDlg.Hide();
button1.Text = "显示非模态对话框";
}
else
{
MdlessDlg.Show();
button1.Text = "隐藏非模态对话框";
}
}
}
}
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 WindowsFormsApplication24
{
public partial class Form2 : Form
{
private string text;
private Color color;
public Color n_color
{
set
{
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
if (value == Color.Red)
radioButton1.Checked = true;
if (value == Color.Yellow)
radioButton2.Checked = true;
if (value == Color.Blue)
radioButton3.Checked = true;
}
}
public string n_text
{
set
{
textBox1.Text = value;
}
}
public Form2()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
Form1 form1 = (Form1)this.Owner;
if (form1 != null)
{
form1.Text = textBox1.Text;
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
Form1 form1 = (Form1)this.Owner;
form1.BackColor = Color.Red;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
Form1 form1 = (Form1)this.Owner;
form1.BackColor = Color.Yellow;
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
Form1 form1 = (Form1)this.Owner;
form1.BackColor = Color.Blue;
}
}
}
}
本文出自 “郭俊的博客” 博客,转载请与作者联系!
原文地址:http://10093949.blog.51cto.com/10083949/1632580