我有一个 WinForms 应用程序。我希望能够在 form2 上按下一个按钮,然后该按钮将反映在 form1 上的 Richtextbox 上。
例如,如果 form2 上的按钮被编码为在单击时键入“Hello”,那么我希望“Hello”文本出现在 form1 上的 Richtextbox 上。
我该怎么做呢?我在网上搜索过,但找不到任何东西。
表格1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Text;
using System.Drawing.Printing;
using System.Diagnostics;
namespace Basic_Word_Processor_Version1._0._0
{
public partial class Form1 : Form
{
public Form1()
{
Instance = this;
}
private string filepath = null;
private int checkPrint;
代码
public static Form1 Instance { get; private set; }
// You still need this like in the first scenario.
public RichTextBox RichTextBox1 { get { return richTextBoxPrintCtrl1; } }
// This constructor should already exist. Just add the one line to it.
}
表格3
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 Basic_Word_Processor_Version1._0._0
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
Form1.Instance.richTextBoxPrintCtrl1.Text = "";
}
public partial class Form1 : Form
{
public static Form1 Instance { get; private set; }
public RichTextBox RichTextBox1 { get { return richTextBoxPrintCtrl1; } }
public Form1()
{
InitializeComponent();
Instance = this;
}
}