469,592 Members | 2,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

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

http://msdn2.microsoft.com/en-us/sys...us(VS.80).aspx
this page says:

"Focus is a low-level method intended primarily for custom control
authors. Instead, application programmers should use the Select method
or the ActiveControl property for child controls, or the Activate
method for forms."

I am trying to give a Numeric UpDown control focus. Only Focus()
works. But this says to not use it.

What am i supposed to do?

Zytan

Feb 16 '07 #1
9 17194
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.
"Zytan" <zy**********@yahoo.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
http://msdn2.microsoft.com/en-us/sys...us(VS.80).aspx
this page says:

"Focus is a low-level method intended primarily for custom control
authors. Instead, application programmers should use the Select method
or the ActiveControl property for child controls, or the Activate
method for forms."

I am trying to give a Numeric UpDown control focus. Only Focus()
works. But this says to not use it.

What am i supposed to do?

Zytan
Feb 16 '07 #2
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
Feb 16 '07 #3
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
Feb 16 '07 #4
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
Feb 16 '07 #5
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.

"Zytan" <zy**********@yahoo.comwrote in message
news:11*********************@q2g2000cwa.googlegrou ps.com...
>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

Feb 16 '07 #6
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 FUCKING YOU DO THAT DIPSHIT???

On Feb 16, 2:21 pm, "Zytan" <zytanlith...@yahoo.comwrote:
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

Feb 16 '07 #7
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
Feb 17 '07 #8
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.
"Zytan" <zy**********@yahoo.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
>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

Feb 17 '07 #9
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

Feb 19 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Gerry Abbott | last post: by
2 posts views Thread by Peter Stojkovic | last post: by
1 post views Thread by clickon | last post: by
4 posts views Thread by Jon Slaughter | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.