Have any of you clever people got any ideas how I could send some text, like a message, to Notepad? I need to leave to leave some text in Notepad when my program finishes/
Save the text to a file using the StreamWriter object, then start a process using the filename - this will automatically start Notepad.
Code:
Dim sw As New System.IO.StreamWriter(Application.StartupPath & "\sample.txt")
sw.Write("This is the text you want to show in Notepad.")
sw.Close()
Dim p As New System.Diagnostics.Process
p.StartInfo.FileName = Application.StartupPath & "\sample.txt"
p.Start()
Yes, I have been looking into using the StreamWriter object. I was hoping to try and do it without actually needing to create a file. A tad trivial I suppose. I think I will just have to create a temporary file, and ensure that I overwrite it every time.
You don't actually have to create a file. If the file is already there, it (StreamWriter) will overwrite it. If not, it will create it. You can of course set up checks and balances for incase the file does not exist, to not try to create it. That would bypass the purpose of a "log" file (file that is keeping track of your messages).
You can also use the SendKeys.Send method (in System.Windows.Forms namespace). The catch is it only sends to the current active application. You can run Notepad using Thread.Start (as in SHelton's post), and then force it to be active with the Win32 API calls FindWindow and SetForegroundWindow.
Chip H.
If you want to get the best response to a question, please check out FAQ222-2244 first
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.