且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何根据打开的选项卡保存带有选项卡的文本框?

更新时间:2022-06-13 05:16:44

如果我理解正确,您正试图在动态生成的每个 tabPage 中都有一个文本框.如果是这种情况,您可以使用此代码概括您的 GetText 函数

If I understand you correctly, you are trying to have a textbox in each of your tabPages generated dynamically. If this is the case you could generalize your GetText function with this code

Function GetText() As String
    If tabControl1.SelectedTab IsNot Nothing Then
        Return tabControl1.SelectedTab.Controls.OfType(Of TextBox)().First().Text
    End If

End Function

这要求您在每一页中至少有一个文本框(并且您的 TabControl 被命名为 tabControl1).SelectedTab 属性(如果不是什么都没有)是您的 tabControl 显示的当前 tabPage

This requires that you have at least one textbox in each page (and your TabControl is named tabControl1). The SelectedTab property (if not nothing) is the current tabPage displayed by your tabControl