如何根据打开的选项卡保存带有选项卡的文本框? [英] How do I save textboxes with tabs depending which tab is open?

查看:48
本文介绍了如何根据打开的选项卡保存带有选项卡的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我决定添加一个选项卡控件,这样我就可以在按下按钮时创建一个新选项卡.我想将文本保存在打开的选项卡中.我创建了一个函数,根据打开的选项卡返回文本,但这仅适用于两个默认选项卡.如果我创建了一个新标签,我不知道如何保存.

So I decided to add a tab control, so I can create a new tab when I press a button. I would like to save the text in the tab that is open. I created a function the returns the text depending on what tab is open, but that only works for the two default tabs. I don't know how I would save if I've created a new tab.

获取文本的函数是这样的:

The function to get the text is this:

Public Function getText() As String
If tabPage1.Visible = True Then
Return mainText.Text
ElseIf tabPage2.Visible = True Then
Return textBox1.Text
End If
End Function

我在网上做了一些研究,我什至查看了 SharpDevelop 的源代码,但我找不到任何东西.提前致谢!

I've done some research online, I've even looked at SharpDevelop's source code and I couldn't find anything. Thanks in advance!

Public Sub setText(Byval value As String)
  If tabPage1.Visible = True Then
     mainText.Text = value
  ElseIf tabPage2.Visible = True Then
     textBox1.Text = value
  End If
End Sub

有谁知道我将如何根据打开的选项卡来确定打开的功能(和以前一样.)

Does anyone know how I would do an open feature determined on what tab is open (as before.)

推荐答案

如果我理解正确,您正试图在动态生成的每个 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

这篇关于如何根据打开的选项卡保存带有选项卡的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆