-1

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

linkings
  • 3
  • 3
  • I suggest that you take a look at [this](https://www.vbforums.com/showthread.php?506103-Tabbed-WebBrowser-a-work-in-progress). It's a web browser rather than a text editor but it demonstrates the principle that you're trying to implement. You can do basically the same thing with a `RichTextBox` control that I did with a `WebBrowser` control. – John Apr 28 '22 at 01:18
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 28 '22 at 02:10
  • Generally Stack Overflow requires people to post their code in the question. I think maybe I can see why you didn't though, `Dim HOLYSHIT As New RichTextBox()`; I'm not anti-fun or anything but you might have an easier time troubleshooting your code if you thought a little more about variable names. – jrh Apr 28 '22 at 02:26
  • jrh - Yikes, you found the "easter egg"... oops! It's just personal shenanigans to understand my variables as a beginner. I got confused after a while with names like "NewThis" or "NewThat"... otherwise, apologies for the rookie moves! – linkings Apr 28 '22 at 02:43
  • OK, I think you're getting better with the whole "show your code" thing. Stack Overflow requires users to put the code *in their post* though, not as an image. Paste code in a triple backticks block, see this link: https://stackoverflow.com/help/formatting – jrh Apr 28 '22 at 21:28
  • ..must have been sheer muscle memory from the UnrealEngine AnswerHub, where pictures are in fact posted into the question (to address issues regarding blueprint visual coding).. – linkings Apr 29 '22 at 01:09
  • @linkings the problem isn't that the picture isn't included with the post, it's that SE readers want to be able to copy/paste your code into their computer to examine it and find the problem, among other things (e.g., making it so blind people can still understand posts, SE does have sight impaired users). If you just post a screenshot we'd have to manually transcribe it back to text. – jrh May 01 '22 at 19:24

2 Answers2

0

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()
John
  • 3,057
  • 1
  • 4
  • 10
  • John, thanks a lot! It finally WORKS! I was pulling my hair out the whole week because it was such a simple logic that i couldn't solve. Thanks again. – linkings Apr 28 '22 at 02:27
0

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
casa
  • 61
  • 2
  • The issue seems solved for now, thanks, the save process is pretty much similar to that in another project. I decided to use .rtf since .txt doesn't include line breaks for some reason. Leaving this here as an alternative. – linkings Apr 28 '22 at 02:58