نمایش محتویات یک صفحه وب سایت در RichTextBox
کنترل های استفاده شده روی فرم
button،textBox و RichTextBox
کد:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(textBox1.Text);
request.Timeout = 6000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader responseReader = new StreamReader(responseStream);
richTextBox1.Text = responseReader.ReadToEnd();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}