VB.NET はわかりませんが、C# でこのコードを作成しました。このコードは、 aに空の aTabPage
が含まれているかどうかを確認します。TextBox
VB.NET の言語を知っていれば、VB.NET に翻訳するのは簡単だと思います。
TabPage に空の TextBox が含まれているかどうかを確認する関数を次に示します。この関数は、TabPage をパラメーターとして受け取り、true
またはを返しますfalse
。
private bool ContainsEmptyTextBox(TabPage tp)
{
bool foundTextBox = false;
bool textBoxIsEmpty = false;
foreach (Control c in tp.Controls)
{
if (c is TextBox)
{
foundTextBox = true;
TextBox tb = c as TextBox;
if (String.IsNullOrEmpty(tb.Text))
{
textBoxIsEmpty = true;
}
break;
}
}
if (foundTextBox == true && textBoxIsEmpty == true)
return true;
else
return false;
}
そして、その関数を使用して a 内のすべてのタブを反復処理し、どのタブにTabControl
空の TextBox が含まれているかを確認する方法を次に示します。
private void button1_Click(object sender, EventArgs e)
{
foreach (TabPage tp in tabControl1.TabPages)
{
if (ContainsEmptyTextBox(tp))
{
// This tabpage contains an empty textbox
MessageBox.Show(tabControl1.TabPages.IndexOf(tp) + " contains an empty textbox");
}
}
}
編集:このサイトを使用して、C# コードを VB.NET に自動的に変換しました。
Private Function ContainsEmptyTextBox(tp As TabPage) As Boolean
Dim foundTextBox As Boolean = False
Dim textBoxIsEmpty As Boolean = False
For Each c As Control In tp.Controls
If TypeOf c Is TextBox Then
foundTextBox = True
Dim tb As TextBox = TryCast(c, TextBox)
If [String].IsNullOrEmpty(tb.Text) Then
textBoxIsEmpty = True
End If
Exit For
End If
Next
If foundTextBox = True AndAlso textBoxIsEmpty = True Then
Return True
Else
Return False
End If
End Function
Private Sub button1_Click(sender As Object, e As EventArgs)
For Each tp As TabPage In tabControl1.TabPages
If ContainsEmptyTextBox(tp) Then
' This tabpage contains an empty textbox
MessageBox.Show(tabControl1.TabPages.IndexOf(tp) & " contains an empty textbox")
End If
Next
End Sub