0

i have a problem setting the FOCUS event on my NUMERICUPDOWN control..

My program initially sets the numericupdown.enabled property to false with the following code:

for (int i = 1; i < 10; i++)
{
    NumericUpDown nud = (NumericUpDown)FindForm().Controls.Find("talla_n" + i, true)[0];
    nud.Enabled = false;
}

Later after doing some actions, it set the property to true again.

for (int i = 1; i < 10; i++)
{
    NumericUpDown nud = (NumericUpDown)FindForm().Controls.Find("talla_n" + i, true)[0];
    nud.Enabled = true;
}

After that, i use the focus function:

NumericUpDown nud = (NumericUpDown)FindForm().Controls.Find("talla_n1", true)[0];
bool focused = nud.Focus();

But it always returns FALSE after the FOCUS Function.

Console.WriteLine(focused); // always returns false

I've turn the TabStop = true and Enabled = true, so i dont know whats the problem..

This is my code for Designer

// 
// talla_n1
// 
this.talla_n1.Location = new System.Drawing.Point(73, 64);
this.talla_n1.Name = "talla_n1";
this.talla_n1.Size = new System.Drawing.Size(41, 22);
this.talla_n1.TabIndex = 18;
this.talla_n1.Tag = "talla_n1";
this.talla_n1.TabStop = true;
this.talla_n1.Enabled = true;
this.talla_n1.ValueChanged += new System.EventHandler(this.textChanged_Numeracion_EventHandler);
this.talla_n1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.talla_n1_KeyDown);
Gerson F
  • 9
  • 1
  • FindForm? What control is the form on? The control can't get the focus if the form isn't the active form. – LarsTech Mar 08 '18 at 20:54
  • The FindForm function works fine while setting the Enabled Property. Alternatively Im using the code talla_n1.Focus(); and isn't working either. – Gerson F Mar 08 '18 at 20:59
  • 1
    You ignored my question. What control is the form on? If you can just use `talia_n1.Focus();`, then why go through the FindForm function? `talia_n1.Select();` is probably the preferred way to do this. – LarsTech Mar 08 '18 at 21:02
  • In the form there is 9 NumericUpDown (Inside a GroupBox), some Buttons. That answer your question? Im trying to set focus in various ways but without success in any of them, i try the findForm function alternatively to the basic way (Control.Focus and Control.Select) but is not working either. – Gerson F Mar 08 '18 at 21:12
  • 1
    By posting code using FindForm, you implied there are other forms involved. Hence the confusion. You have to post code that duplicates the problem. Right now, you haven't done that. Makes it tough to help you. – LarsTech Mar 08 '18 at 21:19
  • Possible duplicate of [What's the difference between Control.Select() and Control.Focus()?](https://stackoverflow.com/questions/802722/whats-the-difference-between-control-select-and-control-focus) – Mark Benningfield Mar 09 '18 at 00:06

0 Answers0