【问题标题】:Open Internet Explorer using Visual Basic and re size the ie window使用 Visual Basic 打开 Internet Explorer 并调整 ie 窗口的大小
【发布时间】:2014-08-24 05:14:15
【问题描述】:

嘿,我被这个错误困扰了很长时间,希望有人能提供帮助, 因此,在我的 .NET 程序中,当您按下按钮时,会启动一个计时器,该计时器会打开多个 Internet Explorer 窗口,但问题是我希望每个打开的窗口都具有不同的大小,这可以通过向大小添加随机性来完成。但我不知道该怎么做。 请帮忙!!!

这是我目前所拥有的

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Process.Start("C:\Program Files (x86)\Internet Explorer\iexplore.exe", "www.google.com")
    End Sub 

【问题讨论】:

    标签: visual-studio-2010 vba internet-explorer visual-studio-2012 button


    【解决方案1】:

    您的示例代码 Timer1_Tick 在 .Net 中

    但是,如果您正在寻找 VBA 解决方案,请尝试类似的方法

      Sub IE()
    
            Dim oIE As Object
    
            Set oIE = CreateObject("InternetExplorer.Application")
    
            oIE.navigate2 "www.google.com"
            oIE.Height = CInt(Int((1000 * Rnd()) + 1))
            oIE.Width = CInt(Int((1000 * Rnd()) + 1))
            oIE.Visible = True
    
        End Sub
    

    此链接可能会有所帮助:http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx

    【讨论】:

    • 嘿,我也想知道你是否可以从 google、yahoo、facebook、twitter 中选择打开哪个网站的随机性?
    【解决方案2】:

    这可以通过使用 interop 和 USER32.dll 来实现

    让我给你一个c#的例子。

        [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
        [DllImport("user32.dll", SetLastError = true)]
        internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
    
        public IntPtr win_handle;
    
        void somefunction(){
                string ie_win_class = "IEFrame";
                string ie_win_nm = "New Tab - Windows Internet Explorer";
                win_handle = FindWindow(win_class, win_name);
                MoveWindow(win_handle, 600, 600, 600, 600, True);
         }
    

    抱歉,我没有使用 VB 的经验。我希望这对你有所帮助。

    链接-

    MoveWindow function

    COM Interop (Visual Basic)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多