帮助在文本框中没有给出输入键盘字符 [英] help for no give input keybord character in textbox
本文介绍了帮助在文本框中没有给出输入键盘字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
namespace shuvo
{
public partial class Form1 : Form
{
bool div = false;
bool equal = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "0";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "1";
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "2";
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "3";
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "4";
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "5";
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "6";
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "7";
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "8";
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "9";
}
private void button11_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("."))
{
return;
}
else
{
textBox1.Text = textBox1.Text + ".";
}
}
private void buttondiv_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}
else
{
div = true;
textBox1.Tag = textBox1.Text;
textBox1.Text = "";
}
}
private void button14_Click(object sender, EventArgs e)
{
}
private void button13_Click(object sender, EventArgs e)
{
}
private void buttonequal_Click(object sender, EventArgs e)
{
equal=true;
if (div)
{
decimal doc = Convert.ToDecimal(textBox1.Tag) / Convert.ToDecimal(textBox1.Text);
textBox1.Text = doc.ToString();
}
}
}
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "9";
}
private void button11_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("."))
{
return;
}
else
{
textBox1.Text = textBox1.Text + ".";
}
}
private void buttondiv_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}
else
{
div = true;
textBox1.Tag = textBox1.Text;
textBox1.Text = "";
}
}
private void button14_Click(object sender, EventArgs e)
{
}
private void button13_Click(object sender, EventArgs e)
{
}
private void buttonequal_Click(object sender, EventArgs e)
{
equal=true;
if (div)
{
decimal doc = Convert.ToDecimal(textBox1.Tag) / Convert.ToDecimal(textBox1.Text);
textBox1.Text = doc.ToString();
}
}
}
}
推荐答案
您似乎正在尝试编写一个计算器,并使用文本框作为结果显示.如果是这样,那么我假设您要对其进行安排,以使用户无法在文本框中键入内容?
如果是这种情况,那么有两种方法可以做到:
1)不要使用文本框:用户希望输入文本框,因此使用他们不能混淆的文本框.请改用标签.
2)将TextBox的ReadOnly
属性设置为true
It looks like you are trying to write a calculator, and use a textbox as the results display. If so, then I assume you want it arranged so that the user cannot type into the textbox?
If that is the case, then there are two ways to do it:
1) Don''t use a text box: users expect to type in them, so using one they can''t could be confusing. Use a Label instead.
2) Set theReadOnly
property of the TextBox totrue
仅需注意:谁需要所有带有按钮的计算器?仅当这是一个(不良)学校项目分配…
在现实生活中,这就是简单的计算器应该做的: http://www.sakryukov.org/freeware/calculator/ [ ^ ].
只需一个文件.
—SA
Just a note: who needs all those calculators with buttons? Only if it is a (bad) school project assignmnt…
In real life, this is what a simple calculator should do: http://www.sakryukov.org/freeware/calculator/[^].
Just one file.
—SA
这篇关于帮助在文本框中没有给出输入键盘字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文