本文整理汇总了C#中System.Windows.Forms.WebBrowser类的典型用法代码示例。如果您正苦于以下问题:C# WebBrowser类的具体用法?C# WebBrowser怎么用?C# WebBrowser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebBrowser类属于System.Windows.Forms命名空间,在下文中一共展示了WebBrowser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClearCookies
/// <summary>
/// 将浏览器中的Cookie清除
/// </summary>
/// <param name="browser">浏览器</param>
public static void ClearCookies(WebBrowser browser)
{
if (browser != null && browser.Document != null)
{
ClearCookies(browser.Document.Cookie, browser.Url.ToString());
}
}
示例2: InitializeComponent
private void InitializeComponent()
{
ComponentResourceManager resources = new ComponentResourceManager(typeof(HelpForm));
this.docViewer = new WebBrowser();
base.SuspendLayout();
this.docViewer.AllowWebBrowserDrop = false;
this.docViewer.Dock = DockStyle.Fill;
this.docViewer.IsWebBrowserContextMenuEnabled = false;
this.docViewer.Location = new Point(0, 0);
this.docViewer.MinimumSize = new Size(20, 20);
this.docViewer.Name = "docViewer";
this.docViewer.Size = new Size(0x124, 0x252);
this.docViewer.TabIndex = 2;
this.docViewer.TabStop = false;
this.docViewer.Url = new Uri("", UriKind.Relative);
this.docViewer.WebBrowserShortcutsEnabled = false;
base.AutoScaleDimensions = new SizeF(6f, 13f);
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
base.ClientSize = new Size(0x124, 0x252);
base.Controls.Add(this.docViewer);
base.Icon = (Icon) resources.GetObject("$this.Icon");
base.Name = "HelpForm";
base.StartPosition = FormStartPosition.Manual;
this.Text = "HelpForm";
base.ResumeLayout(false);
}
示例3: tabControl_TabItemAdded
void tabControl_TabItemAdded(object sender) //, TabItemEventArgs e)
{
// Add an Icon to the tabItem
BitmapImage image = new BitmapImage(new Uri("pack://application:,,,/Test;component/Images/ie.ico"));
Image img = new Image();
img.Source = image;
img.Width = 16;
img.Height = 16;
img.Margin = new Thickness(2, 0, 2, 0);
//e.TabItem.Icon = img;
// wrap the header in a textblock, this gives us the character ellipsis (...) when trimmed
TextBlock tb = new TextBlock();
tb.Text = "New Tab " + count++;
tb.TextTrimming = TextTrimming.CharacterEllipsis;
tb.TextWrapping = TextWrapping.NoWrap;
//e.TabItem.Header = tb;
// add a WebControl to the TAbItem
WindowsFormsHost host = new WindowsFormsHost();
host.Margin = new Thickness(2);
System.Windows.Forms.WebBrowser browser = new System.Windows.Forms.WebBrowser();
browser.DocumentTitleChanged += Browser_DocumentTitleChanged;
browser.Navigated += Browser_Navigated;
host.Child = browser;
//e.TabItem.Content = host;
}
示例4: Text
/// <summary>
/// Creates a Text display control
/// </summary>
/// <param name="options">Region Options for this control</param>
public Text(RegionOptions options)
: base(options.width, options.height, options.top, options.left)
{
// Collect some options from the Region Options passed in
// and store them in member variables.
_filePath = options.uri;
_direction = options.direction;
_backgroundImage = options.backgroundImage;
_backgroundColor = options.backgroundColor;
_scaleFactor = options.scaleFactor;
_backgroundTop = options.backgroundTop + "px";
_backgroundLeft = options.backgroundLeft + "px";
_documentText = options.text;
_scrollSpeed = options.scrollSpeed;
_headJavaScript = options.javaScript;
// Generate a temporary file to store the rendered object in.
_tempHtml = new TemporaryHtml();
// Generate the Head Html and store to file.
GenerateHeadHtml();
// Generate the Body Html and store to file.
GenerateBodyHtml();
// Fire up a webBrowser control to display the completed file.
_webBrowser = new WebBrowser();
_webBrowser.Size = this.Size;
_webBrowser.ScrollBarsEnabled = false;
_webBrowser.ScriptErrorsSuppressed = true;
_webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
// Navigate to temp file
_webBrowser.Navigate(_tempHtml.Path);
}
示例5: Capture
private static Image Capture(string url, Size size)
{
Image result = new Bitmap(size.Width, size.Height);
var thread = new Thread(() =>
{
using (var browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.AllowNavigation = true;
browser.Navigate(url);
browser.Width = size.Width;
browser.Height = size.Height;
browser.ScriptErrorsSuppressed = true;
browser.DocumentCompleted += (sender,args) => DocumentCompleted(sender, args, ref result);
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
return result;
}
示例6: 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));
}
}
示例7: GetScreenshot
public static Bitmap GetScreenshot(Uri uri, int width, int height)
{
Bitmap bitmap;
using (var webBrowser = new WebBrowser())
{
webBrowser.ScrollBarsEnabled = false;
webBrowser.ScriptErrorsSuppressed = true;
webBrowser.Navigate(uri);
while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
webBrowser.Width = width > 0
? width
: webBrowser.Document.Body.ScrollRectangle.Width;
webBrowser.Height = height > 0
? height
: webBrowser.Document.Body.ScrollRectangle.Height;
if (webBrowser.Height <= 0)
webBrowser.Height = 768;
bitmap = new Bitmap(webBrowser.Width, webBrowser.Height);
webBrowser.DrawToBitmap(bitmap,
new Rectangle(0, 0, webBrowser.Width,
webBrowser.Height));
}
return bitmap;
}
示例8: SetUp
public void SetUp()
{
var settings = new Settings();
if (!CEF.Initialize(settings))
{
Assert.Fail();
}
var thread = new Thread(() =>
{
var form = new Form();
form.Shown += (sender, e) =>
{
Browser = new WebBrowser()
{
Parent = form,
Dock = DockStyle.Fill,
};
createdEvent.Set();
};
Application.Run(form);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
createdEvent.WaitOne();
}
示例9: InitializeComponent
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UpdatesWindow));
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.SuspendLayout();
//
// webBrowser1
//
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.webBrowser1.Location = new System.Drawing.Point(0, 0);
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(794, 572);
this.webBrowser1.TabIndex = 0;
this.webBrowser1.Url = new System.Uri("", System.UriKind.Relative);
//
// UpdatesWindow
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(794, 572);
this.Controls.Add(this.webBrowser1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "UpdatesWindow";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Update Notice";
this.ResumeLayout(false);
}
示例10: Browser
/// <summary>
/// initialise browser
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public Browser(System.Windows.Forms.WebBrowser i)
{
Instance = i;
Instance.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(SetBrowserCompleted);
FullLoaded = true;
UseNewIE();
}
示例11: RequestSnapshot
internal static Image RequestSnapshot(Uri url)
{
Image result = null;
using (var completed = new AutoResetEvent(false))
using (var browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.DocumentCompleted += delegate
{
result = ExtractSnapshot(browser);
completed.Set();
};
browser.Navigate(url);
//completed.WaitOne();
while (result == null)
{
Thread.Sleep(0);
Application.DoEvents();
}
}
return result;
}
示例12: FbNFL
public FbNFL(DateTime today)
: base(ESport.Football_NFL)
{
// 設定
this.AllianceID = 1;
this.GameType = "AFUS";
int diffTime = frmMain.GetGameSourceTime("EasternTime");//取得與當地時間差(包含日光節約時間)
if (diffTime > 0)
this.GameDate = today.AddHours(-diffTime);
else
this.GameDate = GetUtcUsaEt(today);//取得美東時間
if (string.IsNullOrWhiteSpace(this.sWebUrl))
{
this.sWebUrl = @"http://www.cbssports.com/nfl/scoreboard";
}
this.DownWeb = new WebBrowser();
this.DownWeb.AllowNavigation = false;
this.DownWeb.AllowWebBrowserDrop = false;
this.DownWeb.ScriptErrorsSuppressed = true;
this.DownWeb.IsWebBrowserContextMenuEnabled = false;
this.DownWeb.ScrollBarsEnabled = false;
this.DownWeb.WebBrowserShortcutsEnabled = false;
this.DownWeb.TabStop = false;
this.DownWeb.Tag = this.sWebUrl;
}
示例13: BbMLB
public BbMLB(DateTime today)
: base(ESport.Baseball_MLB)
{
// 設定
this.AllianceID = 53;
this.GameType = "BBUS";
//this.GameDate = GetUtcUsaEt(today).Date; // 只取日期
int diffTime = frmMain.GetGameSourceTime("EasternTime");//取得與當地時間差(包含日光節約時間)
if (diffTime > 0)
this.GameDate = today.AddHours(-diffTime);
else
this.GameDate = GetUtcUsaEt(today);//取得美東時間
if (string.IsNullOrWhiteSpace(this.sWebUrl))
{
this.sWebUrl = @"http://www.cbssports.com/mlb/scoreboard";
}
this.DownHome = new BasicDownload(this.Sport, this.sWebUrl);
//this.DownHome = new BasicDownload(this.Sport, string.Format(@"http://mlb.mlb.com/gdcross/components/game/mlb/year_{0}/month_{1}/day_{2}/master_scoreboard.json", this.GameDate.ToString("yyyy"), this.GameDate.ToString("MM"), this.GameDate.ToString("dd")));
this.DownWeb = new WebBrowser();
this.DownWeb.AllowNavigation = false;
this.DownWeb.AllowWebBrowserDrop = false;
this.DownWeb.ScriptErrorsSuppressed = true;
this.DownWeb.IsWebBrowserContextMenuEnabled = false;
this.DownWeb.ScrollBarsEnabled = false;
this.DownWeb.WebBrowserShortcutsEnabled = false;
this.DownWeb.TabStop = false;
this.DownWeb.Tag = this.sWebUrl;
}
示例14: BrowserScriptRework
public BrowserScriptRework(WebbrowserForm.BrowserTab browserTab, Utils.BasePlugin.Plugin ownerPlugin, WebBrowser webBrowser, Framework.Interfaces.ICore core)
: base(browserTab, ownerPlugin, "Rework", webBrowser, core, true)
{
core.LanguageItems.Add(new Framework.Data.LanguageItem(STR_REWORK));
webBrowser.Navigating += new WebBrowserNavigatingEventHandler(webBrowser_Navigating);
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
}
示例15: Frame
public Frame()
{
WindowState = FormWindowState.Maximized;
Text = "Bootpad";
Font = new Font("Anonymous Pro", 10);
Dock = DockStyle.Fill;
he = new HtmlEditor();
wb = new WebBrowser { Dock = DockStyle.Fill, ScriptErrorsSuppressed = false };
ut = new System.Windows.Forms.Timer { Interval = 5000 };
ut.Tick += delegate {
if (changed) {
new Thread(new ThreadStart(delegate {
wb.DocumentText = he.Text;
changed = false;
})).Start();
}
};
he.TextChanged += delegate {
changed = true;
};
var sc0 = new SplitContainer { Parent = this, Dock = DockStyle.Fill, SplitterDistance = 100 };
sc0.Panel1.Controls.Add(he);
sc0.Panel2.Controls.Add(wb);
ut.Start();
}