简体   繁体   English

无法从选定选项卡中获取 RichTextBox

[英]Impossible to get the RichTextBox from the Selected Tab

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.我的程序快完成了,它是一个多选项卡记事本,我无法开始保存活动选项卡的 RichTextBox。

Screenshot截屏

First tab has a RichTextBox called "BLACKTEXT" but the others are created dynamically by clicking "New".第一个选项卡有一个名为“BLACKTEXT”的 RichTextBox,但其他选项卡是通过单击“新建”动态创建的。

new tab + new rtb (picture)新标签+新RTB(图片)

When hitting 'Save', the RichTextBox of the SelectedTab has to be saved.点击“保存”时,必须保存 SelectedTab 的 RichTextBox。 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. 我将授予您为我修复它的选项 ([在此处下载.rar][3]) 并将其返回给我, 因为我已经日夜涉猎了一个星期,越来越沮丧,那将是不胜感激。

Thanks, linkings谢谢,链接

This code will get the one and only RichTextBox control from the currently selected TabPage of TabControl1 :此代码将从当前选择的TabControl1TabPage中获取唯一的RichTextBox控件:

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

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?是要保存richtextbox控件还是richtextbox控件的内容? 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:如果要保存的是richttextbox控件的内容,使用RichTextBox的.rtf属性,在要创建的文件上写入:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM