Re: Entering text backwards
- From: "durstin" <durstin.selfridge@xxxxxxxxx>
- Date: Wed, 11 May 2005 16:51:56 -0700
There may be some clever cultural trick available, but you could handle the
keypress event and do your own string construction, something along the
following. You would probably want to create your own subclassed textbox
control:
private void textBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
TextBox txtBox = (TextBox) sender;
string text = txtBox.Text;
int selectionStart = txtBox.SelectionStart;
// Alphanumerics
if (33 <= e.KeyChar && e.KeyChar <= 122)
{
if (txtBox.SelectionStart == 0)
text = e.KeyChar + text;
else
{
text = text.Substring(0, selectionStart) + e.KeyChar +
text.Substring(selectionStart , text.Length - selectionStart);
}
e.Handled = true;
}
// Backspace -- treat as Delete
// unless some text is selected, in which case it behaves as normal
else if (e.KeyChar == 8 && txtBox.SelectionLength == 0 && selectionStart <
text.Length)
{
text = text.Remove(selectionStart, 1);
e.Handled = true;
}
// Delete -- doesn't get captured by KeyPress
txtBox.Text = text;
// return character entry point to original location
txtBox.SelectionStart = selectionStart;
}
"David" <David@xxxxxxxxxxxxx> wrote in message
news:16E43C83-AF2B-4A18-A2D8-AFAA9C58BF42@xxxxxxxxxxxxxxxx
> I want to enter text in a textbox, but have it appear right to left. I
want
> to keep the English cultural settings to do it. When I select RightToLeft
=
> yes, and TextAlign=left, the text ends up right aligned. The entry cursor
> appears to the left of previously entered text, but when I actually type
the
> text, it is entered on the right side.
>
> (I'm actually not trying to enter English text. I'm trying to enter
> Canaanite text. But since the operating system doesn't recognize
Canaanite
> as a cultural setting, I am keeping the English setting, and using a font
> that maps English characters to Canaanite glyphs. So what I'm really
trying
> to do is to have the text behave as if I were entering Hebrew, but since
the
> font maps to the ascii characters, I can't change to Hebrew settings,
because
> I want the keyboard mapping to remain unchanged.)
.
- Follow-Ups:
- Re: Entering text backwards
- From: David
- Re: Entering text backwards
- References:
- Entering text backwards
- From: David
- Entering text backwards
- Prev by Date: Re: Combobox in Datagridview in Edit mode
- Next by Date: Re: Multi-coloured text in a winform application
- Previous by thread: Entering text backwards
- Next by thread: Re: Entering text backwards
- Index(es):
Relevant Pages
|