我有這個代碼窗口窗體應用程序,我一直試圖將其轉換爲Silverlight應用程序,但它不工作!有一個文本框,我附加了KeyDown事件處理程序。當用戶按下箭頭鍵(左側或右側)時,將焦點放在文本框上,它會寫入。要麼 -。當它是窗口形式我使用e.KeyCode和Keys.Right及其作品很好,但是當它是Silverlight時,我使用了e.Key和key.Right,程序不能正常工作,因爲箭頭執行2個函數移動和寫入./-。我如何在Silverlight中解決這個問題? (我的英語不太好)從Winform轉換簡單的代碼到Silverlight應用程序的問題
代碼(窗口形式):
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (sender is TextBox)
{
TextBox textBox = (TextBox)sender;
if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
{
e.Handled = true;
char insert;
if (e.KeyCode == Keys.Left)
{ insert = '.'; }
else
{ insert = '-'; }
int i = textBox.SelectionStart;
textBox.Text = textBox.Text.Insert(i, insert.ToString());
textBox.Select(i + 1, 0);
}
}
}
(和Silverlight):
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (sender is TextBox)
{
TextBox textBox = (TextBox)sender;
if (e.Key == Key.Left || e.Key == Key.Right)
{
e.Handled = true;
char insert;
if (e.Key == Key.Left)
{ insert = '.'; }
else
{ insert = '-'; }
int i = textBox.SelectionStart;
textBox.Text = textBox.Text.Insert(i, insert.ToString());
textBox.Select(i + 1, 0);
}
}
}
我不明白,有沒有使用之間巨大的不同效果鍵碼/鍵和鍵/鍵還是因爲別的?
我已經做了,但還是有問題 – Sara 2010-04-17 23:22:39
該死的,我需要睡眠:/ – Femaref 2010-04-17 23:34:30