2016-08-20 1 views
0

私は新しいです、私はここで例を見つけましたが、私にとってはうまく動作しません。テキストを書き込んだ後にEnterキーを押してプログラムを実行し、書き込みを削除します

私はちょうど私のプログラムを第2の方法で実行しようとしていますが、理解する方法はわかりません。

:私は、textBox1テキストボックス内のいくつかのフレーズを書きたい

は、その後、入力textBox1テキストボックスから書かれたフレーズを削除し、いくつかの計算を行うだけにして、私はこの道を行けばTextBox2を

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace XX_TEXTBOX_TEST 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     }  
     private void textBox1_TextChanged(object sender, EventArgs e) 
     {  
      textBox2.AppendText("OK!"); 
     } 
    } 
} 

でこのテキストを表示するにヒット

`Severity Code Description Project File Line Suppression State Error CS1061 'Form1' does not contain a definition for 'textBox1_TextChanged' and no extension method 'textBox1_TextChanged' accepting a first argument of type 'Form1' could be found (are you missing a using directive or an assembly reference?) XX_TEXTBOX_TEST C:\FOLDER\Form1.Designer.cs 42 Active

そして:

私はエラーを得ました3210

Severity Code Description Project File Line Suppression State Message The designer cannot process unknown name 'textBox1_TextChanged' at line 42. The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. C:\FOLDER\Form1.Designer.cs 43

+0

'テキストが変更されたときにTextChanged'が唯一のトリガーです。 keydownイベント –

答えて

0
private void textBox1_KeyDown(object sender, KeyEventArgs e) 
    { 
     if (e.KeyCode == Keys.Enter) 
     { 
      //your function 
     } 
    } 

あなたは、テキストボックスのKeyDownイベントを使用する必要があります

+0

を使用する必要がありますが、私がこのようにした場合、フォームにエラーが発生し、textBox1_TextChangeがどこに存在するのかわかりません。あるいは私は新しいものでそれをしなければならないが、どこで?私は間違っているのVisual Studio 2015を使用しますか? –

+0

@MolC 'form1.designer.cs'ファイルをチェックすると、関数宣言を見つけることができます。または単にエラーをクリックすると自動的にそのファイルに移動します –

関連する問題