ใครเคยเขียน Web Browser ด้วย C# บ้างครับ คือว่าต้องทำการบ้านอยากให้ เก็บค่า history ต้องทำยังไงครับ หรือใครมีตัวอย่างรบกวนหน่อยนะครับ
Tag : C#
Date :
2010-11-11 12:38:27
By :
benznet
View :
1266
Reply :
1
No. 1
Guest
Code (C#)
private void addNewTab()
{
// create a new TabPage object
TabPage tpage = new TabPage();
tpage.BorderStyle = BorderStyle.Fixed3D;
//add the newly created TabPage
//to the tabcontrol's collection of tab pages
browserTabControl.TabPages.Insert(
browserTabControl.TabCount - 1, tpage);
//create a WebBrowser object
WebBrowser browser = new WebBrowser();
browser.Navigate(homePage);
//add the browser object to the tab page
//you created previously
tpage.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
browserTabControl.SelectTab(tpage);
//add some event handlers to your browser object
browser.ProgressChanged += new
WebBrowserProgressChangedEventHandler(Form1_ProgressChanged);
browser.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(Form1_DocumentCompleted);
browser.Navigating +=
new WebBrowserNavigatingEventHandler(Form1_Navigating);
browser.CanGoBackChanged +=
new EventHandler(browser_CanGoBackChanged);
browser.CanGoForwardChanged +=
new EventHandler(browser_CanGoForwardChanged);
}
Code (C#)
private void addLink(String url, string name)
{
//open the xml file
XmlDocument myXml = new XmlDocument();
//and a new element to the xml file
XmlElement el = myXml.CreateElement("link");
el.SetAttribute("url", url);
el.InnerText = name;
if (!File.Exists(linksXml))
{
XmlElement root = myXml.CreateElement("links");
myXml.AppendChild(root);
root.AppendChild(el);
}
else
{
myXml.Load(linksXml);
myXml.DocumentElement.AppendChild(el);
}
//if the links bar is visible then
//you have to add a ToolStripButton
if (linkBar.Visible == true)
{
//create a new ToolStripButton object with the favicon image,
//website name the click eventhandler to
//navigate to the specific web site
ToolStripButton b =
new ToolStripButton(el.InnerText, getFavicon(url),
items_Click, el.GetAttribute("url"));
b.ToolTipText = el.GetAttribute("url");
//the MouseUp event is used
//for showing the context menu of this button
b.MouseUp += new MouseEventHandler(b_MouseUp);
linkBar.Items.Add(b);
}
myXml.Save(linksXml);
}