在C#“DialPad.Designer.CS”页面中注册KeyPress事件方法

时间:2022-07-16 15:53:23

Im designing a dialerPad form using Windows form, there is a textbox which should only take numbers and not text, my problem is that when i add the code

我使用Windows窗体设计dialerPad表单,有一个文本框应该只采取数字而不是文本,我的问题是,当我添加代码

private void txtDialedNumber_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    //Blaah Blaah Code;
}

but its not getting registered in the other DialPad.Designer.CS page. For example the fallowing code registers TextChangedEvent

但它没有在其他DialPad.Designer.CS页面中注册。例如,休眠代码注册TextChangedEvent

this.txtDailedNumber.TextChanged += new System.EventHandler(this.txtDailedNumber_TextChanged);

Can anybody help me on this?

有人可以帮我吗?

2 个解决方案

#1


1  

I would try to simplify Greg's answer.

我会尝试简化格雷格的答案。

Select the text box > go to properties > events tab> KeyPress Event > select the method this.txtDailedNumber.KeyPress

选择文本框>转到属性>事件选项卡> KeyPress事件>选择方法this.txtDailedNumber.KeyPress

You are done.

你完成了。

#2


4  

You should never change *.designer.cs files manually.

您不应该手动更改* .designer.cs文件。

What you should be doing is opening the design view of your form, selecting the object, and then setting the event handler in the objects properties:

您应该做的是打开表单的设计视图,选择对象,然后在对象属性中设置事件处理程序:

在C#“DialPad.Designer.CS”页面中注册KeyPress事件方法

Alternatively, if you want to register event handler manually (instead of using the designer), just put it under the InitializeComponent() call in the constructor for your form.

或者,如果要手动注册事件处理程序(而不是使用设计器),只需将其放在表单构造函数中的InitializeComponent()调用下即可。

#1


1  

I would try to simplify Greg's answer.

我会尝试简化格雷格的答案。

Select the text box > go to properties > events tab> KeyPress Event > select the method this.txtDailedNumber.KeyPress

选择文本框>转到属性>事件选项卡> KeyPress事件>选择方法this.txtDailedNumber.KeyPress

You are done.

你完成了。

#2


4  

You should never change *.designer.cs files manually.

您不应该手动更改* .designer.cs文件。

What you should be doing is opening the design view of your form, selecting the object, and then setting the event handler in the objects properties:

您应该做的是打开表单的设计视图,选择对象,然后在对象属性中设置事件处理程序:

在C#“DialPad.Designer.CS”页面中注册KeyPress事件方法

Alternatively, if you want to register event handler manually (instead of using the designer), just put it under the InitializeComponent() call in the constructor for your form.

或者,如果要手动注册事件处理程序(而不是使用设计器),只需将其放在表单构造函数中的InitializeComponent()调用下即可。