首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C# winform - InputScope的等价物

C# winform - InputScope的等价物
EN

Stack Overflow用户
提问于 2019-04-04 01:53:32
回答 1查看 161关注 0票数 0

Winform (UWP4.0)中是否有等同于.Net中InputScope的属性?

EN

回答 1

Stack Overflow用户

发布于 2019-04-04 02:33:52

不,我不这么认为。您需要使用验证事件

例如,如果你想确保文本框中包含一封电子邮件,你可以这样做:

代码语言:javascript
复制
private void textBox1_Validating(object sender, 
            System.ComponentModel.CancelEventArgs e)

{
   string errorMsg;
   if(!ValidEmailAddress(textBox1.Text, out errorMsg))
   {

  // Cancel the event and select the text to be corrected by the user.
  e.Cancel = true;
  textBox1.Select(0, textBox1.Text.Length);

  // Set the ErrorProvider error with the text to display. 
  this.errorProvider1.SetError(textBox1, errorMsg);


}
}

private void textBox1_Validated(object sender, System.EventArgs e)
{
   // If all conditions have been met, clear the ErrorProvider of errors.
   errorProvider1.SetError(textBox1, "");
}
public bool ValidEmailAddress(string emailAddress, out string errorMessage)
{
   // Confirm that the email address string is not empty.
   if(emailAddress.Length == 0)
   {
      errorMessage = "email address is required.";
         return false;
   }



     // Confirm that there is an "@" and a "." in the email address, and in the correct order.

   if(emailAddress.IndexOf("@") > -1)
   {
      if(emailAddress.IndexOf(".", emailAddress.IndexOf("@") ) > emailAddress.IndexOf("@") )
      {
         errorMessage = "";
         return true;
      }
   }

   errorMessage = "email address must be valid email address format.\n" +
      "For example 'someone@example.com' ";
      return false;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55501368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档