Bonjour
Le contrôle WebBrowser est en fait un container, dans lequel va s'exécuter IE, et en effet les gars chez Microsoft auraient pu penser à ajouter quelques méthodes permettant de contrôler l'IE
Pour contrôler l'IE encapsulé, l'idée est tout d'abord de trouver son handle, puis de luis balancer des commandes de bas étage, mais il faut revenir sur de la programmation ancestrale et sortir du dotnet
petit exemple:
tout d'abord quelques déclarations pour coller au moteur Windows
Private Const WM_VSCROLL = &H115
Enum ScrollBarCommands
SB_LINEUP = 0
SB_LINELEFT = 0
SB_LINEDOWN = 1
SB_LINERIGHT = 1
SB_PAGEUP = 2
SB_PAGELEFT = 2
SB_PAGEDOWN = 3
SB_PAGERIGHT = 3
SB_THUMBPOSITION = 4
SB_THUMBTRACK = 5
SB_TOP = 6
SB_LEFT = 6
SB_BOTTOM = 7
SB_RIGHT = 7
End Enum
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
ByVal childAfter As IntPtr, _
ByVal lclassName As String, _
ByVal windowTitle As String) As IntPtr
End Function
Puis quelques exemples de pilotage
'recherche du handle du shell encapsulé
Dim ShellEmbeddingHandle As IntPtr = FindWindowEx(WebBrowser1.Handle, IntPtr.Zero, "Shell Embedding", Nothing)
'puis recherche du handle de l'objet
Dim DocObjectViewHandle As IntPtr = FindWindowEx(ShellEmbeddingHandle, IntPtr.Zero, "Shell DocObject View", Nothing)
'enfin le handle de IE
Dim InternetExplorerHandle = FindWindowEx(DocObjectViewHandle, IntPtr.Zero, "Internet Explorer_Server", Nothing)
WebBrowser1.Document.Body.Focus() ' le control doit absolument avoir le focus pour recevoir la commande
'scroll à une position donnée (ici 100 pixels)
'SendMessage(InternetExplorerHandle, WM_VSCROLL, ScrollBarCommands.SB_THUMBPOSITION + &H10000 * 100, Nothing)
'scroll d'une ligne
'SendMessage(InternetExplorerHandle, WM_VSCROLL, ScrollBarCommands.SB_LINEDOWN, Nothing)
'scroll d'une page
SendMessage(InternetExplorerHandle, WM_VSCROLL, ScrollBarCommands.SB_PAGEDOWN, Nothing)
Bon code...