Windows .NET compact framework 3.5 lost focus event not working properly

695 views Asked by At

We are currently migrating a PDA application from .NET compact framework 1.1 to .NET compact framework 3.5.
PDA having operating system Windows 6.0 and 6.5 installed.

On got_focus event of custom text box we have wrote below code

enter code here
private void tbCustom_GotFocus(object sender, EventArgs e)
{ 
    m_Keypad.SetBuffer(tbMileage.Text);
    m_Keypad.HideOSKeyPad();
    m_Keypad.Show();
    this.m_ToolBarButtonNumericKeypad.ImageIndex = 11;
    tbCustom.Focus();
}

its working fine in .NET CF 1.1 but while we convert this code into 3.5 without changing any code its just got into recursive and applcaiton is got crash. Please provide help about this. Thanks in advance.

3

There are 3 answers

0
user3107750 On BEST ANSWER

There are couple of Pinvoke metthods used for opening the custom keypad window without a focus on it. This API works in CF1.0 however it doesn't work for .NET CF3.5 Following is the correct one for .NET CF3.5

[DllImport("coredll.dll", SetLastError = true)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("coredll.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
2
Nicolas R On

Woooow... GotFocus occurs when the control receives (=has) focus, not when giving focus. And in your method you end by focusing into the control that is throwing this event => loop!

tbCustom has focused => your code run, and it set focus to tbCustom => your code run...

Remove this line from your method:

tbCustom.Focus();

Doc about GotFocus: http://msdn.microsoft.com/fr-fr/library/system.windows.forms.control.gotfocus(v=vs.110).aspx

0
RuedigerKausK On

What about:

private void tbCustom_GotFocus(object sender, EventArgs e)
{
    if (m_Keypad.Visible == false)
    {
        m_Keypad.SetBuffer(tbMileage.Text);
        m_Keypad.HideOSKeyPad();
        m_Keypad.Show();
        this.m_ToolBarButtonNumericKeypad.ImageIndex = 11;
        tbCustom.Focus();
    }
}