469,593 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,593 developers. It's quick & easy.

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.KeyEventArgs e)
{
if (e.KeyCode == Keys.F24)
{
StartReading();
}
}


Thanks,

dtittle
Skype: <removed>
Oct 14 '08 #1
8 10524
akshaycjoshi
153 100+
Use the Focus() method of the control to set focus on it.
Oct 14 '08 #2
As the name (newbie) applies, how do I do that?
Oct 14 '08 #3
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.KeyEventArgs e)
{
if (e.KeyCode == Keys.F24)
{
StartReading();
}
}
/CODE

I'm not sure if this is where the code would go either.
Oct 14 '08 #4
joedeene
583 512MB
Well drag a timer to your form in the designer view, and in the code view type in

Expand|Select|Wrap|Line Numbers
  1. private void timer1_Tick(object sender, EventArgs e)
  2.         {
  3.             button1.Focus();
  4.         }
  5.  
  6.         private void Form1_Load(object sender, EventArgs e)
  7.         {
  8.             timer1.Interval = 500;
  9.             timer1.Start();
  10.         }
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
Oct 14 '08 #5
Plater
7,872 Expert 4TB
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?
Oct 14 '08 #6
Curtis Rutland
3,256 Expert 2GB
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
Oct 14 '08 #7
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.
Oct 14 '08 #8
akshaycjoshi
153 100+
private void cmdRead_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.F24)
{
StartReading();
buttonname.Focus();
}
}

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.
Oct 15 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by bradwiseathome | last post: by
3 posts views Thread by Brian Henry | last post: by
4 posts views Thread by Johannes Kiehl | last post: by
7 posts views Thread by Dave Booker | last post: by
2 posts views Thread by karinmorena | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.