RichTextBox1激活,然后RichTextBox2处于非活动状态

时间:2016-03-08 20:12:36

标签: vb.net vb.net-2010

你能帮我设置RichTextBox的焦点吗?我正在尝试创建一个多个RichTextBox。当我打开文本文件时,使用了所有RichTextBox1,RichTextBox2和RichTextBox3。

我希望当RichTextBox1处于活动状态时,其他RichTextBox处于非活动状态并且不使用

我正试图将焦点设置为焦点,但我不知道如何使用它。

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    Try
        With OpenFileDialog1
            .Filter = "Text files(*.txt)|*.txt|" & "All files|*.*"
            If Not focussedrtb Is Nothing Then
                focussedrtb = rtb1
                .ShowDialog() = DialogResult.OK
                filename = .FileName
                sr = New StreamReader(.OpenFile)
                rtb1.Text = sr.ReadToEnd()
                rtb1.Focus()
                rtb1.Enabled = True
                rtb2.Enabled = False
            Else
                rtb2.Text = sr.ReadToEnd()
                rtb1.Enabled = False
                rtb2.Enabled = True
            End If
        End With
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        If Not (sr Is Nothing) Then
            sr.Close()
        End If
    End Try
End Sub

感谢您编辑我的问题。

1 个答案:

答案 0 :(得分:0)

如果您尝试将焦点设置为rtb1,请重新排序:

rtb1.Enabled = True
rtb2.Enabled = False
rtb1.Focus()

或实际上是其中一个

me.ActiveControl = rtb1

rtb1.Select(

**

<强>更新

**

    If Not focussedrtb Is Nothing Then
        focussedrtb = rtb1
        .ShowDialog() = DialogResult.OK
        filename = .FileName
        sr = New StreamReader(.OpenFile)
        rtb1.Text = sr.ReadToEnd()
        rtb1.Enabled = True
        rtb2.Enabled = False
        rtb1.Focus()
    Else
        rtb1.Enabled = False
        rtb2.Enabled = True
        rtb2.Text = sr.ReadToEnd()
    End If  

要解释您需要先启用才能将值放入文本框