在TabStrip的特定选项卡中更改控件的值

时间:2022-03-06 03:56:26

Basically, I have a multipage for different departments of information called mpageTabsMain.

基本上,我有一个称为mpageTabsMain的不同信息部门的多页。

Inside each page of the multipage is a tabstrip, that contains tabs that represents different people.

在多页面的每个页面内都有一个标签条,其中包含代表不同人的标签。

What i'm doing for testing right now is using a button click to fill in a textbox's text on my 2nd page of the multipage.

我正在进行的测试现在是使用按钮单击来填充多页的第二页上的文本框文本。

mpageTabsMain.Pages(1).TextBox1.Text = "test"

However, what this does is it fills in the TextBox1's text for every Tab (person) in the TabStrip.

但是,它的作用是填充TabStrip中每个Tab(人物)的TextBox1文本。

How do I refer to a particular tab (person)'s control in a TabStrip so that only that one is filled?

如何在TabStrip中引用特定选项卡(人)的控件,以便只填充那个?

Thanks.

谢谢。

1 个解决方案

#1


1  

  • 1) You can't have the same control names within a UserForm.

    1)您不能在UserForm中具有相同的控件名称。

  • 2) If you want to handle different controls for each page (e.g. TextBox1 on page1, TextBox2 on page2) you should use a Multipage control and maybe this would be the better choice for your requirements.

    2)如果你想为每个页面处理不同的控件(例如第1页的TextBox1,第2页的TextBox2),你应该使用Multipage控件,这可能是你需求的更好选择。

  • 3) A Tabstrip control makes sense for pages with a similar or identical layout, but uses ONE set of controls only. So if you assign a value to your TextBox1.Text property without further conditions (i.e. distinguishing between the different kinds of pages) you'll get the same text for the same TextBox1 control independantly of which page you are addressing. Though a Tabstrip can possibly facilitate to write comparable code for only a few controls (distinguishing at which page you are), it could be the harder part to code.

    3)Tabstrip控件对于具有相似或相同布局的页面有意义,但仅使用一组控件。因此,如果您在没有其他条件的情况下为TextBox1.Text属性赋值(即区分不同类型的页面),您将获得相同TextBox1控件的相同文本,而与您要寻址的页面无关。虽然Tabstrip可能有助于为少数控件编写可比较的代码(区分你在哪个页面),但它可能是更难编码的部分。

Addendum (refers to comment below)

附录(参见下面的评论)

OK, you are using a TabStrip within a Multipage and apparently you want to display a tabstrip tab for every person. (BTW, I wouldn't do that, you could just change the tab name dynamically, but that isn't the question).

好的,你在Multipage中使用TabStrip,显然你想为每个人显示一个tabstrip标签。 (顺便说一句,我不会这样做,你可以动态地更改选项卡名称,但这不是问题)。

There is no more than one unique TextBox1 control in the whole UserForm. As TextBox1 is a unique Name, and instead your long code line it's sufficient to assign a string value via Me.TextBox1.Text = "test content for Person A" referring to a current tab view of Person A or TextBox1.Text = "test content for Person B" according to another tab view and another tab value. But it's the same TextBox1 in any case. Me stands for the UserForm itself inside the Userform code module. You only 'fake' the view to this text (control) depending on the tab situation and are responsible to write it back properly or save it according to the actual tab view :-;

整个UserForm中只有一个唯一的TextBox1控件。由于TextBox1是一个唯一的名称,而是您的长代码行,通过Me.TextBox1.Text =“人员A的测试内容”指定字符串值就足够了,指的是人员A的当前选项卡视图或TextBox1.Text =“test “人员B的内容”根据另一个选项卡视图和另一个选项卡值。但无论如何它都是相同的TextBox1。我代表Userform代码模块中的UserForm本身。您只需根据选项卡情况“伪造”该文本(控件)的视图,并负责将其正确写回或根据实际的选项卡视图保存: - ;

#1


1  

  • 1) You can't have the same control names within a UserForm.

    1)您不能在UserForm中具有相同的控件名称。

  • 2) If you want to handle different controls for each page (e.g. TextBox1 on page1, TextBox2 on page2) you should use a Multipage control and maybe this would be the better choice for your requirements.

    2)如果你想为每个页面处理不同的控件(例如第1页的TextBox1,第2页的TextBox2),你应该使用Multipage控件,这可能是你需求的更好选择。

  • 3) A Tabstrip control makes sense for pages with a similar or identical layout, but uses ONE set of controls only. So if you assign a value to your TextBox1.Text property without further conditions (i.e. distinguishing between the different kinds of pages) you'll get the same text for the same TextBox1 control independantly of which page you are addressing. Though a Tabstrip can possibly facilitate to write comparable code for only a few controls (distinguishing at which page you are), it could be the harder part to code.

    3)Tabstrip控件对于具有相似或相同布局的页面有意义,但仅使用一组控件。因此,如果您在没有其他条件的情况下为TextBox1.Text属性赋值(即区分不同类型的页面),您将获得相同TextBox1控件的相同文本,而与您要寻址的页面无关。虽然Tabstrip可能有助于为少数控件编写可比较的代码(区分你在哪个页面),但它可能是更难编码的部分。

Addendum (refers to comment below)

附录(参见下面的评论)

OK, you are using a TabStrip within a Multipage and apparently you want to display a tabstrip tab for every person. (BTW, I wouldn't do that, you could just change the tab name dynamically, but that isn't the question).

好的,你在Multipage中使用TabStrip,显然你想为每个人显示一个tabstrip标签。 (顺便说一句,我不会这样做,你可以动态地更改选项卡名称,但这不是问题)。

There is no more than one unique TextBox1 control in the whole UserForm. As TextBox1 is a unique Name, and instead your long code line it's sufficient to assign a string value via Me.TextBox1.Text = "test content for Person A" referring to a current tab view of Person A or TextBox1.Text = "test content for Person B" according to another tab view and another tab value. But it's the same TextBox1 in any case. Me stands for the UserForm itself inside the Userform code module. You only 'fake' the view to this text (control) depending on the tab situation and are responsible to write it back properly or save it according to the actual tab view :-;

整个UserForm中只有一个唯一的TextBox1控件。由于TextBox1是一个唯一的名称,而是您的长代码行,通过Me.TextBox1.Text =“人员A的测试内容”指定字符串值就足够了,指的是人员A的当前选项卡视图或TextBox1.Text =“test “人员B的内容”根据另一个选项卡视图和另一个选项卡值。但无论如何它都是相同的TextBox1。我代表Userform代码模块中的UserForm本身。您只需根据选项卡情况“伪造”该文本(控件)的视图,并负责将其正确写回或根据实际的选项卡视图保存: - ;