我正在尝试访问位于TextBox
内Form
内的Panel
的{{1}}控件以及任何其他GroupBox
控件表格,但我无法访问它们。这就是我的尝试:
TextBox
答案 0 :(得分:2)
Yo可以创建一种方法来以这种方式查找控件的所有后代:
<!-- These do not need to be paragraphs. Any element will work as long as it has this class and a unique ID -->
<p class="tab-text" id="home">HOME TEXT!!!</p>
<p class="tab-text" id ="about">ABOUT TEXT!!!</p>
<h1>Little Shop </h1>
<ul id="tabs">
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
</ul>
<script>
// Run when document is ready
(function() {
// Find the UL parent of the tab links
var tabs = document.getElementById('tabs');
// Find all links inside it
var tabLinks = tabs.getElementsByTagName('a');
// Iterate through them and give them a click event handler
for (var i = 0; i < tabLinks.length; i++)
{
tabLinks[i].onclick = function() {
// Iterate over all the elements with a class of tab-text and hide them initially
[].forEach.call(document.getElementsByClassName("tab-text"), function(el) {
el.style.display = 'none';
});
// Then find the element whose ID matches the href attribute of the link clicked and show that
document.getElementById(this.href.split('#')[1]).style.display = 'block';
return false;
}
}
})();
</script>
然后,您可以使用它来查找表单的所有Private Function GetAllControls(control As Control) As IEnumerable(Of Control)
Dim controls = control.Controls.Cast(Of Control)()
Return controls.SelectMany(Function(ctrl) GetAllControls(ctrl)).Concat(controls)
End Function
后代:
TextBox