2013-07-02 106 views
2

我有一個vb格式的2個文本框。如果txtMaterial是填充我想禁用txtPackage,反之亦然。我使用下面的代碼,但它不起作用。有人可以修復它。 真的很感激它。 TQ。如何從兩個文本框中禁用文本框?

Private Sub txtMaterial_TextChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterial.TextChanged 
    txtMaterial.Enabled = True 
    txtPackage.Enabled = False 

End Sub 

Private Sub txtPackage_TextChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPackage.TextChanged 

    txtPackage.Enabled = True 
    txtMaterial.Enabled = False 

End Sub 

回答

0
Private Sub txtMaterial_TextChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterial.TextChanged 
    If txtMaterial.Text <> "" Then 
     txtPackage.Enabled =False 
    End If 
End Sub 
+0

不要忘了「反之亦然」的條件...... –

+0

TQ但仍然沒有奏效。 – Husna5207

3

使這兩個文本框火一樣的處理,然後簡單地設置每一個基礎上的Enabled()狀態其它TextBox是否在它的東西:

Private Sub txtChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterial.TextChanged, txtPackage.TextChanged 
    txtMaterial.Enabled = (txtPackage.TextLength = 0) 
    txtPackage.Enabled = (txtMaterial.TextLength = 0) 
End Sub 

*注第一行的結尾有兩個控件,最後用Handles txtMaterial.TextChanged, txtPackage.TextChanged列出。

+0

tq但仍然沒有工作。 – Husna5207

+0

它適合我,但我知道我**期待的是什麼。可以給出更多關於它是如何「不工作」的**你**?... –

+0

我想要這樣的東西,>> http://www.google.com.my/imgres?hl=en&biw= 1600波黑= 799&TBM = isch&tbnid = SNr1zLuM77_oJM:&imgrefurl = HTTP://www.codeproject.com/Articles/9952/ComboBox-with-read-only-behavior&docid=LKR5Ftbkgk0AGM&imgurl=http://www.codeproject.com/KB/combobox/ ReadOnlyComboBoxByClaudio/ReadOnlyComboBox1.gif&w = 248&h = 144&ei = R5PTUcPLIeOoiAeEsIHIDw&zoom = 1&ved = 1t:3588,r:0,s:0,i:80&iact = rc&page = 1&tbnh = 115&tbnw = 198&start = 0&ndsp = 18&tx = 109&ty = 42 – Husna5207

0

根據您添加

大段引用我希望把它作爲禁用第二個註釋。但在我的情況下,如果我填寫txtMaterial txtPackage也可以同時填充文本。

解決您的問題一定是這樣的:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    txtPackage.Enabled = False 
End Sub 


Private Sub txtMaterial_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterial.TextChanged 
    If Not String.IsNullOrEmpty(txtMaterial.Text) Then 
     txtPackage.Enabled = True 
    Else 
     txtPackage.Enabled = False 
    End If 
End Sub