开发者

Activating Console window [duplicate]

This question already has answers here: 开发者_JS百科 bring a console window to front in c# (3 answers) Closed 7 years ago.

I am opening Word from within a Console Application. How can I ensure the Console remains the active window, even after I have shown the Word Application?

using System;
using Microsoft.Office.Interop.Word;

namespace WordDocumentObject {
    class Program {
        static void Main(string[] args) {
            _Application app = new Application();
            app.Visible = true;

            //Activate the console window here

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }
    }
}


you will have to use a call to the SetForegroundWindow API to get what you ask:

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

full example is already in SO:

bring a console window to front in c#

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜