我成功地使用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)如何从实际的webbrowser获取当前缩放值?
答案 0 :(得分:1)
尝试MyWeb.ExecWB(OLECMDID.OLECMDID_OPTICAL_ZOOM,OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, CObj (zoomvalue), CObj (IntPtr.Zero))