0

我的页面中有文本框和 4 个按钮(A、B、Delete 和 Enter)。如果我单击按钮,它必须将关键事件发送到文本框。

问题:文本框上没有发生任何操作。

代码:

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);

            }           
    }

吉萨。

4

2 回答 2

0

为什么要尝试将键事件发送到 TextBox,而不是设置其 Text 属性?

于 2010-07-15T09:57:42.510 回答
0

丹尼尔罗斯是对的。这样不是更容易吗?您获取文本框的 Text 属性,然后在 buttonclick 上将正确的字符附加到该字符串,当按下删除按钮时,只需擦除该字符串的最后一个字符。

于 2010-07-15T11:39:32.173 回答