RE: Textbox, keypress keychar, non ASCII characters
- From: v-jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Fri, 24 Jun 2005 02:04:06 GMT
Hi kenneth,
Thanks for your feedback.
For this request, I think we can first get the text change
notification(with OnTextChanged method or TextChanged event), then in this
method/event, just determine if the modified text content string is ascii
characters string.
I think the key point is the last step: how to determine a string is ascii
character string. Normally, we can use ASCIIEncoding.GetBytes() method to
get the byte array of the string, when if certain character is Unicode
character and can not be parse as ascii code, it will become '?'(which is
0x3f) character in the result byte array. So we can just determine if the
result byte array contains any 0x3f value. If not, the input is valid,
else, the we can reset the content back to its original value. Sample code
like this:
public class MyTextBox : System.Windows.Forms.TextBox
{
private string OriginalText=string.Empty;
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged (e);
byte[] newtextbytes=ASCIIEncoding.ASCII.GetBytes(this.Text);
for(int i=0;i<newtextbytes.Length;i++)
{
if(newtextbytes[i]==0x3f)
{
this.Text=OriginalText;
return;
}
}
OriginalText=this.Text;
}
}
This code snippet works well on my side, for your information.
=======================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.
- Follow-Ups:
- RE: Textbox, keypress keychar, non ASCII characters
- From: kenneth@nospam.nospam
- RE: Textbox, keypress keychar, non ASCII characters
- References:
- Textbox, keypress keychar, non ASCII characters
- From: kenneth@nospam.nospam
- RE: Textbox, keypress keychar, non ASCII characters
- From: "Jeffrey Tan[MSFT]"
- RE: Textbox, keypress keychar, non ASCII characters
- From: kenneth@nospam.nospam
- RE: Textbox, keypress keychar, non ASCII characters
- From: "Jeffrey Tan[MSFT]"
- RE: Textbox, keypress keychar, non ASCII characters
- From: kenneth@nospam.nospam
- Textbox, keypress keychar, non ASCII characters
- Prev by Date: Set the left "column length" of my Datagrid
- Next by Date: Re: Need to use a mix of normal & checked treenode
- Previous by thread: RE: Textbox, keypress keychar, non ASCII characters
- Next by thread: RE: Textbox, keypress keychar, non ASCII characters
- Index(es):
Relevant Pages
|