选择带有反斜杠的整个文本

时间:2015-07-04 09:25:44

标签: c# select textbox

我正在创建一个搜索程序,我想在多行文本框中显示找到的文件的路径。问题是我想选择文件的整个路径,但由于存在反斜杠,我不能。我怎样才能做到这一点?我尝试了这个,但效果不好。

private void textBox2_Click(object sender, EventArgs e) {
    try {
        int x = d.length_sum(path, textBox2.GetLineFromCharIndex(textBox2.SelectionStart));
        int y = path[textBox2.GetLineFromCharIndex(textBox2.SelectionStart)].Length + d.num_backslash(path[textBox2.GetLineFromCharIndex(textBox2.SelectionStart)]);
        textBox2.Select(x, y);
        string aux = textBox2.SelectedText;
        selected_files.Add(aux);
        textBox3.Text += aux;
        textBox3.Text += Environment.NewLine;
    }
    catch { }
}

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,那么应该这样做:

private void textBox2_Click(object sender, EventArgs e)
{
    int line = textBox2.GetLineFromCharIndex(textBox1.SelectionStart);
    if (line >= 0 && line < textBox2.Lines.Length) 
        Console.WriteLine(textBox2.Lines[line]);  // or whatever you want to do with it..
}