c# textbox回車控件移動(dòng)焦點(diǎn)
TextBox控件增加了幾個(gè)有意思屬性。一個(gè)布爾值是AcceptsReturn屬性的值,允許c# textbox回車接受為一個(gè)新行,或者激活窗體上的默認(rèn)按鈕。這個(gè)屬性設(shè)置為true時(shí),c# textbox回車文本框中創(chuàng)建一個(gè)新行使用c# textbox回車。CharactorCasing確定文本框中文本的大小寫(xiě)。CharactorCasing枚舉包含3個(gè)值Lower、Normal和Upper。Lower會(huì)使所有的文本小寫(xiě),Upper則把所有的文本轉(zhuǎn)變?yōu)榇髮?xiě),Normal把文本顯示為輸入時(shí)的形式。PasswordChar屬性用一個(gè)字符表示用戶在文本框中輸入文本時(shí)要顯示給用戶的內(nèi)容,這通常用于輸入密碼和pin數(shù)字。c# textbox回車屬性返回輸入的文本,只有顯示的內(nèi)容會(huì)受這個(gè)屬性的影響。
下面為大家介紹的是實(shí)現(xiàn)動(dòng)態(tài)地中窗體中使用c# textbox回車讓焦點(diǎn)在控件數(shù)組中移動(dòng)的兩種方法。
第一種方法:
C# code
- private void Form1_Load(object sender, System.EventArgs e)
 - {
 - TextBox []txt = new TextBox[10];
 - for(int i=0;i <10;i++)
 - {
 - txt[i]= new TextBox();
 - txt[i].Location = new System.Drawing.Point(8, 10+i*30);
 - txt[i].Size = new System.Drawing.Size(50, 21);
 - txt[i].TabIndex = i;
 - txt[i].KeyPress+=new KeyPressEventHandler(txt_KeyPress);
 - this.Controls.Add(txt[i]);
 - }
 - }
 - private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
 - { if(e.KeyChar==13)
 - { SendKeys.Send("{TAB}");
 - }
 - }
 
第二種方法:
C# code
- protected override bool ProcessDialogKey(Keys keyData)
 - {
 - if ((ActiveControl is TextBox || ActiveControl is ComboBox) &&
 - keyData == Keys.Enter)
 - {
 - keyData = Keys.Tab;
 - }
 - return base.ProcessDialogKey(keyData);
 - }
 
本文來(lái)自:CSDN社區(qū) 作者:佚名
【編輯推薦】















 
 
 
 
 
 
 