我正在动态创建新的 IE 浏览器实例,并从那里打开一个 aspx 页面。一切正常,但浏览器没有在屏幕前面弹出。当我从那里单击它时,能够在任务栏中看到 Aspx 页面,它会出现在前面。如何在 IE 创建后立即将该页面显示在所有屏幕的前面。
我已经粘贴了用于创建新 IE 实例的代码。
public class IEInstance
{
public SHDocVw.InternetExplorer IE1;
public void IEInstanceCls(string check)
{
IE1 = new SHDocVw.InternetExplorer();
object Empty = 0;
string urlpath = " ";
urlpath = "http://localhost/TestPage.aspx?";
object URL = urlpath;
IE1.Top = 260;
IE1.Left = 900;
IE1.Width = 390;
IE1.Height = 460;
IE1.StatusBar = false;
IE1.ToolBar = 0;
IE1.MenuBar = false;
IE1.Visible = true;
IE1.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);
}
}
帮我解决这个问题。
谢谢
最佳答案
Internet Explorer 对象有一个 HWND 属性,它是窗口的句柄。您可以使用它将窗口置于前面,如下所示:
SetForegroundWindow((IntPtr)IE1.HWND);
您需要在文件顶部附近导入 SetForgroundWindow windows API,如下所示。
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
关于asp.net - 将 IE 窗口置于屏幕前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9817989/