Hello Gidi
One way you could do this is by trapping the windows message that is
generated by the keystroke.
i.e. the Lparam of the keystroke is the same regardless of language settings.
cut 'n' paste the following into a form and a class respectively
Form...
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace TestKB
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private testMessageFilter fltHelp;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//create a new messagefilter
fltHelp = new testMessageFilter();
//add the filter to the application
Application.AddMessageFilter(fltHelp);
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 64);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(224, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(360, 334);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
Class....
using System;
using System.Windows.Forms ;
namespace TestKB
{
/// <summary>
/// Summary description for MessageFilter.
/// </summary>
public class testMessageFilter:IMessageFilter
{
private System.Windows.Forms.Form m_Parent;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg <30000 & m.Msg != 280)
{
MessageBox.Show(m.LParam.ToString());
}
return false;
}
public System.Windows.Forms.Form Parent
{
get
{
return m_Parent ;
}
set
{
m_Parent = value;
}
}
}
}
the messageboxes that pop represent the key that is pressed not the
cahracter... you can map these to english keyboard characters..
kind regards
Ronnie
"Gidi" wrote:
Hi,
For the last week, i'm looking for a way to make a TextBox always write in
English (No matter what the OS default language is).
i asked here few times but the answers i got didn't help me. i search in
google and found a way with changing the CultureInfo but still didn't work on
a TextBox. i'm sure there's a way to do that, but i don't know what's the way.
I'm desperate, if some one knows the answer, i will be very thankful to know
it also (example will be great....)
Thanks,