浏览器使用c#在windows窗体应用程序
本文关键字:windows 窗体 应用程序 浏览器 | 更新日期: 2023-09-27 17:50:05
我在Windows窗体应用程序中使用c#开发了一个浏览器,现在我想在文本文档中放置一个按钮来存储HTML代码,我该怎么做呢,谢谢
namespace browser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
browser.Refresh();
}
private void home_Click(object sender, EventArgs e)
{
browser.GoHome();
}
private void back_Click(object sender, EventArgs e)
{
if (browser.CanGoBack)
{
browser.GoBack();
}
}
private void forward_Click(object sender, EventArgs e)
{
if (browser.CanGoForward)
{
browser.GoForward();
}
}
private void stop_Click(object sender, EventArgs e)
{
browser.Stop();
}
private void go_Click(object sender, EventArgs e)
{
string url = textBox.Text.Trim();
browser.Navigate(url);
}
}
}
using System.Net;
using System.Net.Http;
WebRequest req = HttpWebRequest.Create("http://yourwebsite.com");
req.Method = "GET";
string source;
using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream()))
{
source = reader.ReadToEnd();
}
System.IO.StreamWriter file = new System.IO.StreamWriter("c:''test.txt");
file.WriteLine(source);
file.Close();