Saving the caret position in editor

This commit is contained in:
Sigmanor 2016-01-23 21:24:56 +02:00
parent f619cc6777
commit f4bc5b860b

View file

@ -27,6 +27,7 @@ public partial class MainWindow : Form
public static bool textSave = false;
public static string[] args = Environment.GetCommandLineArgs();
Properties.Settings ps = Properties.Settings.Default;
int caretPos = 0;
public MainWindow()
{
@ -650,6 +651,7 @@ private void searchTextBox_KeyDown(object sender, KeyEventArgs e)
customRTB.Height = customRTB.Height += 27;
customRTB.Focus();
customRTB.DeselectAll();
customRTB.SelectionStart = caretPos;
e.Handled = e.SuppressKeyPress = true;
}
}
@ -752,7 +754,7 @@ private void findToolStripMenuItem2_Click(object sender, EventArgs e)
{
panel1.Visible = true;
searchTextBox.Focus();
SendMessage(customRTB.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(-1));
//SendMessage(customRTB.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(-1));
customRTB.Height = customRTB.Height - 27;
return;
}
@ -763,11 +765,11 @@ private void findToolStripMenuItem2_Click(object sender, EventArgs e)
panel1.Visible = false;
customRTB.Height = customRTB.Height += 27;
customRTB.Focus();
SendMessage(customRTB.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(1));
//SendMessage(customRTB.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(1));
customRTB.DeselectAll();
customRTB.SelectionStart = caretPos;
return;
}
string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
customRTB.Select(Convert.ToInt32(cc2), 0);
}
private void documentationToolStripMenuItem_Click(object sender, EventArgs e)
@ -946,6 +948,7 @@ void AutoLock(bool minimize)
string saveText = customRTB.Text;
Form2 f2 = new Form2();
key = "";
caretPos = customRTB.SelectionStart;
this.Hide();
if (minimize == true)
{
@ -978,7 +981,7 @@ void AutoLock(bool minimize)
textSave = false;
string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
customRTB.Select(Convert.ToInt32(cc2), 0);
customRTB.SelectionStart = caretPos;
textSave = true;
this.Show();
}
@ -1039,5 +1042,15 @@ private void lockToolStripMenuItem_Click(object sender, EventArgs e)
deleteFileToolStripMenuItem.Enabled = true;
}
}
private void customRTB_Click(object sender, EventArgs e)
{
caretPos = customRTB.SelectionStart;
}
private void customRTB_KeyDown(object sender, KeyEventArgs e)
{
caretPos = customRTB.SelectionStart;
}
}
}