简体   繁体   English

访问TabPageControl中的动态创建的控件

[英]Access Dynamically Created Controls in a TabPageControl

I am creating a bunch of UserControls each in a tab in a TabControl. 我在TabControl的一个选项卡中创建了一堆UserControls。 The problem I'm having is I need to access a value from the controls. 我遇到的问题是我需要从控件中访问一个值。 I have no idea how to do this. 我不知道该怎么做。

string q;
foreach (TabPage tp in tabControler.TabPages)
{
    Filter f = tp.Controls.Find("Filter",true); //not working at all.
    q += f.querry;
}

When creating your control, add the name to it: 创建控件时,为其添加名称:

Filter Filter1 = new Filter();
Filter1.Name = "Filter1";

If this is WinForms and Filter1 is the name of the Filter control, it would just be: 如果这是WinForms,并且Filter1是Filter控件的名称,则它将是:

if (tp.Controls.ContainsKey("Filter1"))
{
  Filter selectedFilter = (Filter)tp.Controls["Filter1"];
} 
Debug.Write(selectedFilter.Value);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM