I am starting to develop web applications. I have a windows application code. I have to convert such functionality to a web application. I have a control text box. I am loading text in this text box. I want to find the current cursor position, row number and column number. The code for the Windows application is shown below:
private void Form1_Load(object sender, EventArgs e) { textBox1.Text = @"This is a demo for text box control I am trying to find the cursor position , line no and column no of the cursor."; } private void textBox1_Click(object sender, EventArgs e) { textBox1.SelectionStart++; label2.Text = textBox1.SelectionStart.ToString(); int i = textBox1.GetLineFromCharIndex(textBox1.SelectionStart); label3.Text = i.ToString(); int j =textBox1.SelectionStart - textBox1. GetFirstCharIndexFromLine(i); label4.Text = j.ToString(); } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Right) || (e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Down)) { textBox1.SelectionStart++; label2.Text = textBox1.SelectionStart.ToString(); int i = textBox1.GetLineFromCharIndex(textBox1.SelectionStart); label3.Text = i.ToString(); int j = textBox1.SelectionStart - textBox1.GetFirstCharIndexFromLine(i); label4.Text = j.ToString(); } }
source share