Answered by:
c# code snippet

Question
-
if (myRadioButton1.Focus().ToString())
why is this code snippet wrong?
Saturday, June 9, 2012 3:35 PM
Answers
-
Hi,
The question is: What do you intend to do?
Do you wanna check if radionbutton has a focus? If so do:
if (myRadioButton1.Focused) { //has focus }
Or you wanna get some other information out or control?
Mitja
- Marked as answer by Lisa ZhuModerator Wednesday, June 13, 2012 9:40 AM
Saturday, June 9, 2012 4:56 PM -
Because you are not comparing the string value that is being returned to anything. Perhaps you meant to use something like:
if (myRadioButton1.Focus()) { }
It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.
- Marked as answer by ms811 Sunday, June 10, 2012 2:31 AM
Saturday, June 9, 2012 3:47 PM -
All replies
-
which is this code snippet wrong?
- Merged by Lisa ZhuModerator Monday, June 11, 2012 5:06 AM duplicate
Saturday, June 9, 2012 3:34 PM -
Because you are not comparing the string value that is being returned to anything. Perhaps you meant to use something like:
if (myRadioButton1.Focus()) { }
It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.
- Marked as answer by ms811 Sunday, June 10, 2012 2:31 AM
Saturday, June 9, 2012 3:47 PM -
There are two errors:
- You're calling ToString non a void method (Focus)
- The if instruction needs a boolean condition, while you're trying to use a string.
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominervaSaturday, June 9, 2012 4:31 PM -
Hi,
The question is: What do you intend to do?
Do you wanna check if radionbutton has a focus? If so do:
if (myRadioButton1.Focused) { //has focus }
Or you wanna get some other information out or control?
Mitja
- Marked as answer by Lisa ZhuModerator Wednesday, June 13, 2012 9:40 AM
Saturday, June 9, 2012 4:56 PM -
could you please elaborate
ms
Sunday, June 10, 2012 2:31 AM -
Hello ms811,
which is this code snippet wrong?
not very clear what you ask, if you give some more information we can better assist you, if you check one or more RadioButton, if only one code Mitja does what you ask, but if you have more than one board or you a ForEach loop or Linq To Objects , one sample here.
private void Form1_KeyDown(object sender, KeyEventArgs e) { foreach (var myRadioButton in Controls.OfType<RadioButton>().Where(myRadioButton => myRadioButton.Focused)) { MessageBox.Show(string.Format("Focused is on {0}", myRadioButton.Name)); } }
For to try this sample please set KeyPreview of your form to true , and manage keyDown event del Form .
Regards.
- Carmelo La Monica
- Visual Basic Tips e Tricks Blog
- WordPress.com Blog
- Blogger
- Edited by Carmelo La Monica Sunday, June 10, 2012 9:24 AM
Sunday, June 10, 2012 9:05 AM -
Kindly provide more info about what you want to do?Sunday, June 10, 2012 9:11 AM
-