Hi Christian,
The problem is that in the constructor CanFocus property returns *false*. It
returns false because the control is not visible yet. Normaly frameworks (at
least some of them ) don't allow focusing invisible windows. So, Focus
method checks CanFocus property and because it is *false* it doesn't do
anything. If it was true the Focus method would call SetFocus API and if
everything goes ok, would set ActiveControl.
However windows allows focusing invisible windows if you try the following
it works.
[DllImport("user32.dll")]
private extern static IntPtr SetFocus(IntPtr hwnd);
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
SetFocus(textBox1.Handle);
}
--
Stoitcho Goutsev (100) [C# MVP]
"Christian Pické" <in**@soft-service.net> wrote in message
news:OD*************@TK2MSFTNGP10.phx.gbl...
OK, this one works. Thanks a lot!
But it still doesn't take away my frustration about a method that simply
doesn't work the way it's described (gets AND sets the focus).
Christian
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!