Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.Threading;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Net;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Drawing.Drawing2D;
- using System.Web;
- namespace Youtube_Downloader
- {
- public partial class Form1 : Form
- {
- public const int WM_NCLBUTTONDOWN = 0xA1;
- public const int HT_CAPTION = 0x2;
- [DllImportAttribute("user32.dll")]
- public static extern int SendMessage(IntPtr hWnd,
- int Msg, int wParam, int lParam);
- [DllImportAttribute("user32.dll")]
- public static extern bool ReleaseCapture();
- public Form1()
- {
- InitializeComponent();
- }
- private void addText(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(bunifuMetroTextbox1.Text))
- {
- bunifuMetroTextbox1.ForeColor = Color.FromArgb(150, 150, 150);
- bunifuMetroTextbox1.Text = "Ex: https://www.youtube.com/watch?v=5aopMm7UGYA";
- }
- bunifuMetroTextbox1.Parent.Parent.BackColor = Color.FromArgb(255, 255, 255);
- }
- private void removeText(object sender, EventArgs e)
- {
- if (bunifuMetroTextbox1.ForeColor == Color.FromArgb(150, 150, 150))
- {
- bunifuMetroTextbox1.ForeColor = Color.FromArgb(255, 255, 255);
- bunifuMetroTextbox1.Text = "";
- }
- bunifuMetroTextbox1.Parent.Parent.BackColor = Color.FromArgb(46, 139, 87);
- }
- private void HoverEnterInput(object sender, EventArgs e)
- {
- if (!bunifuMetroTextbox1.Focused)
- {
- panel8.BackColor = Color.FromArgb(60, 196, 120);
- }
- }
- private void HoverLeaveInput(object sender, EventArgs e)
- {
- if (!bunifuMetroTextbox1.Focused)
- {
- panel8.BackColor = Color.FromArgb(255, 255, 255);
- }
- }
- private void ClickInput(object sender, EventArgs e)
- {
- bunifuMetroTextbox1.Focus();
- }
- private void HoverEnterButton(object sender, EventArgs e)
- {
- label5.BackColor = Color.FromArgb(60, 196, 120);
- label5.Cursor = Cursors.Hand;
- }
- private void HoverLeaveButton(object sender, EventArgs e)
- {
- label5.BackColor = Color.FromArgb(46, 139, 87);
- label5.Cursor = Cursors.Default;
- }
- private void closeEnter(object sender, EventArgs e)
- {
- Panel p = (Panel)sender;
- p.Top -= 5;
- p.Left -= 5;
- p.Width += 10;
- p.Height += 10;
- }
- private void closeLeave(object sender, EventArgs e)
- {
- Panel p = (Panel)sender;
- p.Top += 5;
- p.Left += 5;
- p.Width -= 10;
- p.Height -= 10;
- }
- private void Form1_Click(object sender, EventArgs e)
- {
- label2.Focus();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- this.ActiveControl = label2;
- bunifuMetroTextbox1.ForeColor = Color.FromArgb(150, 150, 150);
- bunifuMetroTextbox1.Text = "Ex: https://www.youtube.com/watch?v=5aopMm7UGYA";
- panel5.AutoScroll = false;
- panel5.HorizontalScroll.Enabled = false;
- panel5.HorizontalScroll.Visible = false;
- panel5.HorizontalScroll.Maximum = 0;
- panel5.AutoScroll = true;
- }
- private void Form1_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- label2.Focus();
- ReleaseCapture();
- SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
- }
- }
- private void Close(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void Download_Button(object sender, EventArgs e)
- {
- if (bunifuMetroTextbox1.ForeColor == Color.FromArgb(150, 150, 150))
- {
- DialogResult dialogResult = MessageBox.Show("Je vois que vous n'avez pas encore rempli la zone de texte,\nsouhaitez-vous malgré tout télécharger la vidéo d'exemple ?","Est-ce une erreur de votre part ?",MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes)
- {
- bunifuMetroTextbox1.ForeColor = Color.FromArgb(255, 255, 255);
- bunifuMetroTextbox1.Text = "https://www.youtube.com/watch?v=5aopMm7UGYA";
- Download(bunifuMetroTextbox1.Text);
- }
- } else
- {
- Download(bunifuMetroTextbox1.Text);
- }
- }
- private void Download(string url)
- {
- string[] parameters = extractParameters(url);
- string ID = getParameter("v", parameters);
- if (!String.IsNullOrWhiteSpace(ID))
- {
- panel3.Visible = true;
- Thread newThread = new Thread(getLinks);
- newThread.Start(ID);
- } else
- {
- MessageBox.Show("Désolé, nos détecteurs intergalatiques ne sont pas en mesure de détecter la moindre vidéo YouTube sur ce lien.\nMerci de nous confier une url YouTube propre ;)");
- }
- }
- public static string[] extractParameters(string url)
- {
- string pat = @"[?&][^?&]+=[^?&]*";
- Regex r = new Regex(pat, RegexOptions.IgnoreCase);
- Match m = r.Match(url);
- string[] result = new string[m.Length];
- int i = 0;
- while (m.Success)
- {
- result[i++] = m.Value;
- m = m.NextMatch();
- }
- return result;
- }
- public static string getParameter(string name, string[] parameters)
- {
- string result = "";
- string[] na;
- string n;
- for (int i = 0; i < parameters.Length; i++)
- {
- n = parameters[i].Substring(1);
- if (!String.IsNullOrWhiteSpace(n))
- {
- na = n.Split('=');
- if (na[0] == name)
- {
- return na[1];
- }
- }
- }
- return result;
- }
- public static string getInfoFromItag(string itag)
- {
- string info = "";
- if (itag == "5")
- {
- info = "FLV;FLV, FLV1 H.263;240p;MP3 Stereo, 22.05 KHz 64.0 Kbps";
- }
- else if (itag == "6")
- {
- info = "FLV;FLV;270p;No Audio";
- }
- else if (itag == "13")
- {
- info = "3GP;3GP;Mobile;No Audio";
- }
- else if (itag == "17")
- {
- info = "3GP;3GP, MPEG-4;144p;AAC, Mono 22.05 KHz 24.0 - 25.6 Kbps";
- }
- else if (itag == "18")
- {
- info = "MP4;MP4, AVC (MPEG4 H.264);360p;AAC, Stereo, 44.1 KHz 96.0 - 100 Kbps";
- }
- else if (itag == "22")
- {
- info = "MP4;MP4, AVC (MPEG4 H.264);720p;AAC, 44.1 KHz 192.0 - 201 Kbps";
- }
- else if (itag == "34")
- {
- info = "FLV;FLV;360p;No Audio";
- }
- else if (itag == "35")
- {
- info = "FLV;FLV;480p;No Audio";
- }
- else if (itag == "36")
- {
- info = "3GP;3GP, MPEG4 H.263;240p;AAC, Mono, 22.05 KHz 32.0 - 34.2 Kbps";
- }
- else if (itag == "37")
- {
- info = "MP4;MP4;1080p;No Audio";
- }
- else if (itag == "38")
- {
- info = "MP4;MP4;3072p;No Audio";
- }
- else if (itag == "43")
- {
- info = "WEBM;WEBM, VP8;360p;Vorbis, Stereo, 44.1 KHz 128 Kbps";
- }
- else if (itag == "44")
- {
- info = "WEBM;WEBM;480p;No Audio";
- }
- else if (itag == "45")
- {
- info = "WEBM;WEBM;720p;No Audio";
- }
- else if (itag == "46")
- {
- info = "WEBM;WEBM;1080p;No Audio";
- }
- else if (itag == "82")
- {
- info = "MP4;MP4, AVC (MPEG4 H.264);360p (3D);AAC, Stereo, 44.1 KHz 128 - 134 Kbps";
- }
- else if (itag == "83")
- {
- info = "MP4;MP4;480p (3D);No Audio";
- }
- else if (itag == "84")
- {
- info = "MP4;MP4, AVC (MPEG4 H.264);720p (3D);AAC, Stereo, 44.1 KHz 192 - 201 Kbps";
- }
- else if (itag == "85")
- {
- info = "MP4;MP4;1080p (3D);No Audio";
- }
- else if (itag == "100")
- {
- info = "WEBM;WEBM;360p (3D);No Audio";
- }
- else if (itag == "101")
- {
- info = "WEBM;WEBM;480p (3D);No Audio";
- }
- else if (itag == "102")
- {
- info = "WEBM;WEBM;720p (3D);No Audio";
- }
- else if (itag == "133")
- {
- info = "MP4;MP4, DASH video;240p;No Audio";
- }
- else if (itag == "134")
- {
- info = "MP4;MP4, DASH video;360p;No Audio";
- }
- else if (itag == "135")
- {
- info = "MP4;MP4, DASH video;480p;No Audio";
- }
- else if (itag == "136")
- {
- info = "MP4;MP4, DASH video;720p;No Audio";
- }
- else if (itag == "137")
- {
- info = "MP4;MP4, DASH video;1080p;No Audio";
- }
- else if (itag == "138")
- {
- info = "MP4;MP4, DASH video;2160p;No Audio";
- }
- else if (itag == "160")
- {
- info = "MP4;MP4, DASH video;144p;No Audio";
- }
- else if (itag == "264")
- {
- info = "MP4;MP4, DASH video;1440p;No Audio";
- }
- else if (itag == "298")
- {
- info = "MP4;MP4, DASH video H.264;720p;No Audio";
- }
- else if (itag == "299")
- {
- info = "MP4;MP4, DASH video H.264;1080p;No Audio";
- }
- else if (itag == "266")
- {
- info = "MP4;MP4, DASH video H.264;2160p;No Audio";
- }
- else if (itag == "139")
- {
- info = "M4A;M4A;No Video;AAC [DASH audio], Stereo, 44.1 KHz 48 Kbps";
- }
- else if (itag == "140")
- {
- info = "M4A;M4A;No Video;AAC [DASH audio], Stereo, 44.1 KHz 128 Kbps";
- }
- else if (itag == "141")
- {
- info = "M4A;M4A;No Video;AAC [DASH audio], Stereo, 44.1 KHz 256 Kbps";
- }
- else if (itag == "167")
- {
- info = "WEBM;WEBM, VP8 DASH video;360p;No Audio";
- }
- else if (itag == "168")
- {
- info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
- }
- else if (itag == "169")
- {
- info = "WEBM;WEBM, VP8 DASH video;720p;No Audio";
- }
- else if (itag == "170")
- {
- info = "WEBM;WEBM, VP8 DASH video;1080p;No Audio";
- }
- else if (itag == "218")
- {
- info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
- }
- else if (itag == "219")
- {
- info = "WEBM;WEBM, VP9 DASH video;144p;No Audio";
- }
- else if (itag == "220")
- {
- info = "WEBM;WEBM, VP9 DASH video;144p;No Audio";
- }
- else if (itag == "242")
- {
- info = "WEBM;WEBM, VP8 DASH video;240p;No Audio";
- }
- else if (itag == "243")
- {
- info = "WEBM;WEBM, VP8 DASH video;360p;No Audio";
- }
- else if (itag == "244")
- {
- info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
- }
- else if (itag == "245")
- {
- info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
- }
- else if (itag == "246")
- {
- info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
- }
- else if (itag == "247")
- {
- info = "WEBM;WEBM, VP8 DASH video;720p;No Audio";
- }
- else if (itag == "248")
- {
- info = "WEBM;WEBM, VP8 DASH video;1080p;No Audio";
- }
- else if (itag == "249")
- {
- info = "WEBM;WEBM;No Video;OPUS [DASH audio], Stereo, 50 KHz";
- }
- else if (itag == "250")
- {
- info = "WEBM;WEBM;No Video;OPUS [DASH audio], Stereo, 70 KHz";
- }
- else if (itag == "251")
- {
- info = "WEBM;WEBM;No Video;OPUS [DASH audio], Stereo, 160 KHz";
- }
- else if (itag == "271")
- {
- info = "WEBM;WEBM, VP8 DASH video;1440p;No Audio";
- }
- else if (itag == "272")
- {
- info = "WEBM;WEBM, VP8 DASH video;2160p;No Audio";
- }
- else if (itag == "302")
- {
- info = "WEBM;WEBM, VP9 DASH video;2160p;No Audio";
- }
- else if (itag == "303")
- {
- info = "WEBM;WEBM, VP9 DASH video;1080p;No Audio";
- }
- else if (itag == "308")
- {
- info = "WEBM;WEBM, VP9 DASH video;1440p;No Audio";
- }
- else if (itag == "313")
- {
- info = "WEBM;WEBM, VP9 DASH video;2160p;No Audio";
- }
- else if (itag == "315")
- {
- info = "WEBM;WEBM, VP9 DASH video;2160p;No Audio";
- }
- else if (itag == "171")
- {
- info = "WEBM;WEBM;No Video;AAC [DASH audio], Stereo, 44.1 KHz 128 Kbps";
- }
- else if (itag == "172")
- {
- info = "WEBM;WEBM;No Video;AAC [DASH audio], Stereo, 44.1 KHz 256 Kbps";
- }
- return info;
- }
- private void getLinks(object ID)
- {
- string data = XmlHttpRequest("https://api.youtubemultidownloader.com/video?id=" + ID.ToString());
- string pat = @"(https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])";
- Regex r = new Regex(pat, RegexOptions.IgnoreCase);
- Match m = r.Match(data);
- List<string> resultt = new string[] { }.ToList();
- //string[] result = new string[m.Length];
- int i = 0;
- while (m.Success)
- {
- if (!String.IsNullOrWhiteSpace(m.Value))
- {
- resultt.Insert(i, m.Value);
- //result[i++] = m.Value;
- }
- m = m.NextMatch();
- }
- string[] result = resultt.ToArray<string>();
- string pat2 = @"^[^,]+,";
- Regex r2 = new Regex(pat2, RegexOptions.IgnoreCase);
- Match m2 = r2.Match(data);
- string[] titleArr = new string[m2.Length];
- int i2 = 0;
- while (m2.Success)
- {
- titleArr[i2++] = m2.Value;
- m2 = m.NextMatch();
- }
- string title = titleArr[0].Substring(10, titleArr[0].Length-12);
- Next(true,title,result,ID.ToString());
- }
- delegate void StringArgReturningVoidDelegate(bool b, string text, string[] urls, string ID);
- private void Next(bool b, string text, string[] urls, string ID)
- {
- if (this.panel3.InvokeRequired)
- {
- StringArgReturningVoidDelegate d = new StringArgReturningVoidDelegate(Next);
- this.Invoke(d, new object[] { b, text, urls, ID });
- }
- else
- {
- this.panel5.Visible = b;
- this.label1.Text = text;
- this.pictureBox1.ImageLocation = "http://img.youtube.com/vi/" + ID + "/0.jpg";
- Panel Container = new Panel();
- Container.BackColor = Color.FromArgb(33, 33, 33);
- Container.Location = bunifuSeparator1.Location;
- Container.Width = bunifuSeparator1.Width;
- Container.Height = urls.Length * 90 + 100;
- panel5.Controls.Add(Container);
- Array.Sort(urls, delegate (string a1, string a2) {
- string[] a1parameters = extractParameters(a1);
- string[] a1info = getInfoFromItag(getParameter("itag", a1parameters)).Split(';');
- string a1Extension = "Unknown";
- string a1Video = "Unknown";
- string a1Quality = "Unknown";
- string a1Audio = "Unknown";
- if (a1info.Length > 2)
- {
- a1Extension = a1info[0];
- a1Video = a1info[1];
- a1Quality = a1info[2];
- a1Audio = a1info[3];
- }
- string[] a2parameters = extractParameters(a2);
- string[] a2info = getInfoFromItag(getParameter("itag", a2parameters)).Split(';');
- string a2Extension = "Unknown";
- string a2Video = "Unknown";
- string a2Quality = "Unknown";
- string a2Audio = "Unknown";
- if (a2info.Length > 2)
- {
- a2Extension = a2info[0];
- a2Video = a2info[1];
- a2Quality = a2info[2];
- a2Audio = a2info[3];
- }
- if (a1Audio == "No Audio")
- {
- return 1;
- }
- if (a2Audio == "No Audio")
- {
- return -1;
- }
- if (a1Quality == "No Video")
- {
- return 1;
- }
- if (a2Quality == "No Video")
- {
- return -1;
- }
- return a2Quality.CompareTo(a1Quality);
- });
- int i;
- int j = 0;
- for (i = 0; i < urls.Length; i++)
- {
- string[] parameters = extractParameters(urls[i]);
- //string mime = HttpUtility.UrlDecode(getParameter("mime", parameters));
- string[] info = getInfoFromItag(getParameter("itag", parameters)).Split(';');
- string Extension = "Unknown";
- string Video = "Unknown";
- string Quality = "Unknown";
- string Audio = "Unknown";
- if (info.Length > 2)
- {
- Extension = info[0];
- Video = info[1];
- Quality = info[2];
- Audio = info[3];
- }
- if (Video != "Unknown")
- {
- Panel tmp = new Panel();
- tmp.BackColor = Color.FromArgb(46, 139, 87);
- tmp.Top = 90 * j + 20;
- tmp.Left = 0;
- tmp.Width = bunifuSeparator1.Width;
- tmp.Height = 80;
- Panel Panel_Quality = new Panel();
- Panel_Quality.BackColor = Color.FromArgb(100, 255, 255, 255);
- Panel_Quality.Top = 5;
- Panel_Quality.Width = Quality.Length * 8 + 30;
- Panel_Quality.Left = tmp.Width - (Panel_Quality.Width + 5);
- Panel_Quality.Height = 30;
- Label Text_Quality = new Label();
- Text_Quality.ForeColor = Color.FromArgb(33, 33, 33);
- Text_Quality.Font = new Font("Century Gothic", 10);
- Text_Quality.AutoSize = false;
- Text_Quality.TextAlign = ContentAlignment.MiddleCenter;
- Text_Quality.Dock = DockStyle.Fill;
- Text_Quality.Text = Quality;
- Panel Panel_Audio = new Panel();
- Panel_Audio.BackColor = Color.FromArgb(100, 255, 255, 255);
- Panel_Audio.Top = 5;
- Panel_Audio.Width = Audio.Length * 8 + 30;
- Panel_Audio.Left = tmp.Width - (Panel_Quality.Width + Panel_Audio.Width + 10);
- Panel_Audio.Height = 30;
- Label Text_Audio = new Label();
- Text_Audio.ForeColor = Color.FromArgb(33, 33, 33);
- Text_Audio.Font = new Font("Century Gothic", 10);
- Text_Audio.AutoSize = false;
- Text_Audio.TextAlign = ContentAlignment.MiddleCenter;
- Text_Audio.Dock = DockStyle.Fill;
- Text_Audio.Text = Audio;
- Panel Panel_Video = new Panel();
- Panel_Video.BackColor = Color.FromArgb(100, 255, 255, 255);
- Panel_Video.Top = 5;
- Panel_Video.Width = tmp.Width - (Panel_Quality.Width + Panel_Audio.Width + 20);
- Panel_Video.Left = 5;
- Panel_Video.Height = 30;
- Label Text_Video = new Label();
- Text_Video.ForeColor = Color.FromArgb(33, 33, 33);
- Text_Video.Font = new Font("Century Gothic", 10);
- Text_Video.AutoSize = false;
- Text_Video.TextAlign = ContentAlignment.MiddleCenter;
- Text_Video.Dock = DockStyle.Fill;
- Text_Video.Text = Video;
- Panel Panel_Download = new Panel();
- Panel_Download.BackColor = Color.FromArgb(255, 255, 255);
- Panel_Download.Top = 40;
- Panel_Download.Width = tmp.Width - 10;
- Panel_Download.Left = 5;
- Panel_Download.Height = 35;
- ProgressBar pbb = new ProgressBar();
- pbb.Dock = DockStyle.Fill;
- pbb.Visible = false;
- Label Text_Download = new Label();
- Text_Download.BackColor = Color.FromArgb(0, 0, 0, 0);
- Text_Download.ForeColor = Color.FromArgb(33, 33, 33);
- Text_Download.Font = new Font("Century Gothic", 15);
- Text_Download.AutoSize = false;
- Text_Download.TextAlign = ContentAlignment.MiddleCenter;
- Text_Download.Dock = DockStyle.Fill;
- Text_Download.Text = "Télécharger !";
- Text_Download.Tag = urls[i] + ";" + text + ";" + Extension + ";" + Quality;
- Text_Download.MouseEnter += Panel_Download_Enter;
- Text_Download.MouseLeave += Panel_Download_Leave;
- Text_Download.Click += (sender2, e2) => Panel_Download_Click(sender2, e2, pbb);
- Panel_Download.Controls.Add(pbb);
- Panel_Download.Controls.Add(Text_Download);
- tmp.Controls.Add(Panel_Download);
- Panel_Quality.Controls.Add(Text_Quality);
- Panel_Audio.Controls.Add(Text_Audio);
- Panel_Video.Controls.Add(Text_Video);
- tmp.Controls.Add(Panel_Quality);
- tmp.Controls.Add(Panel_Audio);
- tmp.Controls.Add(Panel_Video);
- Container.Controls.Add(tmp);
- j++;
- }
- }
- Panel Panel_Re = new Panel();
- Panel_Re.BackColor = Color.FromArgb(255, 255, 255);
- Panel_Re.Top = (urls.Length-1) * 90 + 40;
- Panel_Re.Width = bunifuSeparator1.Width;
- Panel_Re.Left = 0;
- Panel_Re.Height = 45;
- Label Text_Re = new Label();
- Text_Re.BackColor = Color.FromArgb(0, 0, 0, 0);
- Text_Re.ForeColor = Color.FromArgb(255, 0, 0);
- Text_Re.Font = new Font("Century Gothic", 20);
- Text_Re.AutoSize = false;
- Text_Re.TextAlign = ContentAlignment.MiddleCenter;
- Text_Re.Dock = DockStyle.Fill;
- Text_Re.Text = "Télécharger une autre vidéo !";
- Text_Re.MouseEnter += Panel_Re_Enter;
- Text_Re.MouseLeave += Panel_Re_Leave;
- Text_Re.Click += (sender2, e2) => Panel_Re_Click(sender2, e2, Container);
- Panel_Re.Controls.Add(Text_Re);
- Container.Controls.Add(Panel_Re);
- }
- }
- private void Panel_Download_Click(object sender, EventArgs e, object progressBar)
- {
- Label senderLabel = (Label)sender;
- ProgressBar pb = progressBar as ProgressBar;
- pb.Visible = true;
- string[] Info = senderLabel.Tag.ToString().Split(';');
- string url = Info[0];
- string title = Info[1];
- string extension = Info[2];
- string quality = Info[3];
- string filename = title + "." + quality + "." + extension.ToLower();
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.RestoreDirectory = true;
- saveFileDialog.FileName = filename;
- if (saveFileDialog.ShowDialog() == DialogResult.OK)
- {
- WebClient client = new WebClient();
- client.DownloadProgressChanged += (sender2, e2) => On_Download(sender2, e2, progressBar);
- client.DownloadFileCompleted += (sender2, e2) => On_EndDownload(sender2, e2, progressBar);
- client.DownloadFileAsync(new Uri(url), saveFileDialog.FileName);
- }
- }
- void On_Download(object sender, DownloadProgressChangedEventArgs e, object progressBar)
- {
- ProgressBar pb = progressBar as ProgressBar;
- pb.Value = e.ProgressPercentage;
- }
- void On_EndDownload(object sender, EventArgs e, object progressBar)
- {
- ProgressBar pb = progressBar as ProgressBar;
- pb.Visible = false;
- pb.Value = 0;
- MessageBox.Show("Téléchargement terminé !");
- }
- private void Panel_Download_Enter(object sender, EventArgs e)
- {
- Label senderLabel = (Label)sender;
- senderLabel.ForeColor = Color.FromArgb(255, 255, 255);
- senderLabel.Cursor = Cursors.Hand;
- senderLabel.Parent.BackColor = Color.FromArgb(33, 33, 33);
- }
- private void Panel_Download_Leave(object sender, EventArgs e)
- {
- Label senderLabel = (Label)sender;
- senderLabel.ForeColor = Color.FromArgb(33, 33, 33);
- senderLabel.Cursor = Cursors.Default;
- senderLabel.Parent.BackColor = Color.FromArgb(255, 255, 255);
- }
- private void Panel_Re_Click(object sender, EventArgs e, object panel)
- {
- this.panel3.Visible = false;
- this.panel5.Visible = false;
- Panel Container = (Panel)panel;
- Container.Dispose();
- }
- private void Panel_Re_Enter(object sender, EventArgs e)
- {
- Label senderLabel = (Label)sender;
- senderLabel.ForeColor = Color.FromArgb(255, 255, 255);
- senderLabel.Cursor = Cursors.Hand;
- senderLabel.Parent.BackColor = Color.FromArgb(255, 0, 0);
- }
- private void Panel_Re_Leave(object sender, EventArgs e)
- {
- Label senderLabel = (Label)sender;
- senderLabel.ForeColor = Color.FromArgb(255, 0, 0);
- senderLabel.Cursor = Cursors.Default;
- senderLabel.Parent.BackColor = Color.FromArgb(255, 255, 255);
- }
- public static string XmlHttpRequest(string urlString)
- {
- string response = null;
- HttpWebRequest httpWebRequest = null;//Declare an HTTP-specific implementation of the WebRequest class.
- HttpWebResponse httpWebResponse = null;//Declare an HTTP-specific implementation of the WebResponse class
- //Creates an HttpWebRequest for the specified URL.
- httpWebRequest = (HttpWebRequest)WebRequest.Create(urlString);
- try
- {
- //Set HttpWebRequest properties
- httpWebRequest.Method = "GET";
- //Sends the HttpWebRequest, and waits for a response.
- httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
- if (httpWebResponse.StatusCode == HttpStatusCode.OK)
- {
- //Get response stream into StreamReader
- using (Stream responseStream = httpWebResponse.GetResponseStream())
- {
- using (StreamReader reader = new StreamReader(responseStream))
- response = reader.ReadToEnd();
- }
- }
- httpWebResponse.Close();//Close HttpWebResponse
- }
- catch (WebException we)
- { //TODO: Add custom exception handling
- throw new Exception(we.Message);
- }
- catch (Exception ex) { throw new Exception(ex.Message); }
- finally
- {
- httpWebResponse.Close();
- //Release objects
- httpWebResponse = null;
- httpWebRequest = null;
- }
- return response;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement