1

I'm trying to override

protected override void OnInputLanguageChanging(System.Windows.Forms.InputLanguageChangingEventArgs e)
{ 
}

In my Main Form class C# app (Tested on .NET Framework 4.7.2 and 4.8)

The expectation is to have it called, when the user tries to change the Windows language. Unfortunatelly it doesn't work, the method is not called, however the method OnInputLanguageChanged works perfectly but it's too late for me. Is there any trick to have OnInputLanguageChanging working? Thanks

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Shark
  • 165
  • 1
  • 12
  • .NET Framework 4.5.2 is out of support. The oldest supported version is 4.6.2. You aren't using 4.5.2 anyway - all supported Windows versions come with 4.6.2. Even if you target 4.5.2, your application is running on the existing runtime – Panagiotis Kanavos Jan 12 '23 at 09:28
  • BTW even [Windows 8.1 has reached End Of Life](https://support.microsoft.com/en-us/windows/windows-8-1-support-will-end-on-january-10-2023-3cfd4cde-f611-496a-8057-923fba401e93) which means you can't get any kind of support even if you pay MS for it. `Microsoft will not be offering an Extended Security Update (ESU) program for Windows 8.1.` – Panagiotis Kanavos Jan 12 '23 at 09:33
  • It's doesn't work on .NET Framework 4.7.2 either – Shark Jan 12 '23 at 09:49
  • 1
    `when the user tries to change the Windows language` that's incorrect. The event is called *Input*LanguageChanging, not WindowsLanguageChanging. The [InputLanguageChanging](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.inputlanguagechanging?view=netframework-4.7) docs say : `Occurs when the user attempts to change the input language for the form.`. That's when the user hits eg Alt-Shift to change the keyboard language. There are two events though, `Changing` and `Changed`. When the user uses Alt-Shift to change the language, only `Changed` is fired – Panagiotis Kanavos Jan 12 '23 at 09:51
  • There's a similar question [here](https://stackoverflow.com/questions/26617159/hook-detect-windows-language-change-even-when-app-not-focused). When a user changes the keyboard with Alt-Shift, the OS sends `WM_INPUTLANGCHANGE` to the top-most application *after* the change. That corresponds to `InputLanguageChanged`. The `Changing` event would correspond to the `WM_INPUTLANGCHANGEREQUEST` message. It seems WinForms handles this automatically and never raises the event – Panagiotis Kanavos Jan 12 '23 at 10:01
  • From the [WM_INPUTLANGCHANGEREQUEST](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-inputlangchangerequest) docs: `When the DefWindowProc function receives the WM_INPUTLANGCHANGEREQUEST message, it activates the new input locale and notifies the application of the change by sending the WM_INPUTLANGCHANGE message.` I guess since the input *does* change in a WinForms app, the message is already handled and only `Changed` is raised – Panagiotis Kanavos Jan 12 '23 at 10:03
  • In my scenario OnInputLanguageChanging in not called but OnInputLanguageChanged works perfectly. Why? – Shark Jan 12 '23 at 10:04
  • There should be some BUG/Undocumented changes(/or maybe documented, but I couldn't find), the form or the application is not receiving `WM_INPUTLANGCHANGEREQUEST`, so the event will not raise. – Reza Aghaei Jan 12 '23 at 10:06
  • There's an open issue here: https://github.com/MicrosoftDocs/feedback/issues/1863 – Reza Aghaei Jan 12 '23 at 10:18
  • @RezaAghaei that issue is essentially ignored. It does show this isn't a .NET Framework problem though. WinForms is open source now and the source [shows both messages are handled the same way](https://github.com/dotnet/winforms/blob/6042cca9a51875f4625e43bd2167e0d53984ab84/src/System.Windows.Forms/src/System/Windows/Forms/Control.Ime.cs#L703). There were significant changes in how input works from Windows 8 all the way to 11 so *maybe* Windows no longer allows applications to change each other's language or reject a change. If that is no longer allowed, there's no reason to send the REQUEST – Panagiotis Kanavos Jan 12 '23 at 10:25
  • [4.8 source](https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Control.cs,14200) also shows it's expected to work. It's probably Windows Bug or contract change. – Reza Aghaei Jan 12 '23 at 10:29
  • @RezaAghaei not a bug, a conscious change. If that was a bug, no Winforms or WPF application would work at all. By now even WPF is considered community-supported, so I doubt there will be any significant changes to this. – Panagiotis Kanavos Jan 12 '23 at 10:30
  • Nothing to do with WinForms or WPF I guess, but as far as I see, Microsoft (and community) are doing good improvements and maintenance on [WinForms](https://github.com/dotnet/winforms). – Reza Aghaei Jan 12 '23 at 10:32

0 Answers0