Hi, sorry it took so long for a reply, had to wipe pc and re-install everything. To overcome this problem, you need to simply split the string in 2 and add the text in right place. Here's the modified bits of code:
First add these public variables:
public partial class Form1 : Form
{
string str1;
string str2;
int CursPos;
Then change next part to:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (textBox1.SelectionStart < textBox1.Text.Length)
{
str1 = textBox1.Text.Substring(0, textBox1.SelectionStart);
str2 = textBox1.Text.Substring(textBox1.SelectionStart);
CursPos = textBox1.SelectionStart +1;
}
else
{
str1 = textBox1.Text;
str2 = "";
}
if (e.KeyChar == 'a')
{
awrite();
}
// Rest of code as normal until public void uwrite
Then at public void uwrite:
public void uwrite()
{
char ye;
string word;
ye = '\u06CC';
word = ye.ToString();
textBox1.Text = str1 + word + str2;
// int Tlen = textBox1.Text.Length;
// textBox1.Text = textBox1.Text.Substring(0, Tlen - 1) + word;
if (str2 == "")
{
textBox1.SelectionStart = textBox1.Text.Length;
}
else
{
textBox1.SelectionStart = CursPos;
}
}
Apply above alteration to swrite, dwrite etc. You should find now that it works as intended, let me know either way. Dai.
------------------------------------------
Do or do not, there is no try. |
------------------------------------------