asp.net - 将 IE 窗口置于屏幕前面

标签 asp.net internet-explorer-8

我正在动态创建新的 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/

相关文章:

php - 首次访问页面时,Drupal 生成的 HTML 上方出现神秘数字

jquery - 点击 "enter"按钮不会在 IE8 中提交表单

c# - Facebook 分享按钮的不同 URL

c# - CTE 查询在 asp.net 中使用 c# for webform 在数据集中生成错误

c# - 从成功的 strip 结帐重定向

c# - 无法加载文件或程序集,因为 'Access is denied'(标识 : NETWORK SERVICE)

jQuery 无法在 F12 开发工具的 Internet Explorer 8 模式下工作

jquery - IE8 的 CSS 动画问题,在所有其他浏览器中工作正常

javascript - IE8 破坏了脚本 src?

c# - 带有 Entity Framework 的 ASP.NET : EF does not generate identity automatically