+ Reply to Thread
Results 1 to 7 of 7

Thread: combobox steals focus

  1. #1
    didgydont is offline VB.NET Forum Enthusiast didgydont will become famous soon enough
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Mar 2009
    Age
    27
    Posts
    37
    Reputation
    30

    Default combobox steals focus

    hi all
    i have 4 forms i have made a password form(form4) wich i started when form 1 loads
    Code:
    If My.Settings.Userpassenable = Enabled Then
                Form4.ShowDialog()
            End If
    i have set on form 4 load
    maskedtextbox1.focse()
    but the combo box on form 1 keep taking focus
    i found that out by setting Form4.ShowDialog() to Form4.Show() on form 1 any ideas ?
    thank you

  2. #2
    pitaridis is offline VB.NET Forum Enthusiast pitaridis is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2005
    Age
    35
    Posts
    59
    Reputation
    62

    Default

    My friend in order to set the focus to a control you have to make it like this:

    Code:
    Me.ActiveControl = maskedtextbox1
    Have fun.
    If you can help someone, just do it. Do not try to prove that you are more cleaver than other people.

    Excuse me for my English but I am from Greece and my English is not perfect.

  3. #3
    newguy's Avatar
    newguy is offline VB.NET Forum Idol newguy puts e.f. hutton to shame newguy puts e.f. hutton to shame newguy puts e.f. hutton to shame newguy puts e.f. hutton to shame newguy puts e.f. hutton to shame newguy puts e.f. hutton to shame newguy puts e.f. hutton to shame
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jun 2008
    Location
    Denver Co, USA
    Posts
    609
    Reputation
    217

    Default

    maskedtextbox1.select will place the caret in the box and waiting for user input.
    Close Counts for Horseshoes, Handgranades, and Nuclear Missiles!

  4. #4
    pitaridis is offline VB.NET Forum Enthusiast pitaridis is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2005
    Age
    35
    Posts
    59
    Reputation
    62

    Default

    The select method is for selecting the contents of the control. Of course the select method will activate the control but this is not the right way to activate it.
    If you can help someone, just do it. Do not try to prove that you are more cleaver than other people.

    Excuse me for my English but I am from Greece and my English is not perfect.

  5. #5
    didgydont is offline VB.NET Forum Enthusiast didgydont will become famous soon enough
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Mar 2009
    Age
    27
    Posts
    37
    Reputation
    30

    Default

    thank you both very much
    i went with "Me.ActiveControl = maskedtextbox1"
    but "maskedtextbox1.select" will be a good thing to remember
    thank you both again

  6. #6
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute jmcilhinney has a reputation beyond repute
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Age
    41
    Posts
    6,907
    Reputation
    670

    Default

    Quote Originally Posted by pitaridis View Post
    The select method is for selecting the contents of the control. Of course the select method will activate the control but this is not the right way to activate it.
    That is not correct. Select with no parameters is inherited from the control class and simply sets focus to the control. It's functionally equivalent to setting the ActiveControl property. Select with two Integer parameters is for selecting text within the control and it will NOT affect focus at all.

    MaskedTextBox.Select Method (System.Windows.Forms)

    As for the original question, there's probably no need to explicitly set focus to any particular control. When a form is displayed for the first time it will focus the first control in the tab order. If you want your MaskedTextBox to initially have focus then you should simply make it first in the tab order. This may not be possible in a complex layout but for simple forms it's the best way to go.

  7. #7
    pitaridis is offline VB.NET Forum Enthusiast pitaridis is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2005
    Age
    35
    Posts
    59
    Reputation
    62

    Default

    The tab order is an other good idea that you suggested. Anyway, I think that we helped didgydont to solve his problem.

    Have a nice day both of you.
    If you can help someone, just do it. Do not try to prove that you are more cleaver than other people.

    Excuse me for my English but I am from Greece and my English is not perfect.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

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