本文整理汇总了C#中System.Windows.Forms.WebBrowser.Navigate方法的典型用法代码示例。如果您正苦于以下问题:C# WebBrowser.Navigate方法的具体用法?C# WebBrowser.Navigate怎么用?C# WebBrowser.Navigate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.WebBrowser
的用法示例。
在下文中一共展示了WebBrowser.Navigate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: Main
static void Main()
{
for (int i = 0; i != Screen.AllScreens.Length; i++)
{
Form frm = new Form();
WebBrowser brs = new WebBrowser();
brs.Dock = DockStyle.Fill;
brs.ScrollBarsEnabled = false;
if (Screen.AllScreens[i].Primary)
brs.Navigate(new Uri("http://www.cyberspace.org/~jhl"));
else
brs.Navigate(new Uri("http://www.c-faq.com"));
frm.Controls.Add(brs);
frm.FormBorderStyle = FormBorderStyle.None;
frm.Show();
frm.DesktopBounds = Screen.AllScreens[i].Bounds;
/*Compile this console project as Windows Application at: Project/...
Properties/Application/Output type: Windows Application, this hides
the console window. Override FormClosed event triggered by keystroke
ALT+F4 and exit the application at the close of the last form.*/
frm.FormClosed += delegate(object obj, FormClosedEventArgs args)
{
if (Application.OpenForms.Count == 0)
Application.Exit();
};
}
Application.Run();
}
示例3: AutoSubmission
/// <summary>
/// This is the crucial auto submission method used to primarily handle the bot's auto submission work
/// </summary>
/// <param name="browser">WebBrowser to operate on</param>
/// <param name="currentlySolving">Label to show the currently solving problem's name</param>
/// <param name="linkList">List of problem links to solve</param>
/// <param name="awaitTime">Awaiting time after each successful submission</param>
/// <returns>Bool value addressing the success of the method</returns>
public async static Task<bool> AutoSubmission(WebBrowser browser, Label currentlySolving, List<string> linkList, int awaitTime)
{
while(linkList.Any())
{
try
{
Random rng = new Random();
var falseSubmission = rng.Next(3); // Total false submissions for each problem
// Take out a link and remove it from the list afterwards
var indexToRemove = rng.Next(linkList.Count);
var link = linkList[indexToRemove];
linkList.RemoveAt(indexToRemove);
string solutionListPageHtml;
using (var client = new WebClient())
{
// Extract solution list page's html and update currently solving label's text
solutionListPageHtml =
await
client.DownloadStringTaskAsync(
StringManupulation.LinkToSolutions(link.Replace("\r", string.Empty)));
currentlySolving.Text =
Regex.Match(client.DownloadString(link), @"(?<=<title>)(.*)(?= \| CodeChef</title>)")
.ToString();
}
for (int count = 1; count <= falseSubmission; count++)
{
// False submissions
browser.Navigate(StringManupulation.LinkToSubmission(link));
await Submit(browser, StringManupulation.FakeSourceCodeGenerator());
}
// Navigate to submission page and finally submit the correct solution
browser.Navigate(StringManupulation.LinkToSubmission(link));
await Submit(browser, StringManupulation.ExtractedSolution(solutionListPageHtml));
}
catch (Exception)
{
// ignored
}
finally
{
// Wait for awaitTime before jumping for the next submission
await Task.Delay(awaitTime);
}
}
return true;
}
示例4: IeWebMedia
public IeWebMedia(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.
_options = options;
// Check to see if the mode option is present.
string modeId = options.Dictionary.Get("modeid");
bool nativeOpen = modeId != string.Empty && modeId == "1";
if (nativeOpen)
{
// If we are modeid == 1, then just open the webpage without adjusting the file path
_filePath = Uri.UnescapeDataString(options.uri).Replace('+', ' ');
}
else
{
// Set the file path
_filePath = ApplicationSettings.Default.LibraryPath + @"\" + _options.mediaid + ".htm";
}
// Create the web view we will use
_webBrowser = new WebBrowser();
_webBrowser.DocumentCompleted += _webBrowser_DocumentCompleted;
_webBrowser.Size = Size;
_webBrowser.ScrollBarsEnabled = false;
_webBrowser.ScriptErrorsSuppressed = true;
_webBrowser.Visible = false;
if (nativeOpen)
{
// Nativate directly
_webBrowser.Navigate(_filePath);
}
else
{
// Check to see if the HTML is ready for us.
if (HtmlReady())
{
// Write to temporary file
ReadControlMeta();
// Navigate to temp file
_webBrowser.Navigate(_filePath);
}
else
{
RefreshFromXmds();
}
}
Controls.Add(_webBrowser);
// Show the control
Show();
}
示例5: if
void IAutoWeb.Next(WebBrowser webBrowser1)
{
Uri url = webBrowser1.Url;
// Fix bug: Why sometimes it's null?
if(url == null)
{
return;
}
Console.Out.WriteLine("Next>>");
Console.Out.WriteLine(url);
if (url.ToString().StartsWith(URL_LOGIN))
{
this.LoginSupportedByWangWang(webBrowser1.Document);
}
else if (url.ToString().StartsWith(URL_ASSET))
{
MoneyDatabaseUpdater dbUpdater = new MoneyDatabaseUpdater();
if (this._isTotalUpdated == false)
{
this._isTotalUpdated = this.RetrieveTotal(webBrowser1.Document, dbUpdater);
}
if (this.RetrieveDaily(webBrowser1.Document, dbUpdater))
{
if (!this.ClickNextTab(webBrowser1.Document))
{
webBrowser1.Navigate(URL_MIAO);
}
}
}
else if (url.ToString().StartsWith(URL_MIAO))
{
if (this.GetMaoquan(webBrowser1.Document))
{
webBrowser1.Navigate(URL_ETAO);
}
}
else if (url.ToString().StartsWith(URL_ETAO))
{
if (this.SignETao(webBrowser1.Document))
{
this._completed = true;
}
}
else
{
}
}
示例6: loginNico
private void loginNico()
{
try
{
toolStripStatusLabel2.Text = "Giriş Yapılıyor..";
wb = new WebBrowser();
wb.ScriptErrorsSuppressed = true;
wb.Navigate("http://www.nicovideo.jp/login");
while (wb.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
wb.Document.GetElementById("mail").InnerText = "[email protected]";
wb.Document.GetElementById("password").InnerText = "1725839";
foreach (HtmlElement el in wb.Document.GetElementsByTagName("input"))
{
if (el.GetAttribute("type").Equals("submit"))
{
el.InvokeMember("click");
break;
}
}
}
catch{
toolStripStatusLabel2.Text = "Giriş Başarısız..";
}
toolStripStatusLabel2.Text = "Giriş Başarılı..";
button2.Enabled = true;
}
示例7: preview
public void preview(WebBrowser webBrowser, List<Step> tuts)
{
webBrowser.Navigate("about:blank");
HtmlDocument doc = webBrowser.Document;
doc.OpenNew(true);
doc.Write(render(tuts));
}
示例8: 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;
}
示例9: DoOAuth
public static DialogResult DoOAuth()
{
Size size = _dropboxAuthFormSize;
using (var dialog = new Form())
{
WebBrowser browesr = new WebBrowser()
{
Dock = DockStyle.Fill
};
string authUrl = Client.BuildAuthorizeUrl();
// Event handler
browesr.Navigated += (s, ex) =>
{
var url = ex.Url.ToString();
if (url.Equals(_callbackURL))
{
dialog.DialogResult = DialogResult.OK;
}
else if (url.Equals(_cancelCallbackURL))
{
dialog.DialogResult = DialogResult.Cancel;
}
};
browesr.Navigate(authUrl);
dialog.Size = size;
dialog.Controls.Add(browesr);
dialog.StartPosition = FormStartPosition.CenterParent;
return dialog.ShowDialog();
}
}
示例10: 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);
}
示例11: Nailer
//TODO enable
private static void Nailer(string screenNailerId, string RefId, string url)
{
ReferenceId = RefId;
ScreenNailerId = screenNailerId;
WriteLog("In Nailer screenNailerId " + screenNailerId + " RefId " + RefId + " url" + url);
int width = 1280;
int height = 768;
using (WebBrowser browser = new WebBrowser())
{
browser.Width = width;
browser.Height = height;
browser.ScrollBarsEnabled = false;
// This will be called when the page finishes loading
browser.DocumentCompleted += Program.OnDocumentCompleted;
browser.Navigate(url);
// This prevents the application from exiting until
// Application.Exit is called
Application.Run();
}
}
示例12: Post
public HttpResponseMessage Post(EmailModel value)
{
var waiter = new ManualResetEvent(true);
var staThread = new Thread(() =>
{
var browser = new WebBrowser();
browser.DocumentCompleted += (sender, e) =>
{
waiter.Set(); // Signal the web service thread we're done.
Wtf = "fuckkkkkkkkkk";
};
browser.Navigate("http://www.google.com");
});
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
var timeout = TimeSpan.FromSeconds(30);
waiter.WaitOne(timeout); // Wait for the STA thread to finish.
var client = new MailgunClient("app15162.mailgun.org", "key-8-br6rzagyq2r4593n-iqmx-lrlkf902");
var message = new MailMessage(value.From, value.To, value.Title, value.Content);
client.SendMail(message);
return Request.CreateResponse(HttpStatusCode.OK, value);
}
示例13: AuthorizeClient
private static void AuthorizeClient(AppServiceClient appServiceClient)
{
Form frm = new Form();
frm.Width = 640;
frm.Height = 480;
WebBrowser browser = new WebBrowser();
browser.Dock = DockStyle.Fill;
browser.DocumentCompleted += (sender, e) =>
{
if (e.Url.AbsoluteUri.IndexOf(URL_TOKEN) > -1)
{
var encodedJson = e.Url.AbsoluteUri.Substring(e.Url.AbsoluteUri.IndexOf(URL_TOKEN) + URL_TOKEN.Length);
var decodedJson = Uri.UnescapeDataString(encodedJson);
var result = JsonConvert.DeserializeObject<dynamic>(decodedJson);
string userId = result.user.userId;
string userToken = result.authenticationToken;
appServiceClient.SetCurrentUser(userId, userToken);
frm.Close();
}
};
browser.Navigate(string.Format(@"{0}login/twitter", GW_URL));
frm.Controls.Add(browser);
frm.ShowDialog();
}
示例14: GetFeedAsync
public Task<SurveyNewsFeed> GetFeedAsync(string feedUrl) {
// We can't use a simple WebRequest, because that doesn't have access
// to the browser's session cookies. Cookies are used to remember
// which survey/news item the user has submitted/accepted. The server
// checks the cookies and returns the survey/news urls that are
// currently available (availability is determined via the survey/news
// item start and end date).
var tcs = new TaskCompletionSource<SurveyNewsFeed>();
try {
var thread = new Thread(() => {
var browser = new WebBrowser();
browser.DocumentCompleted += (sender, e) => {
try {
if (browser.Url == e.Url) {
SurveyNewsFeed feed = ParseFeed(browser);
tcs.SetResult(feed);
Application.ExitThread();
}
} catch (Exception ex2) {
tcs.SetException(ex2);
}
};
browser.Navigate(new Uri(feedUrl));
Application.Run();
});
thread.Name = "SurveyNewsFeedClient";
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
} catch (Exception ex1) {
tcs.SetException(ex1);
}
return tcs.Task;
}
示例15: CreateImage
internal override void CreateImage(string imagePath)
{
Thread thread = new Thread(delegate()
{
using (WebBrowser browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.AllowNavigation = true;
string tempPath = imagePath + ".html";
File.WriteAllText(tempPath, this.Html);
browser.Navigate(tempPath);
browser.ScriptErrorsSuppressed = true;
//browser.Width = 1024;
//browser.Height = 19999;
browser.Tag = imagePath;
browser.DocumentCompleted += DocumentCompleted;
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
base.CreateImage(imagePath);
}