在VB里引用一个webBrowser显示网页,比如百度。
运行以后,鼠标光标在百度的输入框中闪烁,这时如果切换到其他程序窗口,然后切换回来,光标就消失了。
好像webBrowser从来没有光标焦点过,需要从新点击输入框。这样很麻烦,比如ctrl+c ctrl+v的时候,都需要从新点击输入框不知道是为什么,在VB程序是否可以控制?请教高手自己搜遍了网络,都没有找到方法有人说 切换时保存光标所在句柄 激活时恢复就OK了  但是我不知道具体如何写代码。麻烦各位给个答案。

解决方案 »

  1.   

     窗口得到焦点的时候让webbrowser得到焦点即可
    Dim tdoc As MSHTML.HTMLDocument        
            Set tdoc = WebBrowser.document            If tdoc.activeElement Is Nothing Then                tdoc.parentWindow.Focus
                    
                Else
                    If Not tdoc.hasFocus Then
                        tdoc.Focus
                    End If
                End If
      

  2.   

    晕了,窗体得到焦点的时候不是有事件的么?Private Sub Form_GotFocus()
    Dim tdoc As MSHTML.HTMLDocument
    Set tdoc = WebBrowser.document
    If tdoc.activeElement Is Nothing Then
        tdoc.parentWindow.Focus
    Else
        If Not tdoc.hasFocus Then
            tdoc.Focus
        End If
    End If
    End Sub
      

  3.   

    请问  MSHTML  这是什么?
      

  4.   

    frm.setFocus  貌似无效。
      

  5.   

    delphi 用楼上的方法可以  VB 不行。结贴了