Control wont take focus

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?dmJ0cnlpbmc=?=

    #1

    Control wont take focus

    I am using a switch statement, to check for valid user hours. If the hours
    control is blank, I want to place the cursor back to the hours control for
    the user.

    The following code does NOT work:

    switch (txtHours.Text)
    {
    case "":
    MessageBox.Show ("No hours entered.\nYou must enter hours
    for this record.", "Bad Value for Hours", MessageBoxButto ns.OK,
    MessageBoxIcon. Error);
    txtHours.Focus( );
    break;
    default:
    break;
    }

    Has anybody tried to do this before? Am I using it incorrectly?

    Thanks,
    Terry
  • Peter Duniho

    #2
    Re: Control wont take focus

    vbtrying wrote:
    [...]
    The following code does NOT work:
    >
    switch (txtHours.Text)
    {
    case "":
    MessageBox.Show ("No hours entered.\nYou must enter hours
    for this record.", "Bad Value for Hours", MessageBoxButto ns.OK,
    MessageBoxIcon. Error);
    txtHours.Focus( );
    break;
    default:
    break;
    }
    >
    Has anybody tried to do this before? Am I using it incorrectly?
    How does it "NOT work"? Where do you execute the code?

    The Focus() method does generally work, and I have in fact used it when
    doing textbox value validation. So the general technique is sound.

    But if you aren't putting the code somewhere that guarantees that the
    focus will be left alone after you call Focus(), you could easily wind
    up not seeing any focus change.

    You need to be more specific if you want an answer though. You should
    post a concise-but-complete example of code that reliably reproduces the
    problem (and of course, you should be more precise in describing the
    problem than "does not work").

    Pete

    Comment

    • =?Utf-8?B?dmJ0cnlpbmc=?=

      #3
      Re: Control wont take focus

      Pete, get off your high horse guy! "You need to be more specific if you want
      an answer". Don't answer if you think the question doesn't suite your needs
      as fas as clarity.

      You are the reason bulletin boards don't work.




      "Peter Duniho" wrote:
      vbtrying wrote:
      [...]
      The following code does NOT work:

      switch (txtHours.Text)
      {
      case "":
      MessageBox.Show ("No hours entered.\nYou must enter hours
      for this record.", "Bad Value for Hours", MessageBoxButto ns.OK,
      MessageBoxIcon. Error);
      txtHours.Focus( );
      break;
      default:
      break;
      }

      Has anybody tried to do this before? Am I using it incorrectly?
      >
      How does it "NOT work"? Where do you execute the code?
      >
      The Focus() method does generally work, and I have in fact used it when
      doing textbox value validation. So the general technique is sound.
      >
      But if you aren't putting the code somewhere that guarantees that the
      focus will be left alone after you call Focus(), you could easily wind
      up not seeing any focus change.
      >
      You need to be more specific if you want an answer though. You should
      post a concise-but-complete example of code that reliably reproduces the
      problem (and of course, you should be more precise in describing the
      problem than "does not work").
      >
      Pete
      >

      Comment

      • Peter Duniho

        #4
        Re: Control wont take focus

        vbtrying wrote:
        [...]
        If you don't reply, I'll understand.
        I'm not so sure of that. I suspect that you will think a lack of a
        response on my part is due to an inability to answer the question, when
        in fact it would be due to the lack of an apology from you for your
        behavior.

        If my suspicion is correct, then you don't understand.

        I guess we'll see.

        Pete

        Comment

        • =?Utf-8?B?dmJ0cnlpbmc=?=

          #5
          Re: Control wont take focus

          Don't wait too long for an apology from me. If you can't answer the question,
          or just don't want to, fine. But don't hide behind the premise that you're
          waiting for an apology first before you answer questions.

          You must enjoy the world you live in.



          "Peter Duniho" wrote:
          vbtrying wrote:
          [...]
          If you don't reply, I'll understand.
          >
          I'm not so sure of that. I suspect that you will think a lack of a
          response on my part is due to an inability to answer the question, when
          in fact it would be due to the lack of an apology from you for your
          behavior.
          >
          If my suspicion is correct, then you don't understand.
          >
          I guess we'll see.
          >
          Pete
          >

          Comment

          • Peter Duniho

            #6
            Re: Control wont take focus

            vbtrying wrote:
            Don't wait too long for an apology from me.
            Why would I wait at all? Rest assured, I'm not sitting around waiting
            for you to do anything at all.
            If you can't answer the question,
            or just don't want to, fine.
            As if you could direct me otherwise?
            But don't hide behind the premise that you're
            waiting for an apology first before you answer questions.
            Hide? Um, whatever.
            You must enjoy the world you live in.
            I do, actually. I live in a world where I have no reason to put up with
            jerks who fly off the handle at the least possible provocation, taking
            insult where none was intended, and who cannot be bothered to apologize
            for their atrociously childish behavior.

            Your question is not really that hard. You should think carefully about
            why it is no one else has jumped in to help you out. It's not like
            people are falling over themselves to answer your question. And the
            lack of replies is not because it's too hard for everyone else.

            Pete

            Comment

            • =?Utf-8?B?dmJ0cnlpbmc=?=

              #7
              Re: Control wont take focus

              Childish behavior, um, let me see. Could it be that you have a "need" to get
              the last word in?

              "Peter Duniho" wrote:
              vbtrying wrote:
              Don't wait too long for an apology from me.
              >
              Why would I wait at all? Rest assured, I'm not sitting around waiting
              for you to do anything at all.
              >
              If you can't answer the question,
              or just don't want to, fine.
              >
              As if you could direct me otherwise?
              >
              But don't hide behind the premise that you're
              waiting for an apology first before you answer questions.
              >
              Hide? Um, whatever.
              >
              You must enjoy the world you live in.
              >
              I do, actually. I live in a world where I have no reason to put up with
              jerks who fly off the handle at the least possible provocation, taking
              insult where none was intended, and who cannot be bothered to apologize
              for their atrociously childish behavior.
              >
              Your question is not really that hard. You should think carefully about
              why it is no one else has jumped in to help you out. It's not like
              people are falling over themselves to answer your question. And the
              lack of replies is not because it's too hard for everyone else.
              >
              Pete
              >

              Comment

              • Peter Duniho

                #8
                Re: Control wont take focus

                vbtrying wrote:
                Childish behavior, um, let me see. Could it be that you have a "need" to get
                the last word in?
                Nope. How about you?

                Comment

                Working...