如何在模块内部引用tabcontrol. [英] How to reference a tabcontrol inside a module.
问题描述
程序员,
请帮我解决这个小问题.
我正在开发一个具有多种形式的小型VB.NET项目.
每种形式都有一个私人子,类似于以下所示:
Hi programmers,
Please help me with this little problem.
I am developing a small VB.NET project which has several forms.
Each form has a private sub similar to the one shown below:
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.SelectedTab Is TabPage1 Then
If Estado1 = True Then
Cargador(Me)
Estado1 = False
End If
ElseIf TabControl1.SelectedTab Is TabPage2 Then
If Estado2 = True Then
Cargador(Me)
Estado2 = False
End If
ElseIf TabControl1.SelectedTab Is TabPage3 Then
If Estado3 = True Then
Cargador(Me)
Estado3 = False
End If
ElseIf TabControl1.SelectedTab Is tabpage_N Then
'etc...
Endif
End Sub
我在模块内有以下代码:
I have the following codes inside a module:
module module1
Public Sub Cargador(ByVal MyForm1 As Form)
ReDim CtlPlc(MyForm1.Tabcontrol1.SelectedTab.Controls.Count)
'codes to do something here
end sub
end module
如您所见,每个人都经常调用Cargador子例程.
形式.我知道我不能用简单的"Cargador(Me)"来称呼Cargador子.
我仍然需要为"TabControl1.SelectedTab"传递其他参数.
问题是我不知道如何在
中引用Tabcontrol1.SelectedTab
Cargador的子声明.
编译器在CtlPlc ReDim语句中突出显示"TabControl",并给我一个错误,指出:
As you can see, the Cargador subroutine is being called frequently from every
form. I know that I cannot call the Cargador sub with a simple ''Cargador (Me)''.
I still need to pass other argumments for the ''TabControl1.SelectedTab''.
The problem is that I don''t know how to reference Tabcontrol1.SelectedTab
in
the Cargador''s sub declaration.
The compiler highlights the ''TabControl'' in the CtlPlc ReDim statement and gives me an error that says:
TabControl1 is not a member of system.windows.forms.form
的成员
我是编程新手.任何帮助将不胜感激.
在此先感谢.
I am new to programming. Any help will be appreciated.
Thanks in advance.
推荐答案
首先,删除过程的一部分:If TabControl1.SelectedTab Is TabPage1 Then ... End if
并在此处查看:
First of all, remove the part of procedure:If TabControl1.SelectedTab Is TabPage1 Then ... End if
and take a look here:
If Estado1 = True Then
Cargador (TabControl1.SelectedPage)
Estado1 = False
End If
我什至看不到if
->的其余部分. else
.可能您可以使用它:
I haeven''t see the rest part of if
-> else
. Probably you can use it:
Cargador (TabControl1.SelectedPage)
Estado1 = Not Estado1
End If
更改后的Sub Cargador
可能如下所示:
Changed Sub Cargador
could see like this:
Public Sub Cargador(ByVal tp As TabPage)
ReDim CtlPlc(tp.Controls.Count)
'codes to do something here
End sub
现在我已经在模块以下:
Now I have inside the module the following:
module module1
Public Sub Cargador(ByVal TP As TabPage)
ReDim CtlPlc(TP.Controls.Count)
'codes to do something here
end sub
end module
From the main program I call this public sub with
Cargador((TabPage1)
Cargador((TabPage2)
Cargador((TabPage3)
etc...
It depends on the control I want to pass as the argument.
The error given previously by the compiler is gone.
The program works fine. No problem at all!!!
Thanks.
这篇关于如何在模块内部引用tabcontrol.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!