1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| using System;
using System.IO;
using System.Collections;
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.Xml;
namespace System.Xml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WebBrowser wb = GetSelectedWebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
}
//Intilialisation navigateur wb par onglet actif
private WebBrowser GetSelectedWebBrowser()
{
foreach (Control ctl in tabControl1.SelectedTab.Controls)
{
WebBrowser wb = ctl as WebBrowser;
if (wb != null)
return wb;
}
return null;
}
//Evenement lors de la fin du chargement de la page
private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = GetSelectedWebBrowser();
string url = Convert.ToString(wb.Url);
if (url.StartsWith("https://"))
{
textBox2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
}
if (url.StartsWith("ftp://") | ((url.EndsWith(".rar"))) && ((url.EndsWith(".zip"))))
{
textBox2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
}
string title = "Historique";
TabPage myTabPage = new TabPage(title);
try
{
RichTextBox myRT = new RichTextBox();
myTabPage.Controls.Add(myRT);
myRT.Dock = DockStyle.Fill;
myRT.ReadOnly = true;
string dateetheure = Convert.ToString(DateTime.Now);
myRT.LoadFile("Historique.rtf");
string text = myRT.Text;
string urlh = Convert.ToString(wb.Url);
myRT.Text = "\n" + dateetheure + " - " + urlh + " : " + wb.DocumentTitle + text;
myRT.SaveFile("Historique.rtf");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Clipboard.SetData(DataFormats.Text, ex.Message);
}
textBox2.Text = Convert.ToString(wb.Url);
RichTextBox rtf = new RichTextBox();
string rt = Convert.ToString(rtf);
rtf.Text = rt + " \n " + wb.Url;
}
}
} |