473,625 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18000
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**********@y ahoo.comwrote in message
news:11******** **************@ a75g2000cwd.goo glegroups.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.Fo cus()
numFibonacci.Se lect()

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.Fo cus()
numFibonacci.Se lect()

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.Fo cus()
numFibonacci.Se lect()

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**********@y ahoo.comwrote in message
news:11******** *************@q 2g2000cwa.googl egroups.com...
>I am literally using these two lines of code:

numFibonacci.F ocus()
numFibonacci.S elect()

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-- programmaticall y-- usign a
simple ASP/DHTML page.

CAN MOTHER FUCKING YOU DO THAT DIPSHIT???

On Feb 16, 2:21 pm, "Zytan" <zytanlith...@y ahoo.comwrote:
I am literally using these two lines of code:
numFibonacci.Fo cus()
numFibonacci.Se lect()
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(ByVa l sender As Object, ByVal e As EventArgs)
Handles MyBase.Shown

MyControl.Focus ()

End Sub

does work.

In both event handlers, MyControl.Selec t() works quite happily.
"Zytan" <zy**********@y ahoo.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
85613
by: William Case | last post by:
Hi folks, Screen.PreviousControl.SetFocus works fine to select the control that had focus prior to the one that NOW has focus. Unfortunately, I've not discovered a VBA code way to get the name of the control, that currently has focus. It would be nice if the Screen object had a property called "CurrentControl" that could be stored in a variable, as in: "X = Screen.CurrentControl.Name" Am I overlooking something?
7
4459
by: Gerry Abbott | last post by:
Hi all, Ive got a form with several controls which contain date fields. I'm usng the activex calender control as a separate floating form, I would like to be able to click onto any of the date fields and use the calender to drop a date into it. So far, I've managed to drop the date selected from the calener, into a specified control, and requery the control to display the newly added date. Works fine using the rs object.
0
2458
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls which are not behaving as I would expect. Specifically, if there is a command button external to the usercontrol which is activated by a shortcut key (eg Alt-B), the command button Click event handler code 'executes' even though the textbox set...
2
3369
by: Peter Stojkovic | last post by:
I have the following problem VS.2003 Visual Basic Windows XP My Applictaion has only keyboard inputs. There is no mouse available. Sometimes my program does not go on, because any other control then i expected has gone focus or is activated. So I dont know which control has focus in this moment.
1
5132
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
1
1955
by: Gary | last post by:
There are several controls in my form. How to detect currently which control has the forcus and set the forcus to a certain control? Thanks,
4
4297
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I have is that sometimes I seem to loose the original "holder" of focus and when the user hits tab while using "temporary" focus(while the mouse is over a control) it will change focus to the next control but not update it. So I have several issues....
7
4526
by: Neil | last post by:
I have some code in my form's On Current event which changes focus to a particular control. I want the control to remain where it was when the user moved to the new record. But using Screen.ActiveControl or Me.ActiveControl in the OnCurrent event results in the error "the expression you entered requires the control to be in the active window" (2474). How can I determine the control that had the focus before moving to the new record, so...
7
14616
by: Andrus | last post by:
I have UserControls in MDI child forms containing TextBoxes and other controls. When user re-activates form, I need that Control which was last activated is activated again. Currently *first* control is activated always. To reproduce: 1. Run code. 2. Make TextBox2 as current TextBox by selecting its text
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7178
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.