Entering text backwards

G

Guest

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.)
 
D

durstin

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;

}
 
G

Guest

Thanks. I'm always surprised by what turns out to be easy, and what is
difficult or impossible. I really thought there would just be some sort of
setting that I could set, and it would just work.

Unfortunately, the solution is not workable for my particular problem. I'm
trying to enter Canaanite text, but really I'm trying to do more than that.
The program is for linguists. I'm trying to enter text in any language the
user decides upon, which might include all sorts of "dead languages" like
Canannite, along with constructed languages, like Tolkein's languages or
Klingon.

The variation in text, keyboards, and font mappings prevent me from doing
anything that maps specific characters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top