I want to send every item from my listbox to a notepad,but my logic is kinda beating me.
private void send_Click(object sender, EventArgs e)
{
var notepad = Process.GetProcessesByName("Notepad").FirstOrDefault(p => p.MainWindowTitle == "Untitled - Notepad");
if (notepad != null)
{
if (IsIconic(notepad.MainWindowHandle))
ShowWindow(notepad.MainWindowHandle, 9);
SetForegroundWindow(notepad.MainWindowHandle);
string text = "";
foreach (var item in listBox1.Items)
{
text = item.ToString();
Clipboard.SetText(text);
SendKeys.Send("^V");
SendKeys.Send("{ENTER}");
}
}
}
In my logic this should send every item from the listbox to a notepad every item on a different line.But that doesn't happen every time,sometimes it just sends the only the last item from the listbox as many items there are in the listbox. Am I missing something?