471,599 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 software developers and data experts.

Hard Question - How to make a TextBox always write in English

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,
Nov 17 '05 #1
14 2737
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,


What do you mean by "always write in English"? I don't think
you mean "if the user types French (or any other language), translate
to English" :-)

Hans Kesting
Nov 17 '05 #2
Hi,

What i mean is, that no matter what the OS default language is, in the text
box it will always type the English Letter on the keyboard. for example if i
have a french keyboard and i want to print A (in english) i will press s (in
french) - meaning that if the A (english) and s (french) are the same key on
the keyboard it will always type the english letter. i don't mean to
translate.

"Hans Kesting" wrote:
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,


What do you mean by "always write in English"? I don't think
you mean "if the user types French (or any other language), translate
to English" :-)

Hans Kesting

Nov 17 '05 #3
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,

Nov 17 '05 #4
Ronnie,

First of all Thanks.

i tried that, but what i need is not to know which key was pressed. i want
to draw\print in the text box only the English Letters. i need that TextBox
will show only English Letters.
i.e. if my default langauge is French and i want to enter my name to that
textbox in english, i won't be have to change the langauge (by pressing
Alt+Shift), just by typing Gidi using the english Keys in the keyboard and
the textbox will display Gidi.

"Ronnie Edgar" wrote:
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,

Nov 17 '05 #5
If you're talking about the keyboardlayout:
Look for InputLanguage

Christof

"Gidi" <sh*****@hotmail.com.dontspam> schrieb im Newsbeitrag
news:F3**********************************@microsof t.com...
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,

Nov 17 '05 #6
HI Gidi

I don't think what you are trying to do is possible, as far as I am aware
there is no internal .net way to know that w on an english keyboard = z on a
french keyboard, so you will have to trap the keystrokes and somehow get
their source and then map these to english characters.

using the method outlined below, you get the following results.

when the key is located in the following UK position:

a the lparam for the message is 1966081 if you pressed the q key in france
(press the a key UK you get the same message)

q the lparam is 1048577 this is the french a key,

so you need to trap these messages, and map these to the UK equivalent
characters for these messages. therefore you will have to proxy the textbox
with the filter class

regards

Ronnie

"Gidi" wrote:
Ronnie,

First of all Thanks.

i tried that, but what i need is not to know which key was pressed. i want
to draw\print in the text box only the English Letters. i need that TextBox
will show only English Letters.
i.e. if my default langauge is French and i want to enter my name to that
textbox in english, i won't be have to change the langauge (by pressing
Alt+Shift), just by typing Gidi using the english Keys in the keyboard and
the textbox will display Gidi.

"Ronnie Edgar" wrote:
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,

Nov 17 '05 #7
Thanks,

If i set the InputLanguage to English (by the way how do i do that?), will
my textBox write only in English (at least until the user will change it)?

"Christof Nordiek" wrote:
If you're talking about the keyboardlayout:
Look for InputLanguage

Christof

"Gidi" <sh*****@hotmail.com.dontspam> schrieb im Newsbeitrag
news:F3**********************************@microsof t.com...
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,


Nov 17 '05 #8
You need to install the language you want to convert to, so if you are in
france and you want to convert to english layout you need to install the
english layout on the machine. Be aware that setting the
inputlanguage.CurrentLanguage or wahtever affects the whole thread, and not
just the textbox.

have a look at the InputLanguage Class and you will see usage.

regards

ronnie

"Gidi" wrote:
Thanks,

If i set the InputLanguage to English (by the way how do i do that?), will
my textBox write only in English (at least until the user will change it)?

"Christof Nordiek" wrote:
If you're talking about the keyboardlayout:
Look for InputLanguage

Christof

"Gidi" <sh*****@hotmail.com.dontspam> schrieb im Newsbeitrag
news:F3**********************************@microsof t.com...
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,


Nov 17 '05 #9
Thanks, Ronnie.

I have Hebrew and English installed on my machine, and i want to put my
program in machines that the default language is Hebrew (those machine will
have hebrew and english installed too). what i'm thinking to do is to change
the language each time the TextBox Get\Lose Focus, what do you think?

"Ronnie Edgar" wrote:
You need to install the language you want to convert to, so if you are in
france and you want to convert to english layout you need to install the
english layout on the machine. Be aware that setting the
inputlanguage.CurrentLanguage or wahtever affects the whole thread, and not
just the textbox.

have a look at the InputLanguage Class and you will see usage.

regards

ronnie

"Gidi" wrote:
Thanks,

If i set the InputLanguage to English (by the way how do i do that?), will
my textBox write only in English (at least until the user will change it)?

"Christof Nordiek" wrote:
If you're talking about the keyboardlayout:
Look for InputLanguage

Christof

"Gidi" <sh*****@hotmail.com.dontspam> schrieb im Newsbeitrag
news:F3**********************************@microsof t.com...
> 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,

Nov 17 '05 #10
Hi Gidi

That should work,

kind regards

Ronnie

Nov 17 '05 #11
Hi Ronnie,

if my Default langauage is Hebrew, how can i set the InputLangauge to be
English. there are only 2 kins of parameters CurrentLangauge and
DefaultLanguage, and when i look at the example in MSDN i get the same result
because when i start my program my default langauge is my current langauge.
so how can i change it?

"Ronnie Edgar" wrote:
Hi Gidi

That should work,

kind regards

Ronnie

Nov 17 '05 #12
Hi Ronnie,

i'm Happy to announce that i found a simple solution to this problem:

i'm checking if my current language is not english and while it's not i'm
sending alt+shift using SendKeys.Send("+%");

is there a better way to know what is the current language then :
if(myCurrentLanguage.Culture.EnglishName!="English (United States)")

the problem here is, if it won't be English United Sates and it will be
English UK it still be good but the alt+shift event will be called.

what do you think about my solution?
Thank you very much for your help
Gidi
"Ronnie Edgar" wrote:
Hi Gidi

That should work,

kind regards

Ronnie

Nov 17 '05 #13
Hi Gidi
if you use InputLanguage.CurrentInputLanguage and set it it sets the
language only for the program... and not! for the computer so you will not
see the language change at machine level only at application level.

regards
ronnie

Nov 17 '05 #14
Hi Gidi,

to get the InputLanguage you wish you can use the InputLanguage.FromCulture
method.

Christof

"Gidi" <sh*****@hotmail.com.dontspam> schrieb im Newsbeitrag
news:C0**********************************@microsof t.com...
Hi Ronnie,

if my Default langauage is Hebrew, how can i set the InputLangauge to be
English. there are only 2 kins of parameters CurrentLangauge and
DefaultLanguage, and when i look at the example in MSDN i get the same
result
because when i start my program my default langauge is my current
langauge.
so how can i change it?

"Ronnie Edgar" wrote:
Hi Gidi

That should work,

kind regards

Ronnie

Nov 17 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Hans-Joachim Widmaier | last post: by
33 posts views Thread by Xah Lee | last post: by
5 posts views Thread by Steve S | last post: by
4 posts views Thread by Dado | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.