用C#中的Process方法集中匹配打开的记事本中的单词



我正在尝试将CTRL-F机制添加到visual studio中的C#应用程序中。

我的应用程序使用Process.start方法打开Windows记事本并查找给定的单词。我想在记事本上找到这个词并集中注意力。

我有一种搜索这个词的方法,但如果用户点击CTRL-F,如何将注意力集中在正确的行上?

有人知道怎么做吗?或者可能有一个框架可以帮助你?

我的应用程序是通过在文本框中键入任何字符串序列来搜索任何文件,并获得包含它的文件,之后我有了这个文件的打开功能,我想获得焦点词,我在打开的记事本中键入了它(因为我得到了包含这个字符串的txt文件(

例如,我键入";你好";在textbox中获取file.txt,打开后在里面我有一个焦点词";你好";

执行此操作的代码:

private async void button2_Click(object sender, EventArgs e)
{
Process.Start("yourProcess");
this.WindowState = FormWindowState.Minimized;
await Task.Delay(1000);
SendKeys.Send("^(f)");
foreach (char c in textBox1.Text)
{
SendKeys.Send("{" + c + "}");
}
SendKeys.Send("{ENTER}");
//if you want to automatycally remove search window use:
SendKeys.Send("{ESC}");
}

下面是我目前在内部的代码(但不起作用(:"private async void OpeningFile_Click(object sender,RoutedEventArgs e(";

try
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = PathResult.ToString();
startInfo.Arguments = """ + PathResult.ToString() + """;
startInfo.UseShellExecute = true;
Process.Start(startInfo);

MessageBox.Show(ControlHelper.WordToFind);

await Task.Delay(1000);

System.Windows.Forms.SendKeys.SendWait("^(f)");
foreach(char x in ControlHelper.WordToFind)
{
System.Windows.Forms.SendKeys.SendWait("{" + x + "}");
}
System.Windows.Forms.SendKeys.SendWait("{ENTER}");

System.Windows.Forms.SendKeys.SendWait("{ESC}");          
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "n" + PathResult.ToString());
}

最新更新