C# 检查动态创建的 richtextbox 中的输入

C# Check input in dynamically created richtextbox

这是我的资料:

private void button1_Click(object sender, EventArgs e)
    {
        //Creating the RichTextBox
        RichTextBox rtb = new RichTextBox();
        rtb.Location = new Point(20, 20);
        rtb.Width = 400;
        rtb.Height = 300;
        rtb.BackColor = Color.White;
        rtb.Font = new Font("Mistral", 16, FontStyle.Regular);
        int size = rtb.TextLength;
        rtb.AcceptsTab = true;
        rtb.ScrollBars = RichTextBoxScrollBars.Both;
        rtb.ReadOnly = false;
        rtb.MaxLength = rtb.TextLength;
        rtb.ShortcutsEnabled = true;
        rtb.EnableAutoDragDrop = true;
        Controls.Add(rtb);
}

我想使用

将用户条目大写
string text = rtb.Text.ToUpper();
rtb.Text = text;
rtb.SelectionStart = rtb.Text.Length;

要做到这一点,我需要让用户不断进入 rtb.Text 我怎样才能做到这一点? 提前致谢。

有点乱:

 private void createDynamicRTB()
    {
        rtb.Location = new Point(20, 20);
        rtb.Width = 400;
        rtb.Height = 300;
        rtb.BackColor = Color.White;
        rtb.Font = new Font("Mistral", 16, FontStyle.Regular);
        int size = rtb.TextLength;
        rtb.AcceptsTab = true;
        rtb.ScrollBars = RichTextBoxScrollBars.Both;
        rtb.ReadOnly = false;
        rtb.MaxLength = rtb.TextLength;
        rtb.ShortcutsEnabled = true;
        rtb.EnableAutoDragDrop = true;
        Controls.Add(rtb);
    }
    RichTextBox rtb = new RichTextBox();
    private void button1_Click(object sender, EventArgs e)
    {
        //Capitalize
        rtb.Text = rtb.Text.ToUpper();


    }

或...

RichTextBox rtb = new RichTextBox();
    private void Form1_Load(object sender, EventArgs e)
    {
        createDynamicRTB();
        rtb.TextChanged += Rtb_TextChanged;//use this to capitalize after leaving
        rtb.KeyPress += Rtb_KeyPress;//use this to capitalize immediately
    }

    private void Rtb_KeyPress(object sender, KeyPressEventArgs e)
    {
        rtb.Text = rtb.Text.ToUpper();
    }

    private void Rtb_TextChanged(object sender, EventArgs e)
    {
        //Capitalize
        rtb.Text = rtb.Text.ToUpper();
    }

    private void createDynamicRTB()
    {
        rtb.Location = new Point(20, 20);
        rtb.Width = 400;
        rtb.Height = 300;
        rtb.BackColor = Color.White;
        rtb.Font = new Font("Mistral", 16, FontStyle.Regular);
        int size = rtb.TextLength;
        rtb.AcceptsTab = true;
        rtb.ScrollBars = RichTextBoxScrollBars.Both;
        rtb.ReadOnly = false;
        rtb.MaxLength = rtb.TextLength;
        rtb.ShortcutsEnabled = true;
        rtb.EnableAutoDragDrop = true;
        Controls.Add(rtb);
    }