2013-01-07 27 views
1

我的應用程序中有兩個文本框,一個是txtCampaign,另一個是txtUrl。爲txtCampaign tabindex屬性爲1和的TabIndex爲txtUrl是2製表符在窗口應用程序中不起作用

現在我已經用下面的代碼:

private void txtCampaign_Enter(object sender, EventArgs e) 
{ 
     txtCampaign.BorderStyle = BorderStyle.FixedSingle; 
     txtUrl.BorderStyle = BorderStyle.Fixed3D; 
} 

private void txtUrl_Enter(object sender, EventArgs e) 
{ 
     txtUrl.BorderStyle = BorderStyle.FixedSingle; 
     txtCampaign.BorderStyle = BorderStyle.Fixed3D; 
} 

現在,當我從第一個文本框txtCampaign使用的標籤,因爲它不會讓我去到第二個文本框。

我不知道爲什麼會發生這種情況?但是,如果我刪除上面的代碼其工作正常對我來說

+1

我也不知道。當你設置新的'BorderStyle'值時,你可能會失去焦點。嘗試在事件處理程序中調用'txtBox.Focus()'。如果這不是你的下一個嘗試,也重置事件處理程序中的「TabOrder」值。 – mortb

回答

2

在您的事件中使用SetFocus()。示例代碼:

public Form1() 
{ 
    InitializeComponent(); 
    textBox1.Enter += textBox1_Enter; 
    textBox2.Enter += textBox2_Enter; 
} 

private void textBox2_Enter(object sender, EventArgs e) 
{ 
    textBox1.BorderStyle = BorderStyle.Fixed3D; 
    textBox2.BorderStyle = BorderStyle.FixedSingle; 
    textBox2.Focus(); 
} 

private void textBox1_Enter(object sender, EventArgs e) 
{ 
    textBox2.BorderStyle = BorderStyle.Fixed3D; 
    textBox1.BorderStyle = BorderStyle.FixedSingle; 
    textBox1.Focus(); 
} 
+1

它的工作正常。 –

相關問題