Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Text to Notepad by VB.NET 1

Status
Not open for further replies.

BDRichardson

Programmer
Jul 23, 2003
46
GB
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.

Many thanks for your assistance.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top