我在更新表单上的vb.net应用程序中使用富文本框来获取地址值。我的更新查询是在运行时生成的,它循环遍历表单上的文本框,并检查哪些字段具有某些值,并在数据库中更新相应的字段。在vb.net的富文本框中检查文本
For Each x As Control In Me.Controls
If x.GetType Is GetType(TextBox) Or x.GetType Is GetType(MaskedTextBox) Or x.GetType Is GetType(RichTextBox) Then
If Not x.Name = "party_code" Then
'if user has not entered a value in a textbox then incremnets the flag variable
If (x.Text = String.Empty) Or ((x.Name = "contact1" Or x.Name = "contact2" Or x.Name = "ptcl") And (x.Text.Trim().EndsWith("-") And x.Text.Trim().StartsWith("-"))) Then
flag += 1
End If
'checks if the user has entered a value in some textbox
If (Not x.Text = String.Empty And Not x.Name = "contact1" And Not x.Name = "contact2" And Not x.Name = "ptcl") Or ((x.Name = "contact1" Or x.Name = "contact2" Or x.Name = "ptcl") And Not x.Text.Trim.EndsWith("-")) Then
'generates query text for the textbox which contains some value
str = str & comma & x.Name & " = @" & x.Name
comma = " , "
End If
End If
End If
Next
我还使用Enter键将焦点移到窗体上的下一个文本框。当焦点到达地址富文本框,我不必更新数据库中的地址字段,我按Enter键移动到下一个文本框,然后上面的代码跟踪该地址富文本框已获得一些新的价值,即输入密钥,并更新地址字段在数据库中。我怎样才能摆脱这个问题?
后面转移焦点代码:
Private Sub town_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles town.KeyDown
If e.KeyData = Keys.Return Then
address.Focus()
End If
End Sub
Private Sub address_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles address.KeyDown
If e.KeyData = Keys.Return Then
Button3.Focus()
End If
End Sub
我已经通过keydown事件处理它..!
显然你的“转移重心上回车键”的代码被打破。你没有发布它,但我的水晶球说你忘了使用Handled或SuppressKeyPress属性。 – 2011-12-27 15:37:43
我已经在keydown事件中添加了处理焦点转移的代码...请现在 – user944591 2011-12-27 18:18:18