c#选中哪个选项卡页是文本框
我甚至不知道该由谁用我的英语来解释:)但我会试试 我有带3个TabPages的TabControl1(例如page1、page2、page3) 我执行了foreach循环以检查启用了哪些TextBox:c#选中哪个选项卡页是文本框,c#,foreach,tabcontrol,C#,Foreach,Tabcontrol,我甚至不知道该由谁用我的英语来解释:)但我会试试 我有带3个TabPages的TabControl1(例如page1、page2、page3) 我执行了foreach循环以检查启用了哪些TextBox: foreach (TabPage tp in tabControl1.TabPages) { foreach (Control textboxy in tp.Controls) { if (textboxy
foreach (TabPage tp in tabControl1.TabPages)
{
foreach (Control textboxy in tp.Controls)
{
if (textboxy is TextBox)
{
if (textboxy.Enabled)
{
if (!string.IsNullOrWhiteSpace(textboxy.Text))
{ ...
现在,我需要知道哪个选项卡页是我可以发送报告的文本框:
// ------ report ---------//
string userID = LoginForm.UserID;
string name;
string computerName = textboxy.Name;
string computer = computerName;
}
string whichTabPage = ...? ; <- HERE
(there is connectionstring)
...}
..}
报告必须包括:选项卡页面名称、启用的文本框名称和文本框中的文本。类似于此的内容
string whichTabPage=String.Empty;
foreach (TabPage tp in tabControl1.TabPages)
if (textboxy.Enabled)
{
whichTabPage = tp.Name;
}
next
如果愿意,您也可以使用
tp.Text
而不是tp.Name
,您还不能使用变量tp吗?哪个是你的标签页?tp.Name?只需将这一部分封装在一个函数中,然后返回tp
您所在的位置。就这样。谢谢你们的提示。我忘记了我的变量tp。我刚刚完成了tp.Name.ToString();这就是我所需要的:)谢谢。就像我在第一次评论中说的。我做到了:tp.Name.ToString();您不需要将ToString()与tp.Name一起使用,Name已经是一个string当我不使用ToString()时,它会显示:{TabName}但如果我添加ToString()结果是TabName。
string whichTabPage=String.Empty;
foreach (TabPage tp in tabControl1.TabPages)
if (textboxy.Enabled)
{
whichTabPage = tp.Name;
}
next