Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

arrow keys acting like tab key on controls added at runtime

Hi, Here's my code... I add a usercontrol to a form at runtime and add textboxes to a frame on the usercontrol. When the form loads however, the arrow keys on these textboxes act like tabs, moving the cursor to the next textbox. When user clicks on another control (added at design time) on the screen and come back to the textboxes, the arrow keys start behaving fine.
Any idea why this may occur, and how I could fix it?


Private WithEvents MyEditor As VBControlExtender

Set MyEditor = MyForm.Controls.Add("ctlMyUserControl", "MyEditor")
MyEditor.Visible = True

MyEditor.object.Controls.Add "VB.TextBox", "txtName", MyEditor.object.Controls("frameUserInfo")
MyEditor.object.Controls.Add "VB.TextBox", "txtAddress", MyEditor.object.Controls("frameUserInfo")
1 Solution
I am not sure this will work, but try doing this in Form_Activate event....

cmdButton.SetFocus ' forcus to any design time conrol
SendKeys "{TAB}"
txtName.SetFocus ' now focus back to whereever you want

Good Luck!
powerstreakAuthor Commented:
The form starts out empty...the usercontrol is loaded at runtime.
I sent a WM_LBUTTONDOWN message to an existing control on the usercontrol during Initproperties and it worked. Wish I'd known the underlying reason for this behaviour.
Thanks though, for sending me in the right direction.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now