我想創建一個從多行文本框向外部程序發送密鑰的程序。 在文本框中是多行文本,但我需要第一行, 並將它發送到外部程序。C#如何在帶有sendkeys的循環中讀取第一行,然後是第二行,然後是第三行?
這個想法是,在一個循環中完成它,並在它到達最後一行時停止。
我做了一些代碼,但它並不像我需要的那樣工作,即時通訊不是最好的這種編程語言。
文本在多行文本框:
Hello im here
Here to create
Create for honor
honor for all
all for hello
Hello im here
Here to create
Create for honor
honor for all
all for hello
代碼:
private void button1_Click(object sender, EventArgs e)
{
// Countdown of 5 seconds before the SendKeys starts sending.
timer1.Start();
System.Threading.Thread.Sleep(5000);
for (int i = 0; i < richTextBox1.Lines.Length; i++)
{
SendKeys.Send(richTextBox1.Lines[i] + "\r\n");
// First line
// Start timer1 agian to read second line.
//
}
// Loop ends when it hits the last line (Bottom).
}
什麼在下面的代碼發生不正是我需要的, 它將分隔行一次發送整個文本.. 這樣的:
Hello im here
Here to create
Create for honor
honor for all
all for hello
Hello im here
Here to create
Create for honor
honor for all
all for hello
但我需要像這樣:
Hello im here
//first line -> Timer1 ends -> Start Timer1 agian to read second line
Here to create
//Second line -> Timer1 ends -> Start Timer1 agian to read third line
Create for honor
//Third line -> Timer1 ends -> Start Timer1 agian to read fourth line
等等等到循環點擊最後一行,並停在最後一行。
Got it!但如何只獲得第一條線? 我得到了您的代碼,並將richTextBox1.Lines [i]更改爲richTextBox1.Lines [0],因此它只會選取第一行。 它發送第一行! :d 但也有117行的文本框,並將其發送117X的第一行.. 如何挑選只在第一行沒有第一線去乘 –
@AlJuicebox你只想要發送的第一線?這不是你最初提出的問題。在這種情況下,只需刪除'for'循環並執行'Thread.Sleep',然後執行'SendKeys.Send(richTextBox1.Lines [0] +「\ r \ n」);'。 – hnefatl
我得到了它的工作。對不起,我沒有問起第一個地方.. 我做了for(int i = 0; i