我成功地使用来自 VB.NET 的 webbrowser 控件来显示和打印文档,但我无法获得我想要应用的缩放功能。
例如,您可以创建一个新项目,添加一个带有“Webbrowser1”控件和两个按钮“btn_Plus”和“btn_Minus”的表单。
不要忘记将 COM 引用添加到“Microsoft Internet Controls”。
Option Strict Off 'because of late binding MyWeb.ExecWB
Imports SHDocVw
Public Class Form1
Dim zoomvalue As Integer = 50
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strHtml As String = "<HTML><h1>Doc...<h1></br><h4>My html here</br>acts like web page.<h4></HTML>"
Me.WebBrowser1.Navigate("about:" + strHtml)
End Sub
Private Sub zoom()
Try
Dim MyWeb As Object = Me.WebBrowser1.ActiveXInstance
MyWeb = Me.WebBrowser1.ActiveXInstance
MyWeb.ExecWB(OLECMDID.OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, zoomvalue, IntPtr.Zero)
MyWeb = Nothing
Catch ex As Exception
'MessageBox.Show("Error:" & ex.Message)
End Try
End Sub
Private Sub btn_Plus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Plus.Click
zoomvalue += 5
zoom()
End Sub
Private Sub btn_Minus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Minus.Click
zoomvalue -= 5
zoom()
End Sub
End Class
1)为什么这不起作用,我认为它应该起作用?
2)如何让它工作?
3) 如何从实际的网络浏览器中获取当前缩放值?