我动态地创建了2个元素。现在,我想在事件onChange上将数据从richTextBox复制到WebBrowser
动态创建数据时如何将数据从richTextBox复制到WebBrowser?
我的代码
void OpenFile(string path, string filename)
{
StreamReader read = new StreamReader(path);
if(richTextBox1.Text.Length == 0)
{
return;
}
else
{
TabPage tp = new TabPage();
int tc = tabControl1.TabCount + 1;
tp.Text = filename;
tabControl1.TabPages.Add(tp);
RichTextBox rtb = new RichTextBox();
WebBrowser wb = new WebBrowser();
rtb.Width = tp.Width / 2;
rtb.Height = tp.Height;
rtb.TextChanged += new System.EventHandler(setText);
rtb.Text = read.ReadToEnd();
wb.Left = tp.Width / 2;
wb.Width = tp.Width / 2;
wb.Height = tp.Height;
tp.Controls.Add(rtb);
tp.Controls.Add(wb);
return;
}
}
private void setText(object sender, EventArgs e)
{
MessageBox.Show("TEXT CHANGED");
}
答案 0 :(得分:2)
尝试一下
rtb.TextChanged += (s, e) => { wb.DocumentText = rtb.Text; };