2017-02-11 11 views
-1

私は単純な電卓を作成したいと思います。ユーザがクリックした数を示すtextBoxを持っています。それぞれの数字は32桁です(MaxLengthプロパティは、ボタンではなくキーボードで入力した場合のみ機能します)。テキストボックスに表示できるボタンの数を制限したい

enter image description here

+0

を受け入れることから、テキストボックスを停止するためにこれをやりましたか?このロジックが実装されている場所のように見えます。 – David

+1

コードを表示する場合に役立ちます。 –

+0

[前回](http://stackoverflow.com/questions/42178197/)でこの質問をしましたが、提案された解決策ではクリップボードの番号を貼り付けることができず、[重複する質問](http: /stackoverflow.com/a/17893102/22437)、貼り付け番号の処理だけでなく、必要な処理も行います。 –

答えて

0

ボタンをクリックしたときにテキストをテキストに追加するので、テキストボックスに32文字以上の文字が含まれている場合はテキストを追加しないでください。もう1つは次のようなことです。長さが32になるとあなたは明らかにこれを行う必要

private void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    var box = sender as TextBox; 
    e.Handled = box.Text.Length == 32; 
} 

あなたがすることができる他の事は、すべてのボタンを無効にすることです:

はちょうどあなたがこのようにそれを処理しているイベントハンドラを伝えますKeyPressテキストボックスのイベントハンドラ。

0

あなたはその長さを確認してくださいテキストボックスに表示されている文字列に次の番号を追加する前に。大きすぎる場合は追加しないでください

0

うん、私はボタンが最初の場所でのテキストボックスに値を入れるにはどうすればよい以上9桁

private void button1_Click(object sender, EventArgs e) 
    { 
     if (textBox1.Text.Length < 9) 
     { 
      textBox1.Text += "1"; 
     } 
    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     if (textBox1.Text.Length < 9) 
     { 
      textBox1.Text += "2"; 
     } 

    } 

    private void button5_Click(object sender, EventArgs e) 
    { 
     if (textBox1.Text.Length < 9) 
     { 
      textBox1.Text += "5"; 
     } 
    } 

    private void button7_Click(object sender, EventArgs e) 
    { 
     if (textBox1.Text.Length < 9) 
     { 
      textBox1.Text += "7"; 

     } 
    } 

    private void button8_Click(object sender, EventArgs e) 
    { 
     textBox1.Text += "8"; 
    } 

    private void button9_Click(object sender, EventArgs e) 
    { 
     if (textBox1.Text.Length < 9) 
     { 
      textBox1.Text += "9"; 
     } 


    } 

    private void button4_Click(object sender, EventArgs e) 
    { 
     if (textBox1.Text.Length < 9) 
     { 
      textBox1.Text += "4"; 
     } 

    } 

    private void button6_Click(object sender, EventArgs e) 
    { 

     if (textBox1.Text.Length < 9) 
     { 
      textBox1.Text += "6"; 

     } 
    } 
    private void button3_Click(object sender, EventArgs e) 
    { 
     if (textBox1.Text.Length < 9) 
     { 
      textBox1.Text += "3"; 

     } 
    } 
関連する問題