在Command Button的OnClick事件之后触发Textbox LostFocus事件 [英] Textbox LostFocus event fires after Command Button's OnClick event

查看:59
本文介绍了在Command Button的OnClick事件之后触发Textbox LostFocus事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)


结束子


任意想法?


爱德华

解决方案

Edward,


为什么不在保存按钮上将enabled属性设置为false,并在

上设置lostfocus事件,启用保存按钮,以及每个

文本框的getfocus,将保存按钮上的启用设置为false,直到填充文本框



-

Michael Bragg,总裁

eSolTec,Inc。

a 501(C)(3)组织
MS授权MAR

寻找用于发育障碍的二手笔记本电脑。

" te ******** @ hotmail.com"写道:


WINDOWS FORMS


我有一个包含文本框的表单,允许用户输入字符串。

在LostFocus事件中,文本框将字符串格式化为首选的

格式。


但是,如果用户按下保存按钮,而文本框有焦点,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)


结束子


任意想法?


Edward


尝试使用文本框'''验证'"事件......这就是它的用途,应该

工作。

-

丹尼斯在休斯顿

" eSolTec,Inc。501(c)(3)"写道:


Edward,


为什么不在保存按钮上设置启用属性为false

lostfocus事件,启用保存按钮,并在每个

文本框的gotfocus上,将保存按钮上的启用设置为false,直到文本框<是否填充了


-

Michael Bragg,总裁

eSolTec,Inc。

a 501(C)(3)组织

MS授权MAR

寻找用于发育障碍的二手笔记本电脑。


" ; TE ******** @ hotmail.com"写道:


WINDOWS FORMS


我有一个包含文本框的表单,允许用户输入字符串。

在LostFocus事件中,文本框将字符串格式化为首选的

格式。


但是,如果用户按下保存按钮,而文本框有焦点,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)


结束子


任意想法?


爱德华



te ******** @ hotmail.com 写道:

[snip]


谢谢,伙计们,我会给这些镜头。


爱德华


WINDOWS FORMS

I''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 preferred
format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn''t run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.

I like the LostFocus event, because I''ve got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function 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.LostFocus

Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward

解决方案

Edward,

Why don''t you set the enabled property to false on the save button and on
the lostfocus event, enable the save button, and on the gotfocus of each
textbox, set the enabled on the save button to false, until the textbox(es)
are populated?
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
"te********@hotmail.com" wrote:

WINDOWS FORMS

I''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 preferred
format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn''t run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.

I like the LostFocus event, because I''ve got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function 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.LostFocus

Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward


Try using the textbox''s "Validating" event..that''s what it is for and should
work.
--
Dennis in Houston
"eSolTec, Inc. 501(c)(3)" wrote:

Edward,

Why don''t you set the enabled property to false on the save button and on
the lostfocus event, enable the save button, and on the gotfocus of each
textbox, set the enabled on the save button to false, until the textbox(es)
are populated?
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
"te********@hotmail.com" wrote:

WINDOWS FORMS

I''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 preferred
format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn''t run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.

I like the LostFocus event, because I''ve got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function 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.LostFocus

Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward



te********@hotmail.com wrote:
[snip]

Thanks, guys, I''ll give these a shot.

Edward


这篇关于在Command Button的OnClick事件之后触发Textbox LostFocus事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆