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(); } }解决方法 作为这个 post中接受的答案,你必须使用JavaScript来获得你的clinet方面的SelectionStart和SelectionEnd.然后,通过重置数据将结果(可能使用隐藏的输入值)发布到服务器:
How to get selected text from textbox control with javascript
总结以上是内存溢出为你收集整理的c# – 查找文本框光标位置,行号.和列号.在asp.net中全部内容,希望文章能够帮你解决c# – 查找文本框光标位置,行号.和列号.在asp.net中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)