VB.NET 输入框 - 如何识别何时按下取消按钮? [英] VB.NET Inputbox - How to identify when the Cancel Button is pressed?

查看:34
本文介绍了VB.NET 输入框 - 如何识别何时按下取消按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 Windows 应用程序,它会弹出一个输入框,供用户输入日期进行搜索.

I have a simple windows application that pops up an input box for users to enter in a date to do searches.

我如何确定用户是点击了取消"按钮,还是仅仅按下了确定"而不输入任何数据,因为两者似乎都返回了相同的值?

How do I identify if the user clicked on the Cancel button, or merely pressed OK without entering any data as both appear to return the same value?

我找到了一些在 VB 6 中处理这个问题的例子,但它们都没有在 .NET 世界中真正起作用.

I have found some examples of handling this in VB 6 but none of them really function in the .NET world.

理想情况下,我想知道如何分别处理空的 OK 和 Cancel,但只要有一个处理取消的好方法我就完全可以了.

Ideally I would like to know how to handle the empty OK and the Cancel seperately, but I would be totally ok with just a good way to handle the cancel.

推荐答案

这是我所做的,它非常适合我想要做的事情:

Here is what I did and it worked perfectly for what I was looking to do:

Dim StatusDate As String
 StatusDate = InputBox("What status date do you want to pull?", "Enter Status Date", " ")

        If StatusDate = " " Then
            MessageBox.Show("You must enter a Status date to continue.")
            Exit Sub
        ElseIf StatusDate = "" Then
            Exit Sub
        End If

这个键是将输入框的默认值设置为一个实际的空格,所以用户只按确定按钮将返回值"",而按取消返回"

This key was to set the default value of the input box to be an actual space, so a user pressing just the OK button would return a value of " " while pressing cancel returns ""

从可用性的角度来看,输入框中的默认值开始突出显示,并在用户键入时清除,因此体验与该框没有值时没有什么不同.

From a usability standpoint, the defaulted value in the input box starts highlighted and is cleared when a user types so the experience is no different than if the box had no value.

这篇关于VB.NET 输入框 - 如何识别何时按下取消按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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