If you are writing a forms application, Form has an event handler for this.
http://msdn2.microsoft.com/en-us/library/system.windows.forms.inputlanguagechang
edeventargs.aspx
Thanks, but this event rises only on input language change in my form, I want
to know every time the user changes his language, even if it is in another
form / window / process.
> If you are writing a forms application, Form has an event handler for this.
>
[quoted text clipped - 16 lines]
> > Ofry
> >
Willy Denoyette [MVP] - 20 Feb 2008 10:24 GMT
> Thanks, but this event rises only on input language change in my form, I
> want
> to know every time the user changes his language, even if it is in another
> form / window / process.
Don't know what you mean by this, the "InputLanguageChanged" event is raised
when the *user* changes the input language at the system level, all windows
application running in the users login session will get this event (a
windows message WM_INPUTLANGCHANGE) when the user changes the input
language.
Consider following sample:
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
public class Form1 : System.Windows.Forms.Form
{
Label lbl = new Label();
public Form1()
{
this.Controls.Add(lbl);
lbl.Size = new Size(400, 48);
lbl.Padding = new Padding(5);
// uncomment if you want to handle the event in the
InputLanguageChangedEventHandler
//this.InputLanguageChanged += new
InputLanguageChangedEventHandler(languageChange);
}
private void languageChange(Object sender, InputLanguageChangedEventArgs
e)
{
lbl.Text = e.InputLanguage.Culture.ToString();
}
protected override void WndProc(ref Message m)
{
if(m.Msg == 0x0051) // WM_INPUTLANGCHANGE
{
lbl.Text = string.Format("Posting Thread: {0} \n{1}",
Thread.CurrentThread.ManagedThreadId, m);
}
base.WndProc(ref m);
}
public static void Main(string[] args)
{
Application.Run(new Form1());
}
}
This illustrates how you can add your own handler by overriding WndProc, or
using the predefined handler for this message, however, both handle the same
message!.
Willy.