111,056
社区成员




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private MyDialog m_dlg;
private void toolStripButton1_Click(object sender, EventArgs e)
{
MyDialog dlg = new MyDialog(richTextBox1.Text);
if (dlg.ShowDialog() == DialogResult.OK)
{
richTextBox1.Text = dlg.TextBoxValue;
}
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
if (m_dlg == null)
{
m_dlg = new MyDialog(richTextBox1.Text);
m_dlg.TextBoxChanged += new EventHandler(
(sender1, e1) =>
{ richTextBox1.Text = m_dlg.TextBoxValue; }
);
m_dlg.FormClosed += new FormClosedEventHandler(
(sender2, e2) => { m_dlg = null; }
);
m_dlg.Show(this);
}
else
{
m_dlg.Activate();
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class MyDialog : Form
{
public event EventHandler TextBoxChanged;
public string TextBoxValue
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
public MyDialog() : this("") { }
public MyDialog(string Param)
{
InitializeComponent();
TextBoxValue = Param;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (TextBoxChanged != null)
TextBoxChanged(this, e);
}
private void button1_Click(object sender, EventArgs e)
{
Close();
}
}
}