Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

Setting a control focus in OnLoad event.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony - 22 Feb 2006 23:29 GMT
Based on data present when I load a form, I need to be able to set focus to
a specific control.
I have added code  as the last line of my Load handler setting a control to
have focus. e.g. control3.Focus().
But when the form is displayed, the first control with tab stop has focus
instead of the control I set.

This should be a very basic thing to do but I can't figure out how.

In the WIN32 API, you would return false form the OnInitDialog() method to
allow retention of focus you set programmatically.
Anyone know how to do this?

Thanks,
Tony
Stoitcho Goutsev (100) - 23 Feb 2006 14:58 GMT
Tony,

Control.Focus doesn't work if the control is invisible. During OnLoad no
controls are visible, so Focus() doesn't work.

If you use .NET 2.0 you can do that during Shown event.

For all versions instead calling control3.Focus() in the Load event handler
you can do:
this.ActiveControl = control3;
where *this* is the form.

Forst solution is only for .NET 2.0 the second is for all versions of .NET.

Signature

Stoitcho Goutsev (100)

> Based on data present when I load a form, I need to be able to set focus
> to a specific control.
[quoted text clipped - 11 lines]
> Thanks,
> Tony
Tony - 23 Feb 2006 16:22 GMT
The ActiveControl property worked, I don't recall ever seeing that for some
reason.

Thanks,
Tony

> Tony,
>
[quoted text clipped - 26 lines]
>> Thanks,
>> Tony

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.