减法键枚举是什么? [英] What is the subtract key enumeration?

查看:115
本文介绍了减法键枚举是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我一直试图找出我需要使用哪个号码,以便我的文本框允许输入负值。我已经尝试了所有我能找到的建议; 189,109和Key.Subtract,但这些都不适合我。



下面是我试图把它放在的代码。



有谁可以帮助我?



谢谢你和许多亲切的问候。



我尝试过:



Hi there,

I have been trying to find out which number I need to use in order for my text box to allow a negative value input. I've tried all the suggested ones I can find; 189, 109 and Key.Subtract, but none of these are working for me.

Below is the code in which I am trying to put it.

Can anyone please help me?

Thank you and many kind regards.

What I have tried:

char ch = e.KeyChar;

            if (!Char.IsDigit(ch) && ch != 8 && ch != 46 && ch != 110 && ch != 189 && ch != 13)
            {
                e.Handled = true;
                MessageBox.Show("Please Enter Valid Input");
            }

推荐答案

在if行上设置一个断点。

运行你的app在调试器中。

单击TextBox。

按' - '。

查看 ch的内容
Put a breakpoint on the "if" line.
Run your app in the debugger.
Click on the TextBox.
Press '-'.
Look at the content of ch


仅创建一个数字TextBox并不那么简单。



你有代码吗?从文本框处理复制和粘贴的地方?可能不是。



当然,你是限制按键,但是如何用非数字值粘贴?


箭头键怎么样?



删除和退格?



顺便说一下,您应该创建一个只接受值的新TextBox控件。我当然希望你不要将这些代码放在你的表格中。
Creating a numeric only TextBox isn't that simple.

Do you have code in place to handle copying and pasting from the textbox? Probably not.

Sure, you're limiting key presses, but how about pasting in a non-numeric value?

How about the arrow keys?

Delete and Backspace?

By the way, you should be making a new TextBox control that only accepts values. I sure hope you're not putting this code in your Form.


这篇关于减法键枚举是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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