(我不想简单地拍摄页面并放大,因为我需要使用页面上的链接和按钮)。
如果重要,我使用的是.NET 2.0。
解决方法 似乎在 IE Zoom有一个解决方案涉及覆盖Webbrowser中的AttachInterfaces和DetachInterfaces以获取IWebbrowser2接口,然后使用olECMDID_OPTICAL_ZOOM调用ExecWB。我试过他的sample code,它似乎工作; (简略)相关类看起来像这样:
using System;using System.windows.Forms;using System.Runtime.InteropServices;namespace Zoombrowser{ public partial class Mybrowser : Webbrowser { #region enums public enum olECMDID { // ... olECMDID_OPTICAL_ZOOM = 63,olECMDID_OPTICAL_GETZOomrANGE = 64,// ... } public enum olECMDEXEcopT { // ... olECMDEXEcopT_DONTPROMPTUSER,// ... } public enum olECMDF { // ... olECMDF_SUPPORTED = 1 } #endregion #region IWebbrowser2 [Comimport,/*SuppressUnmanagedCodeSecurity,*/ TypelibType(TypelibTypeFlags.Foleautomation | TypelibTypeFlags.FDual | TypelibTypeFlags.FHIDden),GuID("D30C1661-cdaF-11d0-8A3E-00C04FC9E26E")] public interface IWebbrowser2 { [dispID(100)] voID GoBack(); [dispID(0x65)] voID GoForward(); [dispID(0x66)] voID GoHome(); [dispID(0x67)] voID GoSearch(); [dispID(0x68)] voID Navigate([In] string Url,[In] ref object flags,[In] ref object targetFramename,[In] ref object postData,[In] ref object headers); [dispID(-550)] voID Refresh(); [dispID(0x69)] voID Refresh2([In] ref object level); [dispID(0x6a)] voID Stop(); [dispID(200)] object Application { [return: MarshalAs(UnmanagedType.Idispatch)] get; } [dispID(0xc9)] object Parent { [return: MarshalAs(UnmanagedType.Idispatch)] get; } [dispID(0xca)] object Container { [return: MarshalAs(UnmanagedType.Idispatch)] get; } [dispID(0xcb)] object document { [return: MarshalAs(UnmanagedType.Idispatch)] get; } [dispID(0xcc)] bool topLevelContainer { get; } [dispID(0xcd)] string Type { get; } [dispID(0xce)] int left { get; set; } [dispID(0xcf)] int top { get; set; } [dispID(0xd0)] int WIDth { get; set; } [dispID(0xd1)] int Height { get; set; } [dispID(210)] string Locationname { get; } [dispID(0xd3)] string LocationURL { get; } [dispID(0xd4)] bool Busy { get; } [dispID(300)] voID Quit(); [dispID(0x12d)] voID ClIEntToWindow(out int pcx,out int pcy); [dispID(0x12e)] voID PutProperty([In] string property,[In] object vtValue); [dispID(0x12f)] object GetProperty([In] string property); [dispID(0)] string name { get; } [dispID(-515)] int HWND { get; } [dispID(400)] string Fullname { get; } [dispID(0x191)] string Path { get; } [dispID(0x192)] bool Visible { get; set; } [dispID(0x193)] bool Statusbar { get; set; } [dispID(0x194)] string StatusText { get; set; } [dispID(0x195)] int Toolbar { get; set; } [dispID(0x196)] bool Menubar { get; set; } [dispID(0x197)] bool FullScreen { get; set; } [dispID(500)] voID Navigate2([In] ref object URL,[In] ref object headers); [dispID(0x1f5)] olECMDF queryStatusWB([In] olECMDID cmdID); [dispID(0x1f6)] voID ExecWB([In] olECMDID cmdID,[In] olECMDEXEcopT cmdexecopt,ref object pvaIn,IntPtr pvaOut); [dispID(0x1f7)] voID Showbrowserbar([In] ref object pvaClsID,[In] ref object pvarShow,[In] ref object pvarSize); [dispID(-525)] WebbrowserReadyState ReadyState { get; } [dispID(550)] bool Offline { get; set; } [dispID(0x227)] bool Silent { get; set; } [dispID(0x228)] bool Registerasbrowser { get; set; } [dispID(0x229)] bool RegisterasDropTarget { get; set; } [dispID(0x22a)] bool TheaterMode { get; set; } [dispID(0x22b)] bool Addressbar { get; set; } [dispID(0x22c)] bool Resizable { get; set; } } #endregion private IWebbrowser2 axIWebbrowser2; public Mybrowser() { } protected overrIDe voID AttachInterfaces( object nativeActiveXObject) { base.AttachInterfaces(nativeActiveXObject); this.axIWebbrowser2 = (IWebbrowser2)nativeActiveXObject; } protected overrIDe voID DetachInterfaces() { base.DetachInterfaces(); this.axIWebbrowser2 = null; } public voID Zoom(int factor) { object pvaIn = factor; try { this.axIWebbrowser2.ExecWB(olECMDID.olECMDID_OPTICAL_ZOOM,olECMDEXEcopT.olECMDEXEcopT_DONTPROMPTUSER,ref pvaIn,IntPtr.Zero); } catch (Exception) { throw; } } }}总结
以上是内存溢出为你收集整理的使用WebBrowser .NET控件放大网页全部内容,希望文章能够帮你解决使用WebBrowser .NET控件放大网页所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)