using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Load += new EventHandler(Form1_Load); this.Shown += new EventHandler(Form1_Shown); } HogeClass hogege = new HogeClass(); void Form1_Load(object sender, EventArgs e) { this.hogege.WebBrowser.Dock = DockStyle.Fill; this.Controls.Add(hogege.WebBrowser); hogege.Url.Add("http://t...content-available-to-author-only...h.net/test/read.cgi/tech/1346940693/"); hogege.Url.Add("http://e...content-available-to-author-only...h.net/test/read.cgi/poverty/1347865751/"); } void Form1_Shown(object sender, EventArgs e) { hogege.NavigateStart(); } } class HogeClass { public List Url = new List(); public MyWebBrowser WebBrowser = new MyWebBrowser(); int i_status = 0; int count = 0; public void NavigateStart() { if (this.Url.Count != 0) { this.count = 0; this.WebBrowser.SetStatus = this.SetStatus1; this.WebBrowser.Navigate(this.Url[count]); } } private void SetStatus1(int SetStatus) { switch (i_status) { case 0: //文字入力 this.WebBrowser.InputText("hogehoge"); //ボタン押す処理 //mwebb.ButtonClick(); this.WebBrowser.Refresh(); //ボタン押下処理を書いてないのでダミー i_status++; break; case 1: i_status = 0; count++; if (this.Url.Count > count) this.WebBrowser.Navigate(this.Url[count]); break; } } } delegate void SetStatusCallback(int Status); class MyWebBrowser : WebBrowser { public SetStatusCallback SetStatus; private int _Count = 0; public MyWebBrowser() { this.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(MyWebBrowser_DocumentCompleted); this.Navigating += new WebBrowserNavigatingEventHandler(MyWebBrowser_Navigating); } void MyWebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e) { Interlocked.Increment(ref _Count); } void MyWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { Interlocked.Decrement(ref _Count); if (this._Count == 0) { if (this.SetStatus != null) { this.SetStatus(0); } } } int hogehoge = 0; public void InputText(string s) { hogehoge = 1; //WebBrowserが表示してるwebページのテキストボックスへの文字入力 } public void ButtonClick() { hogehoge = 0; //WebBrowserが表示してるwebページのボタンを押す処理 } } }