2017-03-04 3 views
0

Microsoft Access用のビジュアルスタジオウィンドウフォームを含むCOM Interopオブジェクトを作成しました。言い換えれば、私は自分のdllを登録してtlbに変換した後、Microsoft Accessの中で自分のWindowsフォームを開くことができます。C#Windows Form Com InteropオブジェクトのAccessタブまたは入力ボタンが機能しない

すべてはフォームが機能やボタンが作動しないフォーカスがあるとき Enterキーを押すと(TABを押して、コントロールにフォーカスを与える)タブコントロールを開いたときを除き、正常に動作します。

別のC#アプリケーションでCOMオブジェクトを実行すると、すべて正常に動作します。 Microsoft Accessで実行しようとするときにのみ、この問題が発生します。

enter image description here

私のWindowsフォームは4つのテキストボックスと他には何も付いたボタンがあります。そして、私のコントロールのすべてTabStop TRUETabIndexの値も同様に設定されています。 にアクセスすると、表示 - >タブオーダーすべてが正しく設定されているのがわかります。しかし、まだのTABボタンは機能しません。

答えて

0

私はので、私は動的に次のタブインデックスを検索し、TABユーザーがボタンを押した後、そのコントロールにフォーカスを与える関数を書いて、それはバグのようなものであると信じています。

ここにコードが抜粋されています。

private Control _control; 
private int _tabIndex; 

public Form1() 
{ 
    InitializeComponent(); 

    KeyDown += FormEvent; // subscribe to event 
} 

private void FormEvent(object sender, KeyEventArgs e) 
{ 
    // if pressed key is not tab, or there is no active form return 
    if (e.KeyCode != Keys.Tab || ActiveForm == null) return; 

    // get the control which currently has focus and get its tab index 
    _control = ActiveForm.ActiveControl; 
    _tabIndex = _control.TabIndex; 

    // iterate through all the controls on the form 
    for (var i = 0; i < Controls.Count; i++) 
    { 
     // continue until the next control which has to gain focus is found 
     if (Controls[i].TabIndex != _tabIndex + 1) continue; 

     // control found but its not suppose to gain focus on tab, 
     if (!Controls[i].TabStop) 
     { 
      i = -1; // start from the beggining of the loop 
      _tabIndex++; // search for the next control 
     } 
     // control found, focus on it 
     else 
      ActiveForm.ActiveControl = Controls[i]; 
    } 
} 
関連する問題