本文整理汇总了C#中System.Windows.Forms.WebBrowser.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# WebBrowser.Dispose方法的具体用法?C# WebBrowser.Dispose怎么用?C# WebBrowser.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.WebBrowser
的用法示例。
在下文中一共展示了WebBrowser.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetIeCompatibility
public static void SetIeCompatibility()
{
WebBrowser webBrowserInstance = new WebBrowser();
int iEnumber = webBrowserInstance.Version.Major; //reference: http://support.microsoft.com/kb/969393/en-us
int compatibilityCode = iEnumber * 1000;//Reference:http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation
webBrowserInstance.Dispose();
Trace.TraceInformation("Using Internet Explorer {0}", iEnumber);
var fileName = Path.GetFileName(Application.ExecutablePath);
try
{
//Note: write to HKCU (HKEY_CURRENT_USER) instead of HKLM (HKEY_LOCAL_MACHINE) because HKLM need admin privilege while HKCU do not. Ref:http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control
Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION",
fileName,
compatibilityCode);
}
catch (Exception ex)
{
Trace.TraceError(String.Format("Error setting IE compatibility: {0}", ex));
}
try //for 32 bit IE on 64 bit windows
{
Registry.SetValue(
@"HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION",
fileName,
compatibilityCode);
}
catch (Exception ex)
{
Trace.TraceError(String.Format("Error setting IE compatibility: {0}", ex));
}
}
示例2: BitmapThreadWorker
public void BitmapThreadWorker(object url)
{
try
{
DateTime started = DateTime.Now;
WebBrowser browser = new WebBrowser();
browser.ScrollBarsEnabled = false;
browser.ClientSize = new Size(800, 600);
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
browser.Navigate((string)url);
while (bmp == null)
{
Thread.Sleep(1000);
Application.DoEvents();
TimeSpan elapsed = DateTime.Now.Subtract(started);
if (elapsed.TotalMilliseconds > s_RequestTimeout / 2)
{
browser.Dispose();
mre.Set();
break;
}
}
}
catch
{
mre.Set();
}
}
示例3: DoScreenshot
/// <summary>
/// This method creates a new form with a webbrowser of correct size on it,
/// to make a fullsize website screenhot.
/// </summary>
/// <param name="navigatingArgs">The <see cref="WebBrowserNavigatingEventArgs"/> instance containing the event data,
/// especially the url.</param>
/// <param name="filename">The filename to save the screenshot to.</param>
public static void DoScreenshot(WebBrowserNavigatingEventArgs navigatingArgs, string filename)
{
newTargetUrl = navigatingArgs.Url;
newScreenshotFilename = filename;
var tempBrowser = new WebBrowser();
var dummyForm = new Form { ClientSize = new Size(1, 1), FormBorderStyle = FormBorderStyle.None };
dummyForm.ShowInTaskbar = false;
dummyForm.Controls.Add(tempBrowser);
dummyForm.Show();
tempBrowser.ScrollBarsEnabled = true;
tempBrowser.ScriptErrorsSuppressed = true;
tempBrowser.DocumentCompleted += WebBrowserDocumentCompleted;
if (navigatingArgs.TargetFrameName != string.Empty)
{
tempBrowser.Navigate(navigatingArgs.Url, navigatingArgs.TargetFrameName);
}
else
{
tempBrowser.Navigate(newTargetUrl);
}
while (tempBrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
tempBrowser.Dispose();
}
示例4: GenerateScreenshot
public Bitmap GenerateScreenshot(string url, int width, int height)
{
WebBrowser wb = new WebBrowser();
wb.NewWindow += wb_NewWindow;
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
Thread.Sleep(int.Parse(ConfigurationSettings.AppSettings["WaitForLoadWebSite"].ToString().Trim()));
wb.Width = width;
wb.Height = height;
if (width == -1)
{
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
wb.Height = wb.Document.Body.ScrollRectangle.Height;
}
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
示例5: Main
static void Main(string[] args)
{
System.Console.WriteLine("Create your own web history images.");
System.Console.WriteLine("Type the URL (with http://...");
string url = System.Console.ReadLine();
System.Console.WriteLine(@"Save to location (e.g. C:\Images\)");
string path = System.Console.ReadLine();
IArchiveService service = new WebArchiveService();
Website result = service.Load(url);
System.Console.WriteLine("WebArchive Sites found: " + result.ArchiveWebsites.Count);
WebBrowser wb = new WebBrowser();
int i = 0;
foreach (ArchiveWebsite site in result.ArchiveWebsites)
{
i++;
System.Console.WriteLine("Save image (Date " + site.Date.ToShortDateString() + ") number: " + i.ToString());
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(site.ArchiveUrl);
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
wb.Width = wb.Document.Body.ScrollRectangle.Width;
wb.Height = wb.Document.Body.ScrollRectangle.Height;
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
bitmap.Save(path + site.Date.Year.ToString() + "_" + site.Date.Month.ToString() + "_" + site.Date.Day.ToString() + ".bmp");
}
wb.Dispose();
System.Console.WriteLine(result.Url);
}
示例6: GenerateWebSiteImageInternal
private void GenerateWebSiteImageInternal()
{
WebBrowser WebBrowser = new WebBrowser();
WebBrowser.ScrollBarsEnabled = false;
WebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
WebBrowser.Navigate(Url);
while (WebBrowser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
WebBrowser.Dispose();
}
示例7: _GenerateWebSiteThumbnailImage
private void _GenerateWebSiteThumbnailImage()
{
WebBrowser m_WebBrowser = new WebBrowser();
m_WebBrowser.ScrollBarsEnabled = false;
m_WebBrowser.Navigate(m_Url);
m_WebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
while (m_WebBrowser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
m_WebBrowser.Dispose();
}
示例8: _Generate
private void _Generate()
{
var browser = new WebBrowser { ScrollBarsEnabled = false };
browser.Navigate(m_Url);
browser.DocumentCompleted += WebBrowser_DocumentCompleted;
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
browser.Dispose();
}
示例9: AddForm
public AddForm()
{
InitializeComponent();
button_save.Enabled = false;
if (!string.IsNullOrEmpty(config.TfsDefaultProject))
{
textbox_tfsUrl.Text = config.TfsServerUrl;
textbox_defaultProject.Text = config.TfsDefaultProject;
button_save.Enabled = true;
}
this.BindScreen();
// genereate system info
StringBuilder systemInfo = new StringBuilder();
OperatingSystem os = Environment.OSVersion;
systemInfo.AppendFormat("OS Version : {0}{1}", os.VersionString.ToString(), Environment.NewLine);
systemInfo.AppendFormat("Computer name : {0}{1}", SystemInformation.ComputerName, Environment.NewLine);
systemInfo.AppendFormat("Monitor count : {0}{1}", SystemInformation.MonitorCount, Environment.NewLine);
systemInfo.AppendFormat("Monitors same display format : {0}{1}", SystemInformation.MonitorsSameDisplayFormat, Environment.NewLine);
systemInfo.AppendFormat("Primary monitor size : {0} x {1} {2}", SystemInformation.PrimaryMonitorSize.Height.ToString(), SystemInformation.PrimaryMonitorSize.Width.ToString(), Environment.NewLine);
systemInfo.AppendFormat("Terminal server session : {0}{1}", SystemInformation.TerminalServerSession, Environment.NewLine);
systemInfo.AppendFormat("Working Area : {0} X {1} {2}", SystemInformation.WorkingArea.Height.ToString(), SystemInformation.WorkingArea.Width.ToString(), Environment.NewLine);
WebBrowser browser = new WebBrowser();
systemInfo.AppendFormat("Internet explorer version : {0}{1}", browser.Version, SystemInformation.WorkingArea.Width.ToString(), Environment.NewLine);
browser.Dispose();
//version firefox
var regKeyFirefox = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Mozilla\Mozilla Firefox", false);
if (regKeyFirefox != null)
{
systemInfo.AppendFormat("{0}Firefox version :{1}",Environment.NewLine, regKeyFirefox.GetValue("CurrentVersion"));
}
//version chrome
var regKeyChrome = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome", false);
if (regKeyChrome != null)
{
systemInfo.AppendFormat("{0}Chrome version : {1}",Environment.NewLine, regKeyChrome.GetValue("Version"));
}
textbox_SystemInfo.Text = systemInfo.ToString();
}
示例10: _Generate
private void _Generate()
{
_browser = new WebBrowser
{
ScrollBarsEnabled = false
};
_browser.Navigate(_mUrl);
_browser.DocumentCompleted += WebBrowser_DocumentCompleted;
while (_browser.ReadyState != WebBrowserReadyState.Complete)
{
}
_browser.Dispose();
}
示例11: Main
static void Main(string[] args)
{
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate("http://code-inside.de");
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
wb.Width = wb.Document.Body.ScrollRectangle.Width;
wb.Height = wb.Document.Body.ScrollRectangle.Height;
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
bitmap.Save("C://screenshot.bmp");
}
示例12: GetWebPageWorker
protected void GetWebPageWorker()
{
using (var browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.ScriptErrorsSuppressed = true;
browser.Navigate(_url);
// Wait for control to load page
while (browser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
browser.ClientSize = new Size(1280, 1024);
Thread.Sleep(1000);
bitmap = new Bitmap(1280, 1024);
browser.DrawToBitmap(bitmap, new Rectangle(0, 0, browser.Width, browser.Height));
browser.Dispose();
}
}
示例13: ToImage
/// <summary>
/// Convert url to bitmap byte array
/// </summary>
/// <param name="url">Url to browse</param>
/// <param name="width">width of page (if page contains frame, you need to pass this params)</param>
/// <param name="height">heigth of page (if page contains frame, you need to pass this params)</param>
/// <param name="htmlToManipulate">function to manipulate dom</param>
/// <param name="timeout">in milliseconds, how long can you wait for page response?</param>
/// <returns>bitmap byte[]</returns>
/// <example>
/// byte[] img = new Uri("http://www.uol.com.br").ToImage();
/// </example>
public static byte[] ToImage(this Uri url, int? width = null, int? height = null, Action<HtmlDocument> htmlToManipulate = null, int timeout = -1)
{
byte[] toReturn = null;
Task tsk = Task.Factory.StartNew(() =>
{
WebBrowser browser = new WebBrowser() { ScrollBarsEnabled = false };
browser.Navigate(url);
browser.DocumentCompleted += (s, e) =>
{
var browserSender = (WebBrowser)s;
if (browserSender.ReadyState == WebBrowserReadyState.Complete)
{
if (htmlToManipulate != null) htmlToManipulate(browserSender.Document);
browserSender.ClientSize = new Size(width ?? browser.Document.Body.ScrollRectangle.Width, height ?? browser.Document.Body.ScrollRectangle.Bottom);
browserSender.ScrollBarsEnabled = false;
browserSender.BringToFront();
using (Bitmap bmp = new Bitmap(browserSender.Document.Body.ScrollRectangle.Width, browserSender.Document.Body.ScrollRectangle.Bottom))
{
browserSender.DrawToBitmap(bmp, browserSender.Bounds);
toReturn = (byte[])new ImageConverter().ConvertTo(bmp, typeof(byte[]));
}
}
};
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
browser.Dispose();
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
tsk.Wait(timeout);
return toReturn;
}
示例14: GetHtmlByWebBrowser
public static String GetHtmlByWebBrowser(String url, DependencyObject dispatcher)
{
ManualResetEvent mre = new ManualResetEvent(false);
StreamReader stream = null;
dispatcher.Dispatcher.Invoke(new Action(() =>
{
WebBrowser wb = new WebBrowser();
wb.Navigate(url);
wb.Navigated +=new WebBrowserNavigatedEventHandler((Object sender,WebBrowserNavigatedEventArgs e)=>
{
wb.Stop();
Encoding encoding = Encoding.GetEncoding(wb.Document.Encoding);
stream = new StreamReader(wb.DocumentStream, encoding);
wb.Dispose();
mre.Set();
});
}));
mre.WaitOne();
return stream.ReadToEnd();
}
示例15: Import
public override void Import(PwDatabase pwStorage, Stream sInput,
IStatusLogger slLogger)
{
StreamReader sr = new StreamReader(sInput, Encoding.Unicode, true);
string strData = sr.ReadToEnd();
sr.Close();
strData = strData.Replace(@"<WBR>", string.Empty);
strData = strData.Replace(@"­", string.Empty);
WebBrowser wb = new WebBrowser();
try
{
wb.Visible = false;
wb.ScriptErrorsSuppressed = true;
UIUtil.SetWebBrowserDocument(wb, strData);
ImportPriv(pwStorage, wb.Document.Body);
}
finally { wb.Dispose(); }
}