2009/12/22

MaskedTextBox.SelectAll()無作用!?


當文字方塊取得焦點時
user都會要求文字方塊可以自動把文字全選起來

private void textBox1_Enter(object sender, EventArgs e)
{
    textBox1.SelectAll();
}

 

但遮罩文字方塊在設定遮罩後
上面的方法就沒有作用了


解決方法很簡單
只要再呼叫一次Focus方法
問題就解決了

private void maskedTextBox1_Enter(object sender, EventArgs e)
{
    maskedTextBox1.Focus();
    maskedTextBox1.SelectAll();
}

 

 

by sam319

0 意見: