-1
在Form1如何将字符串从新窗体传递给form1 richtextbox?
private void button4_Click(object sender, EventArgs e)
{
AddText at = new AddText();
at.Show();
richTextBox2.Text = at.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 test
{
public partial class AddText : Form
{
public string text = "";
public AddText()
{
InitializeComponent();
}
private void AddText_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
text = textBox1.Text;
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
当我在新的形式,它从分配给textBox1
可变文本的文字点击button1
。
但它没有传递给Form1.richTextBox2
。 我想这个问题是我尝试在文本中的按钮单击事件在指定Form1
:
richTextBox2.Text = at.text;
但在新的形式按钮Click
事件之前发生这种情况。 Form1
我应该在richTextBox2
的文本中指定文本的位置/方式?
我用ShowDialog()
它只有当我关闭新窗体窗口时才起作用。只有当我关闭它时,才会看到richTextBox2
中的文字。但是我想看到richTextBox2
中的文本,当我单击确定(button1)按钮而不关闭窗体。