views:

187

answers:

2

Hi All,

I am have textbox and 4 button in my page (A, B, Delete and Enter). If i click the button 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.

A: 

Why are you trying to send a key event to the TextBox, instead of setting its Text property?

Daniel Rose
I am creating a virtual keyboard.
Geetha
And what stops you from setting the Text property?
Daniel Rose
+2  A: 

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.