Results 1 to 6 of 6

Thread: Leave a control with code?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Leave a control with code?

    Is there a way to leave a control in code without explicitly going to the next control? For example, I want to

    Me.TextBox1.Text = "abc"
    Me.TextBox1.Leave

    Not

    Me.TextBox1.Text = "abc"
    Me.TextBox2.Select

  2. #2
    Lively Member
    Join Date
    Jul 2010
    Posts
    86

    Re: Leave a control with code?

    Is the selectnextcontrol function what you want? Signature is below.

    Public Function SelectNextControl(ByVal ctl As System.Windows.Forms.Control, ByVal forward As Boolean, ByVal tabStopOnly As Boolean, ByVal nested As Boolean, ByVal wrap As Boolean) As Boolean

  3. #3
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    Re: Leave a control with code?

    You can use

    Code:
    Me.SelectNextControl(Me.TextBox2, False, True, True, True)
    The first True or False option here is set to False. That determines whether you want to move forward or backward in the tab order. True to move forward and False to move backward. You want to enter text into a textbox and then keep the focus at that textbox? If TextBox2 is the next textbox in the tab order after TextBox1 then this code should set the focus to TextBox1.
    Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

    "Persistence is the magic of success." Paramahansa Yogananda

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Leave a control with code?

    I'm trying to enter TextBox2 without firing it's enter event twice.

  5. #5
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    Re: Leave a control with code?

    You can control what textbox has focus using SelectNextControl. I'm not sure what you mean by this

    I'm trying to enter TextBox2 without firing it's enter event twice.
    Maybe you could explain exactly what you are trying to do.
    Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

    "Persistence is the magic of success." Paramahansa Yogananda

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Leave a control with code?

    TextBox2 has a voice prompt. If you say Me.TextBox2.Select the voice prompt is heard twice because TextBox2's enter event fires twice. Currently I'm using a boolean variable to control this. I'm looking for a better way.

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