Click here to Skip to main content
15,907,396 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Make the Text Bold ?? Pin
Ravenet11-Feb-08 4:14
Ravenet11-Feb-08 4:14 
GeneralRe: How to Make the Text Bold ?? Pin
phannon8611-Feb-08 4:21
professionalphannon8611-Feb-08 4:21 
GeneralRe: How to Make the Text Bold ?? Pin
Ravenet11-Feb-08 4:24
Ravenet11-Feb-08 4:24 
GeneralRe: How to Make the Text Bold ?? Pin
Pete O'Hanlon11-Feb-08 4:34
mvePete O'Hanlon11-Feb-08 4:34 
GeneralRe: How to Make the Text Bold ?? Pin
Ravenet11-Feb-08 4:37
Ravenet11-Feb-08 4:37 
GeneralRe: How to Make the Text Bold ?? Pin
Guffa11-Feb-08 5:17
Guffa11-Feb-08 5:17 
QuestionWriting text to an open notepad file Pin
Member 51425211-Feb-08 1:25
Member 51425211-Feb-08 1:25 
GeneralRe: Writing text to an open notepad file Pin
Martin#11-Feb-08 2:44
Martin#11-Feb-08 2:44 
Hello,

One solution would be to use the Process class of System.Diagnostic namespace.
There you find a member called MainWindowHandle, which is an IntPtr.

In combination with the "user32.dll" method "SetForegroundWindow", you can activate the open notepad instance.

After that is done you could use "SendKeys.Send" method to send your text.

Here is a little demo:
using System.Runtime.InteropServices;
		
    Process[] procNP = Process.GetProcessesByName("notepad");
    if(procNP.Length>0)
    {
        if(procNP[0].MainWindowHandle!=IntPtr.Zero)
        {
            SetForegroundWindow(procNP[0].MainWindowHandle);
 
            System.Threading.Thread.Sleep(100);
 
            SendKeys.Send("Hello World!");
	}
 
	foreach(Process actP in procNP)
	{
            actP.Dispose();
	}
    }
 
 
[DllImport("user32.dll")]
private static extern int SetForegroundWindow (IntPtr hWnd);


Hope it helps!

All the best,

Martin

GeneralRe: Writing text to an open notepad file Pin
Member 51425211-Feb-08 17:14
Member 51425211-Feb-08 17:14 
GeneralRe: Writing text to an open notepad file Pin
Martin#12-Feb-08 2:14
Martin#12-Feb-08 2:14 
GeneralRe: Writing text to an open notepad file Pin
Member 51425213-Feb-08 18:22
Member 51425213-Feb-08 18:22 
GeneralVisual C# 2008 Express Edition Pin
Ray Hayes11-Feb-08 1:24
Ray Hayes11-Feb-08 1:24 
GeneralRe: Visual C# 2008 Express Edition Pin
Ed.Poore11-Feb-08 3:15
Ed.Poore11-Feb-08 3:15 
GeneralRe: Visual C# 2008 Express Edition Pin
Pete O'Hanlon11-Feb-08 3:52
mvePete O'Hanlon11-Feb-08 3:52 
GeneralRe: Visual C# 2008 Express Edition Pin
Ed.Poore11-Feb-08 5:07
Ed.Poore11-Feb-08 5:07 
GeneralRe: Visual C# 2008 Express Edition Pin
Pete O'Hanlon11-Feb-08 8:30
mvePete O'Hanlon11-Feb-08 8:30 
GeneralRe: Visual C# 2008 Express Edition Pin
Ed.Poore11-Feb-08 8:47
Ed.Poore11-Feb-08 8:47 
GeneralRe: Visual C# 2008 Express Edition Pin
Pete O'Hanlon11-Feb-08 10:28
mvePete O'Hanlon11-Feb-08 10:28 
GeneralRe: Visual C# 2008 Express Edition Pin
Ray Hayes11-Feb-08 4:24
Ray Hayes11-Feb-08 4:24 
GeneralRe: Visual C# 2008 Express Edition Pin
leppie11-Feb-08 8:14
leppie11-Feb-08 8:14 
GeneralRe: Visual C# 2008 Express Edition Pin
Ray Hayes11-Feb-08 9:09
Ray Hayes11-Feb-08 9:09 
GeneralPlugins Pin
pokabot11-Feb-08 1:18
pokabot11-Feb-08 1:18 
GeneralRe: Plugins Pin
Pete O'Hanlon11-Feb-08 2:23
mvePete O'Hanlon11-Feb-08 2:23 
GeneralRe: Plugins Pin
Ed.Poore11-Feb-08 3:17
Ed.Poore11-Feb-08 3:17 
GeneralRe: Plugins Pin
pokabot11-Feb-08 4:26
pokabot11-Feb-08 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.