0

There is form with text element that should receive focus every time form shown.

In .NET CF Form has no OnShow(n) event

I try to use workaround:

MyForm_GotFocus() // or MyForm_Activated
{
   txtTextControl.Text = string.Empty;
   txtTextControl.Focus()
}

txtTextControl_GotFocus()
{
    txtTextControl.SelectAll()
}

Code for getting form instance:

public static MyForm GetForm
{
    get
    {    
       if (s_inst == null || s_inst.IsDisposed)
       {
         s_inst = new MyForm();
       }
    return s_inst; 
    }
}

public static void ShowForm()
{
   var frm = GetForm;
   frm.Show();
}

1) First time ShowForm (Form instance has been created): txtTextControl emptied and got focus, txtTextControl_GotFocus event raised

2) Second time ShowForm : OK too

3) Third time ShowForm : txtTextControl emptied, but does not get focus

Is there bug or feature? Is there workaround? Show I rewrite ShowForm? Is OpenNETCF.IOC.UI is better solution (50 forms in project)?

1
  • Try overriding OnActivated and then focusing your textbox (or whatever you want to do). There's no way for me to test this right now, so I won't post it as an answer because I do not know for sure that it will work. If it works, comment, and I'll re-post as answer.
    – Alan
    Apr 28, 2013 at 7:34

1 Answer 1

0

I had that same question once.

Set the TabIndex for the control to 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.