本文介绍了在Command Button的OnClick事件之后触发Textbox LostFocus事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! WINDOWS FORMS 我有一个包含文本框的表单,允许用户输入字符串。 在LostFocus事件中, textbox将字符串格式化为首选的 格式。 但是,如果用户按下保存字样。按钮,而文本框有焦点,LostFocus代码没有在正确的时间运行,所以 保存按钮函数正在处理格式错误的字符串和 整个caboodle会啪嗒一声。 我喜欢LostFocus事件,因为我已经超过了14在表单上的各个选项卡上的这些 文本框,它们可能包含不同的 字符串,但必须以正确的格式进行格式化。这是处理这个的 函数: Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object, ByVal e As System。 EventArgs)处理txtMonStartArbitrated.LostFocus, txtMonEndArbitrated.LostFocus,_ txtTueStartArbitrated.LostFocus,txtTueEndArbitrated.LostFocus,_ txtWedStartArbitrated.LostFocus,txtWedEndArbitrated .LostFocus,_ txtThurStartArbitrated.LostFocus,txtThurEndArbitrated.LostFocus, _ txtFriStartArbitrated.LostFocus,txtFriEndArbitrated.LostFocus,_ txtSatStartArbitrated.LostFocus,txtSatEndArbitrated.LostFocus,_ txtSunStartArbitrated.LostFocus,txtSunEndArbitrated.LostFocus Dim txtTextBox As TextBox = CType(sender,TextBox ) txtTextBox.Text = FormatArbTime(txtTextBox.Text) 结束子 任意想法? 爱德华 解决方案 WINDOWS FORMSI''ve a form that has a textbox that allows the user to enter a string.On the LostFocus event, the textbox formats the string into a preferredformat.However, if the user presses the "Save" button while the textbox hasthe focus, the LostFocus code doesn''t run at the right time, so thatthe "Save" function is dealing with an incorrectly formatted string andthe whole caboodle goes splat.I like the LostFocus event, because I''ve got upwards of 14 suchtextboxes on various tabs on the form, which all may contain differentstrings but must all be formatted in the correct format. Here is thefunction that handles this:Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,txtMonEndArbitrated.LostFocus, _txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,_txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocusDim txtTextBox As TextBox = CType(sender, TextBox)txtTextBox.Text = FormatArbTime(txtTextBox.Text)End SubAny thoughts?Edward 解决方案 这篇关于在Command Button的OnClick事件之后触发Textbox LostFocus事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-02 12:32