2013-07-29 40 views
0

我已經在Windows計算器開發一個簡單的計算器像任何控制,VB.NET從來沒有得到重點

但與Windows計算器,點擊任意按鈕後,把重點放在該按鈕是特定點擊的還有按鈕。

所以如何永遠不要關注計算器窗體上的所有按鈕......?

我不認爲最好在每個按鈕的點擊事件上寫出鬆散的焦點代碼......所以更好的解決方案?

回答

1

沒有看到你的任何代碼,我會假設你有一個文本框顯示用戶按下的數字,所以你需要在用戶點擊一個按鈕後將焦點設置到文本框,比如這樣的:

TextBox1.Focus() 

注意:如果您的文本框中沒有命名TextBox1,然後換到無論你的文本框實際上是命名的名稱。

+0

我不想將焦點設置連'textbox' –

1

而不是標準按鈕使用從標準按鈕派生的類的實例NoFocusButton。在這個類中覆蓋ShowFocusCues屬性並且總是返回false。

Form f = new Form(); 

// Need to add manually the buttons to your form unless you build a customcontrol 
NoFocusButton b = new NoFocusButton(); 
b.Text = "ClickMe"; 
f.Controls.Add(b); 
f.Show(); 

// Class derived by the Button control, it is identical but the 
// property that control the drawing of the Focus rectangle returns FALSE 
// tricking the WinForm system to avoid to draw the focus rectangle 
class NoFocusButton : System.Windows.Forms.Button 
{ 
    protected override bool ShowFocusCues 
    { 
     get 
     { 
      return false; 
     } 
    } 
} 

的榮譽屬於Remove Focus Rectangle from Button