【发布时间】:2012-02-12 00:40:28
【问题描述】:
我是 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();
}
}
【问题讨论】:
-
您必须使用 javascript 才能获得相同的功能。由于选择是客户端的,而该代码将是服务器端的。