两个TextBox GotFocus()递归了. [英] Two TextBox GotFocus() got recursive.

查看:69
本文介绍了两个TextBox GotFocus()递归了.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我一直在研究Windows Mobile表单.我有一个带有两个文本框的Windows Mobile应用程序表单.

1.两个文本框值都是强制性的.
2.在编辑模式下,如果将TextBox1聚焦并使其为空,然后用户导航到TextBox2,则需要显示一条消息"TextBox1中的值是强制性的",并且控件需要将注意力集中在TextBox1上. 3.同样,如果填充了TextBox1并将焦点移至TextBox2,并且如果用户将焦点移至窗体上除TextBox1和TextBox2之外的其他任何位置,则应将TextBox2对准焦点,并显示一条消息,指出"TextBox1中的值是必需的" >
但是,当使用TextBox1_GotFocus()和TextBox2_GotFocus()实现此功能时,由于调用变为递归并引发了stackoverflow异常,我遇到了异常.

我怎么能克服这个.感谢您的帮助.

Hi,

I have been working on Windows Mobile Forms. I have a windows mobile application form with two textbox.

1. Both textbox value is mandatory.
2. At edit mode, if TextBox1 is focused and made empty and then user navigate to TextBox2 then there a message need to be shown "Value in TextBox1 is mandatory" and control needs to focus back on TextBox1.
3. Similarly if TextBox1 is filled and focus is shifted to TextBox2 and if user places focus to any other place on form except TextBox1 and TextBox2 then TextBox2 should be focused and a message to be shown as "Value in TextBox1 is mandatory"

But while implemeting this with TextBox1_GotFocus() and TextBox2_GotFocus() I got exception as the call becomes recursive and a stackoverflow exception is thrown.

How could I get over this. Any help is appreciated.

推荐答案

您只需将TextBox1&TextBox2强制设置为
即this.TextBox1.Imandatory = true;
this.TextBox2.Ismandatory = true;


要进行验证,您可以使用:
if(string.Isnullorempty(TextBox1.Text)|| string.Isnullorempty(Textbox2.Text))
{
this.GetDialogBox().Show(this,CustomDialogBox.DialogBoxType.OkDialog,您可以添加自己的注释");
this.texBox1.focus();
}

请寻找业务.
:)
you can simply make TextBox1& TextBox2 Mandatory
i.e this.TextBox1.Imandatory=true;
this.TextBox2.Ismandatory=true;


for validation you can use:
if(string.Isnullorempty(TextBox1.Text)||string.Isnullorempty(Textbox2.Text))
{
this.GetDialogBox().Show(this, CustomDialogBox.DialogBoxType.OkDialog, "you can add you own comment");
this.texBox1.focus();
}

Please look for busines.
:)


您需要在失去文本框焦点时验证数据输入,而不是在关注其他控件之后检查输入的数据.

尝试使用文本框的onBlur事件检查数据验证并重新关注失败.
You need to validate the data entry at the time of lost focus of textboxes instead of checking the data entered after focus on other control.

Try onBlur event of textbox to check data validation and re-focus on failure.


这篇关于两个TextBox GotFocus()递归了.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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