今天移植项目到wm 真的头大 ,一个简单的问题折腾了将近半天

1.自定义UserTextBox控件,只有一个label和textbox,定义控件EnterPress事件

C# code 
public partial class UserTextBox : UserControl { 
  public UserTextBox() { 
   InitializeComponent(); 
   textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown); 
   
   nud.Click                                 nud-click
   } 
   public event KeyEventHandler EnterPress = null; 
   private void textBox1_KeyDown(object sender , KeyEventArgs e) 
   { 
     if ( EnterPress != null ) 
       { 
          if ( e.KeyCode == Keys.Enter ) 
               { EnterPress(null , e); } 
       } 
   } 
   
  }


2.在Form中应用自定义控件EnterPerss事件
(1)首先在构造函数中添加声明
      C# code
      this.userTextBox1.EnterPress += new System.Windows.Forms.KeyEventHandler(this.userTextBox1_EnterPress);
 (2)EnterPress事件代码
      C# code
      private void userTextBox1_EnterPress(object sender , KeyEventArgs e) { MessageBox.Show("this is a test"); }