giving control focus = Focus? Select? ActiveControl? Activate?

S

Stephany Young

Well, one learns something new every day :)

I have never had any qualms about using the Control.Focus() method and I
have never encountered any issues in using it.

That said, I just tried using the Control.Focus() and Control.Select()
methods to set the focus to a NumericUpDown control and both worked just
fine.

But thank you for pointing out that note because it has solved an issue of
setting the focus to the next or previous control in the tab order. The
Control.Select method has a nice overload for doing just that.
 
Z

Zytan

Well, one learns something new every day :)

Yup!
I have never had any qualms about using the Control.Focus() method and I
have never encountered any issues in using it.

I know from the Win32 API that going behind the scenes can cause
problems, so, when thet have a warning like this, i try and avoid it.
That said, I just tried using the Control.Focus() and Control.Select()
methods to set the focus to a NumericUpDown control and both worked just
fine.

I am literally using these two lines of code:

numFibonacci.Focus()
numFibonacci.Select()

Commenting one out at a time, and only Focus() works.

When I use Select(), pressing Tab does nothing! Something else has
control, and Tab doesn't give back focus to a control in the tab
order!
But thank you for pointing out that note because it has solved an issue of
setting the focus to the next or previous control in the tab order. The
Control.Select method has a nice overload for doing just that.

Yeah, i see that. cool. you're welcome!

Zytan
 
Z

Zytan

I am literally using these two lines of code:
numFibonacci.Focus()
numFibonacci.Select()

Commenting one out at a time, and only Focus() works.

Ok, I have tried giving it focus in Form1_Load, and Control.Select()
does work!

So, the issue is that, for some reason, in the other place that i call
it, something strange is happening. Regardless, there is a difference
between the two functions. maybe because Focus() is more low level it
is solving another issue that Select() couldnt hope to solve. i'll
work on it.

Zytan
 
Z

Zytan

I am literally using these two lines of code:
numFibonacci.Focus()
numFibonacci.Select()

Commenting one out at a time, and only Focus() works.

When I use Select(), pressing Tab does nothing! Something else has
control, and Tab doesn't give back focus to a control in the tab
order!

Figured it out... it is because i was making the control with the
focus disabled via Control.Enable = False

Only Control.Focus() can save the day at this point, not
Control.Select(). presumably because .Focus() is low level, the very
reason you are not supposed to use it.

and this is from microsoft's own example:
http://msdn2.microsoft.com/en-us/library/waw3xexc.aspx
of which i should note, the tutorial is only half complete.

Zytan
 
S

Stephany Young

In the Form.Load event, Control.Select() is 'honoured' but Control.Focus()
is not. However, if you put Control.Focus() in the Form.Shown event then it
is 'honoured'.

Yes, the two methods are implemented differently.

If you have not already got it, I recommend that you get hold of Lutz
Roeder's Reflector. You can get it from:

http://www.aisto.com/roeder/dotnet/

It is invaluable, for delving into the internals of the Framework.
 
A

aaron.kempf

you surely mean that 'the framework is only half complete' right?

because it's not; it is not HALF of the solution that we had in vb6 /
vba / vbs.

We can't use clientside vb.net in DHTML
anything else you sell me is _CRAP_

I can create a spreadsheet, CLIENTSIDE-- programmatically-- usign a
simple ASP/DHTML page.

CAN MOTHER ****ING YOU DO THAT DIPSHIT???
 
Z

Zytan

In the Form.Load event, Control.Select() is 'honoured' but Control.Focus()
is not. However, if you put Control.Focus() in the Form.Shown event then it
is 'honoured'.

Ok, I remember something about that a while back when I made a post
about this same topic (different error, though). I am not sure what
'honoured' means, but I will stick to what the docs say -- use
Select().

If you have not already got it, I recommend that you get hold of Lutz
Roeder's Reflector. You can get it from:

http://www.aisto.com/roeder/dotnet/

It is invaluable, for delving into the internals of the Framework.

Thank you for the recommendation. I have used this before, its
amazing. I never thought about checking the code in there, though.

Zytan
 
S

Stephany Young

What I meant by 'honoured' was that, where MyControl is not the first
available control in the tab order:

Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Load

MyControl.Focus()

End Sub

does not work, but:

Private Sub Form_Shown(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Shown

MyControl.Focus()

End Sub

does work.

In both event handlers, MyControl.Select() works quite happily.
 
Z

Zytan

What I meant by 'honoured' was that, where MyControl is not the first
available control in the tab order:

Ah, right, basically you can check this with the .CanFocus()
and .CanSelect() methods.

Zytan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top