I am have textbox and 4 button in my page (A, B, Delete and Enter). If i click the 开发者_如何学Pythonbutton it has to send key event to the textbox.
Problem: No action is happening on the textbox.
Code:
void buttonElement_Click(object sender, RoutedEventArgs e)
{
// create variable for holding string
String sendString = "";
// stop all event handling
e.Handled = true;
// set sendstring to key
sendString = ((Button)sender).CommandParameter.ToString();
// if something to send
if (!String.IsNullOrEmpty(sendString))
{
// if sending a string
if (sendString.Length > 1)
{
// add {}
sendString = "{" + sendString + "}";
}
// set keyboard focus
System.Windows.Input.Keyboard.Focus(this.txtSearch);
System.Windows.Forms.SendKeys.SendWait(sendString);
}
}
Geetha.
Daniel Rose is right. Wouldn't it be easier this way? You take the Text property of the textbox and on the buttonclick you append the right character to this string of when the delete-button is pressed just erase the last character of this string.
Why are you trying to send a key event to the TextBox, instead of setting its Text property?
精彩评论