2017-06-03 16 views
0

私は3つのタブのtabcontrolを持っており、それぞれのタブにはテキストボックスが含まれています。各タブのすべてのテキストボックスとボタンを1回クリックするだけです(ボタンイベントまたはすべてのテキストボックスを消去する別の方法)vb.netのtabcointrolsでテキストボックスをクリアする

私はすでに多くのようなものになりますのみ

Private Sub ClearFields(ByVal cntr As Control) 
    For Each page As TabPage In TabControl1.TabPages 
     For Each ctl As Control In page.Controls 
      If TypeOf ctl Is TextBox Then 
       ctl.Text = "" 
      End If 
      If TypeOf ctl Is ComboBox Then 
       ctl.Text = "" 
      End If 
      If ctl.HasChildren Then 
       For Each thing As Control In ctl.Controls 
        If TypeOf thing Is TextBox Then 
         thing.Text = "" 
        End If 
       Next 
      End If 
     Next 
    Next 
End Sub 
+0

TabControl1.ClearSpecificControls 

クリアすべてのコントロールは、ちょうど約事のこのタイプ – Plutonix

答えて

0

最初のタブのための唯一の効果的なことが多くのコードを試してみました:ここ

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    ClearTabControl(TabControl1) 
End Sub 

Private Sub ClearTabControl(ByVal tb As TabControl) 
    For Each page As TabPage In TabControl1.TabPages 
     ClearFields(page) 
    Next 
End Sub 

Private Sub ClearFields(ByVal cntr As Control) 
    For Each ctl As Control In cntr.Controls 
     If TypeOf ctl Is TextBox OrElse TypeOf ctl Is ComboBox Then 
      ctl.Text = "" 
     ElseIf ctl.HasChildren Then 
      ClearFields(ctl) 
     End If 
    Next 
End Sub 
+0

おかげでたくさんの** **関連取引の下にリストされているすべてのポストは、plzは私を覚えています。 – babin

0

がanotです彼女の方法は言語拡張方法としてセットアップされています。新しいコードモジュールを作成し、デフォルトコードを以下のコードに置き換えます。

Public Module ControlExtensions 
    <Runtime.CompilerServices.Extension()> 
    Public Sub ClearSpecificControls(ByVal sender As Control) 
     Dim currentControl As Control = sender.GetNextControl(sender, True) 
     Dim cboControl As ComboBox = Nothing 

     Do Until currentControl Is Nothing 
      If TypeOf currentControl Is TextBox Then 
       currentControl.Text = "" 
      ElseIf TypeOf currentControl Is ComboBox Then 
       cboControl = CType(currentControl, ComboBox) 
       If cboControl.DataSource IsNot Nothing Then 
        cboControl.DataSource = Nothing 
       Else 
        cboControl.Items.Clear() 
       End If 
      End If 
      currentControl = sender.GetNextControl(currentControl, True) 
     Loop 
    End Sub 
End Module 

TabControl1内のすべてのTextBoxコントロールとComboBoxコントロールをクリアします。あなたが助けを必要とするたびに、フォーム

ClearSpecificControls 
関連する問題