2

Possible Duplicate:
Focus issue on Form Load

I have a Activex control written in VB 6.0 or C++ maybe that been using it as a AxInterop in the C# WinForms program, it is very much like a text box but with some special logics, etc... and we have added it to a toolbar ... When the form loads I want the keyboard focus to be inside this so I used .Focus and also .Select methods on it but still it does NOT get the focus. When I run the program from VS IDE : It gets the focus. When I run the .EXE file outside of the IDE: It does not get the focus.

What do you think?

here is an screen shot of it too:

enter image description here

Community
  • 1
  • 1
Bohn
  • 26,091
  • 61
  • 167
  • 254
  • You seem to have created an exact duplicate of this question. I have posted my answer there, so you can now delete this question. – g t Nov 16 '12 at 06:59

1 Answers1

2

Are you sure the component is visible when you try to give it focus?

If you are trying to do the focussing in a Form.Load event handler, try moving it to the Form.Shown handler instead, or perhaps Control.Enter.

The difference in behaviour could be down to a timing issue. Have a look on MSDN for the order in which events occur on an opening form for more ideas.

g t
  • 7,287
  • 7
  • 50
  • 85
  • great things to consider...will do – Bohn Nov 15 '12 at 17:13
  • hmm where is "FormShown" event? can't find it..I could find "Enter" tho... – Bohn Nov 15 '12 at 17:16
  • I updated the names for each event. To see a list of all events for a Form/Control, have a look at the Events list in the Properties window of the Designer. See http://msdn.microsoft.com/en-us/library/aa984320(v=VS.71).aspx – g t Nov 16 '12 at 06:56