c# – 查找文本框光标位置,行号.和列号.在asp.net中

c# – 查找文本框光标位置,行号.和列号.在asp.net中,第1张

概述我是Web应用程序开发的初学者.我有一个 Windows应用程序的代码.我必须转换为Web应用程序的相同功能.我有一个文本框控件.我正在加载一些文本到该文本框.我想找到当前光标位置,行号和列号. Windows应用程序的代码如下: private void Form1_Load(object sender, EventArgs e) { textBox1.Text = @" @H_301_1@ 我是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

总结

以上是内存溢出为你收集整理的c# – 查找文本框光标位置,行号.和列号.在asp.net中全部内容,希望文章能够帮你解决c# – 查找文本框光标位置,行号.和列号.在asp.net中所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1234302.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存