我是Web应用程序开发的初学者.我有一个
Windows应用程序的代码.我必须转换为Web应用程序的相同功能.我有一个文本框控件.我正在加载一些文本到该文本框.我想找到当前光标位置,行号和列号. Windows应用程序的代码如下:
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。