退格键 [英] back space

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

问题描述

在下面,我做了一个叫做baCK的键,空格.当您按下键时,应删除文本框中的最后一个字符.不是这种情况.实际上什么都没发生,为什么?

Below i made a key called baCK, space. When you hit the key the last char in the text box should be removed. this is not the case. in fact nothing happends why?

私有 无效 Backspace_ctl3dPushButton1_Click( 对象 发件人, EventArgs e)

private void Backspace_ctl3dPushButton1_Click(object sender, EventArgs e)

{

int g;

int g;

g = KeyBoard_textBox.Text.Length-1;

g = KeyBoard_textBox.Text.Length - 1;

如果 (g> 0)

if (g > 0)

{

KeyBoard_textBox.Text.Remove(g,1);

KeyBoard_textBox.Text.Remove(g , 1 );

g = KeyBoard_textBox.Text.Length;

g = KeyBoard_textBox.Text.Length;

推荐答案

您对Remove的调用将返回带有该字符串的新字符串字符已删除;但是,它不会更改原始字符串.要实现您想要的目标,您应该写:

Your call to Remove will return a new string with that character removed; it does not change the original string, though. To achieve what you want you should write:

KeyBoard_textBox.Text = KeyBoard_textBox.Text.Remove(g,1);

KeyBoard_textBox.Text = KeyBoard_textBox.Text.Remove (g, 1);

此外,除非您实际上打算在文本框中至少保留一个字符,否则您的支票应显示为:

Also, unless you actually intend to leave at least one character in your textbox, your check should read:

如果(g> = 0){

if (g >= 0) {

 

关于
--mc

Regards
--mc


这篇关于退格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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