Home > Net >  Impossible to get the RichTextBox from the Selected Tab
Impossible to get the RichTextBox from the Selected Tab

Time:04-28

My program is almost finished, which is a multi-tabbed Notepad, and i can't get to work saving the RichTextBox of the active tab.

Screenshot

First tab has a RichTextBox called "BLACKTEXT" but the others are created dynamically by clicking "New".

new tab new rtb (picture)

When hitting 'Save', the RichTextBox of the SelectedTab has to be saved. I tried many answers in Google. I'll grant you the option to fix it for me ([download here.rar][3]) and return it back to me, because i've been dabbling around day and night for a week with increasing frustration and that would be greatly appreciated.

Thanks, linkings

CodePudding user response:

This code will get the one and only RichTextBox control from the currently selected TabPage of TabControl1:

Dim selectedRichTextBox = TableControl1.SelectedTab.
                                        Controls.
                                        OfType(Of RichTextBox)().
                                        Single()

CodePudding user response:

I can't fix it for you but maybe I could help. Do you want to save the richtextbox control or the content of the richtextbox control? If it's the content of richttextbox control that you want to save, use the .rtf property of the RichTextBox and write it on the file to be created:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    With SaveFileDialog1
        If .ShowDialog() = Windows.Forms.DialogResult.OK Then
            Call SaveRTF(.FileName)
        End If
    End With
End Sub

Private Sub SaveRTF(ByVal pSelectedPath As String)
    Dim newFile As String = pSelectedPath & ".rtf"
    File.AppendAllText(newFile, RichTextBox1.Rtf)
End Sub
  • Related