C# closing maximized keyboard cuts off program

339 views Asked by At

I managed to get a keyboard in windows 8 to show when clicking on a NumericUpDown box in a new form that I made pop up. Unfortunately, it seems that after closing the keyboard on "lost focus", the window is distorted and wont show the entire program until that popup window is closed.

//Close keyboard
void CopiedNudPass_LostFocus(object sender, EventArgs e)
{

    Version win8version = new Version(6, 2, 9200, 0);

    if (Environment.OSVersion.Version >= win8version)
    {
        Process[] oskProcessArray = Process.GetProcessesByName("TabTip");
        foreach (Process onscreenProcess in oskProcessArray)
        {
            onscreenProcess.Kill();
        }
    Refresh();
    }
}

So, basically, I need to refresh the background window when closing the keyboard from the currently opened form. Any advice is appreciated. Thank you.

1

There are 1 answers

0
fac7orx On

I found my solution here:

After killing the process for TabletKeyboard(TabTip.exe) application doesn't bring back to its original size in wpf

Here is my new close code:

//Close keyboard
void CopiedNudPass_LostFocus(object sender, EventArgs e)
{
        Version win8version = new Version(6, 2, 9200, 0);

        if (Environment.OSVersion.Version >= win8version)
        {
            uint WM_SYSCOMMAND = 274;
            uint SC_CLOSE = 61536;
            IntPtr KeyboardWnd = FindWindow("IPTip_Main_Window", null);
            PostMessage(KeyboardWnd.ToInt32(), WM_SYSCOMMAND, (int)SC_CLOSE, 0);
        }
}

I also had to add a reference to WindowsBase and add external functions to the project. The steps and additional code are in the url I linked to in this post. Here's how you add a reference for WindowsBase to get using System.Windows.Interop; to work:

  1. Right click on project
  2. Highlight Add and click Reference
  3. Ensure you have Framework selected under Assemblies
  4. Scroll down and check in "WindowsBase" and hit ok
  5. Add using System.Windows.Interop; at the top of your code and your done