Results 1 to 6 of 6

Thread: How to get the active control of the active form?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    How to get the active control of the active form?

    Hi all,

    I want to get the active control (control which has the focus or where the cursor is on) each time the cursor moves to another control or each time a control receives a focus.

    How do i do this?

    Thanks.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: How to get the active control of the active form?

    you can use me.activecontrol. you need to handle the _gotfocus event of your controls

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: How to get the active control of the active form?

    Quote Originally Posted by .paul. View Post
    you can use me.activecontrol. you need to handle the _gotfocus event of your controls
    thanks...

    i forgot about the Me.ActiveControl...

    Quote Originally Posted by .paul. View Post
    you need to handle the _gotfocus event of your controls
    isn't there a way to handle gotfocus by groups of items instead of doing it individually?

    thanks.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  4. #4
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: How to get the active control of the active form?

    Quote Originally Posted by adshocker View Post
    Hi all,

    I want to get the active control (control which has the focus or where the cursor is on) each time the cursor moves to another control or each time a control receives a focus.

    How do i do this?

    Thanks.
    Me.Active Control will work for getting the control that has the focus, but I don't think there is anything that easy for getting which control the Mouse is over.

    Your best bet is to give all the controls the same MouseEnter event and in it use typeof sender to determine what type the control is and then trycast to convert it into to whatever control it is.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to get the active control of the active form?

    Quote Originally Posted by .paul. View Post
    you need to handle the _gotfocus event of your controls
    Enter and Leave, NOT GotFocus and LostFocus.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: How to get the active control of the active form?

    thanks..

    i'll give it a try.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width