Cannot assign to 'Focus' because its a 'Method Group in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dtittle
    New Member
    • Jan 2008
    • 8

    Cannot assign to 'Focus' because its a 'Method Group in C#

    I am trying to keep focus on a button. How do I do that?

    private void cmdRead_KeyDown (object sender, System.Windows. Forms.KeyEventA rgs e)
    {
    if (e.KeyCode == Keys.F24)
    {
    StartReading();
    }
    }


    Thanks,

    dtittle
    Skype: <removed>
    Last edited by Curtis Rutland; Oct 14 '08, 09:08 PM. Reason: removed skype ID -- against signature guidelines
  • akshaycjoshi
    New Member
    • Jan 2007
    • 153

    #2
    Use the Focus() method of the control to set focus on it.

    Comment

    • dtittle
      New Member
      • Jan 2008
      • 8

      #3
      As the name (newbie) applies, how do I do that?

      Comment

      • dtittle
        New Member
        • Jan 2008
        • 8

        #4
        How do you use the Focus() method???

        I'm trying to keep focus on a button after I press it. The TabIndex is set to zero. I've heard some stuff about using the Focus() method of the control but I'm not sure what to do with it. Do any of you all have an example I could look at?

        CODE
        private void cmdRead_KeyDown (object sender, System.Windows. Forms.KeyEventA rgs e)
        {
        if (e.KeyCode == Keys.F24)
        {
        StartReading();
        }
        }
        /CODE

        I'm not sure if this is where the code would go either.

        Comment

        • joedeene
          Contributor
          • Jul 2008
          • 579

          #5
          Well drag a timer to your form in the designer view, and in the code view type in

          Code:
          private void timer1_Tick(object sender, EventArgs e)
                  {
                      button1.Focus();
                  }
          
                  private void Form1_Load(object sender, EventArgs e)
                  {
                      timer1.Interval = 500;
                      timer1.Start();
                  }
          but instead of button1 put the name or control you want to have focused, and change the timer's interval rate to one that suits you.

          joedeene

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            When you say "focus" do you mean you want to watch for when a certain key on the keyboard is pressed (as your code would suggest), or do you want the point of concentration to always be on a certain control?

            Comment

            • Curtis Rutland
              Recognized Expert Specialist
              • Apr 2008
              • 3264

              #7
              Threads Merged.

              Please don't double post your questions. If you made a mistake and need to change your question, you can click the Edit button to edit your post, or you can post your corrections in a reply to your original thread. If you can't find your original thread, click the "My Subscriptions" link near the top of the page. If you feel that your question has been overlooked, post a reply to it to "bump" it back to the top of the forum. We ask that you do this only once every 24 hours.

              So there is no reason to double post. It makes it hard on the Experts and you to keep track of what help you've already been given.

              Also, the Cafe is not the place for technical questions. Please post your questions in a single appropriate forum. If you don't know which, choose one, and we'll move it for you.

              Also, I have removed your Skype ID from your signature on this post. It is against our Signature Guidelines:

              From the FAQ (Things that are unacceptable in a signature)
              Your own or anyone else’s email address (this is for your own security) or other personal contact details
              MODERATOR

              Comment

              • dtittle
                New Member
                • Jan 2008
                • 8

                #8
                Sorry all, I am trying to keep focus on a button that is remapped to a virtual key. when I press the trigger ((PSION WORKABOUT PRO) device with a trigger grip). I want to fire the RFID reader. It works the first time; however, after reading tag and displaying the output, the focus leaves the read button, So yes, Plater I am trying as you asked, to keep the focus to on the read button at all times.

                Comment

                • akshaycjoshi
                  New Member
                  • Jan 2007
                  • 153

                  #9
                  private void cmdRead_KeyDown (object sender, System.Windows. Forms.KeyEventA rgs e)
                  {
                  if (e.KeyCode == Keys.F24)
                  {
                  StartReading();
                  buttonname.Focu s();
                  }
                  }

                  There is nothing difficult about using this method then why is it causing so much probels for you.
                  Anyways consult the SDK for more information.

                  Comment

                  Working...