두 개의 텍스트 상자가 있으며 각기 다른 키 누르기 이벤트가 첨부되어 있습니다.하나의 키 이벤트를 포커스가있는 컨트롤에 연결하십시오.
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == '\r')
{
e.Handled = true;
// some other stuff
}
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == '\r')
{
e.Handled = true;
// some other stuff
}
}
키 누르기 이벤트를 포커스가있는 텍스트 상자에 동적으로 연결하는 방법이 있습니까?
편집 :
뭔가 같은 :
void KeyPress(object sender, KeyPressEventArgs e)
{
foreach(Control c in this)
{
if(c == TextBox && c.Focused)
{
if(e.KeyChar == '\r')
{
// do something
}
}
}
}
foreach는 (이에서 제어 c)에 그게 ^^ –
Naaa, 그것은 그냥하지 않는 절대 의사 코드 ^^ – betaFlux
내 대답을 봐,이 방법은 할 수있다 –