そのため、C-Sharpで電卓アプリケーションに取り組んでおり、一度に複数のピリオド/ポイントを入力できないようにしたいと考えています。そのため、「.....」、「1..1」、「1.1.1」と入力することはできません。本当にそのようなものです。また、入力してアルファベット文字が追加されないようにします。キーボードでは、「a、b、c」のような文字。
MaskedTextBoxを使用するように言われましたが、それが正しいかどうか知りたいです。また、それが正しい場合、どのようにコードに実装しますか?私はC#に関しては完全な初心者なので、助けが必要です(初心者向けにトーンダウン)。
これまでのところ、私が書いたコードは次のとおりです。
double total1 = 0;
double total2 = 0;
public Form1()
{
InitializeComponent();
}
private void btnOne_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnOne.Text;
}
private void btnTwo_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnTwo.Text;
}
private void btnThree_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnThree.Text;
}
private void btnFour_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnFour.Text;
}
private void btnFive_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnFive.Text;
}
private void btnSix_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSix.Text;
}
private void btnSeven_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSeven.Text;
}
private void btnEight_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnEight.Text;
}
private void btnNine_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnNine.Text;
}
private void btnZero_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnZero.Text;
}
private void btnClear_Click(object sender, EventArgs e)
{
txtDisplay.Clear();
}
private void btnPlus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
}
private void btnEquals_Click(object sender, EventArgs e)
{
total2 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Text = total2.ToString();
total1 = 0;
}
private void btnPoint_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnPoint.Text;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void txtDisplay_TextChanged(object sender, EventArgs e)
{
}
}
だから私は尋ねます...この「MaskedTextBox」にどのように/どこに追加しますか-それが正しい場合は?どうすれば実装できますか?何がそれを機能させるのですか?
ありがとう!