选择其中包含反斜杠的整个文本

Selecting whole text with backslashes in it

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

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 { }
}

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

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..
}