2014-01-22 63 views
0

我有許多文本框。請參閱照片。得到插入文本框中的插入位置

i1

我創建了一個小鍵盤爲我的形式。參考照片。

i2e

幫我把代碼當點擊數字鍵盤,其插入位置將會出現在文本框中。 作爲示例,現在在Salesman文本框中插入光標,然後當用戶單擊數字7時,將在銷售員文本框中出現 。

回答

0

當您點擊一個數字小鍵盤按鈕時,脫字符將從文本框中消失。因此,我們無法搜索哪個文本框存在字符,因爲沒有文本框。您可以通過將上次聚焦的文本框保存在變量中並輸出單擊到該文本框的數字來實現此目的。這就是我的意思的例子:

public TextBox FocusedTextBox; 
public Form1() 
{ 
    InitializeComponent(); 
    textBox1.GotFocus += textBox_GotFocus; 
    textBox2.GotFocus += textBox_GotFocus; 
} 

private void textBox_GotFocus(object sender, EventArgs e) 
{ 
    FocusedTextBox = (TextBox) sender; 
} 

private void Button7_Click(object sender, EventArgs e) 
{ 
    if (FocusedTextBox != null) FocusedTextBox.Text += "7"; 
} 
+0

這個解決方案是否可以接受? – har07