计算器的后退空间不起作用 [英] Calculator's back space does not work

查看:66
本文介绍了计算器的后退空间不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#创建一个计算器,我只希望我的退格键可以在textBoxes上工作.
我有一个应该执行退格功能的按钮.

I am creating a calculator using c#, I just want that my backspace should work on textBoxes.
I have a button that should performs functionality of backspace.

推荐答案

退格字符确实适用于所有文本框,除非您处理了一些防止这种情况的事件.
您需要显示代码片段以获取更多帮助.

请参阅我对其他问题的回答(如何保存变量中包含2个值 [
Backspace character does work on all text boxes unless you handled some event to prevent that.
You need to show a fragment of you code to get further help.

Please see my Answer to your other Question (How to save 2 values in a variable[^]) and thing thoroughly: you need to select much easier coding tasks as you only start programming and still have to learn the very basic idea.

See my separate Answer done after clarification by OP.

—SA


我希望您正在使用 System.Windows.Forms.Keys.Back键代码来处理退格.
I hope you are handling backspace using the System.Windows.Forms.Keys.Back keycode.


回答后续问题:

这是模拟退格键的方法之一:

Answering a follow-up Question:

This is one of the ways to emulate backspace:

myButton.Click += (sender, eventArgs) => {
    myTextBox.Focus();
    Application.DoEvents();
    SendKeys.Send("{BACKSPACE}");
};



警告!避免在其他情况下使用Application.DoEvents;一个常见的错误是定期将其作为线程的肮脏替代品.

没有SendKeys:
的变体



Warning! Avoid using Application.DoEvents for other cases; one common mistake is doing it periodically as a dirty substitute of threading.

A variant without SendKeys:

myButton.Click += (sender, eventArgs) => {
int currentPosition = myTextBox.SelectionStart;
if (currentPosition > 0)
    myTextBox.Text = myTextBox.Text.Remove(currentPosition - 1, 1);
};



—SA



—SA


这篇关于计算器的后退空间不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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