public Download(string url, string saveto, Panel panel, VistaControls.ProgressBar pb, VistaControls.ThemeText.ThemedLabel name,
            VistaControls.ThemeText.ThemedLabel speed,
            VistaControls.ThemeText.ThemedLabel percent,
            VistaControls.Button cancel)
        {
            _Panel = panel;
            this.URL = url;
            this.Name = Path.GetFileName(url);
            this.SaveTo = saveto;
            this._Pb = pb;
            this._LblPercent = percent;
            this._LblName = name;
            this._LblSpeed = speed;
            this._BtnCancel = cancel;

            _LblName.Text = Name;
            _LblPercent.Text = "0% 0B/0B";
            _LblSpeed.Text = "0B/s";

            this._Client = new WebClient();
            _Client.UseDefaultCredentials = true;

            avg = new long[1000];
        }
        public void Add(string url)
        {
            #region GENERATED CODE
            VistaControls.ProgressBar pbPercent = new VistaControls.ProgressBar();
            VistaControls.ThemeText.ThemedLabel lblName = new VistaControls.ThemeText.ThemedLabel();
            VistaControls.ThemeText.ThemedLabel lblPercent = new VistaControls.ThemeText.ThemedLabel();
            VistaControls.ThemeText.ThemedLabel lblSizeInfo = new VistaControls.ThemeText.ThemedLabel();
            VistaControls.Button btnCancel = new VistaControls.Button();

            System.Windows.Forms.Panel panel = new System.Windows.Forms.Panel();
            panel.SuspendLayout();
            //
            // pbPercent
            //
            pbPercent.Location = new System.Drawing.Point(3, 40);
            pbPercent.Name = "pbPercent";
            pbPercent.Size = new System.Drawing.Size(373, 23);
            pbPercent.TabIndex = 6;
            //
            // lblName
            //
            lblName.BorderSize = 10;
            lblName.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            lblName.Location = new System.Drawing.Point(3, 4);
            lblName.Name = "lblName";
            lblName.Padding = new System.Windows.Forms.Padding(10, 9, 0, 0);
            lblName.Size = new System.Drawing.Size(334, 34);
            lblName.TabIndex = 9;
            lblName.Text = "Loading";
            //
            // btnCancel
            //
            btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
            btnCancel.Image = Download_Manager.Properties.Resources.icon_cross.ToBitmap();
            btnCancel.Location = new System.Drawing.Point(376-22, 10);
            btnCancel.Name = "btnCancel";
            btnCancel.Size = new System.Drawing.Size(22, 23);
            btnCancel.TabIndex = 11;
            btnCancel.Text = " ";
            btnCancel.TextAlign = System.Drawing.ContentAlignment.BottomRight;
            btnCancel.UseVisualStyleBackColor = true;
            btnCancel.Parent = panel;
            btnCancel.Show();
            //
            // lblPercent
            //
            lblPercent.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            lblPercent.Location = new System.Drawing.Point(3, 63);
            lblPercent.Name = "lblPercent";
            lblPercent.Size = new System.Drawing.Size(196, 27);
            lblPercent.TabIndex = 7;
            lblPercent.Text = ".............";
            lblPercent.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            //
            // lblSizeInfo
            //
            lblSizeInfo.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            lblSizeInfo.Location = new System.Drawing.Point(205, 63);
            lblSizeInfo.Name = "lblSizeInfo";
            lblSizeInfo.Size = new System.Drawing.Size(172, 27);
            lblSizeInfo.TabIndex = 8;
            lblSizeInfo.Text = ".............";
            lblSizeInfo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            //
            // panel
            //
            panel.BackColor = System.Drawing.Color.Transparent;
            panel.Controls.Add(pbPercent);
            panel.Controls.Add(lblSizeInfo);
            panel.Controls.Add(lblName);
            //panel.Controls.Add(btnCancel);
            panel.Controls.Add(lblPercent);
            panel.ForeColor = System.Drawing.Color.Black;
            panel.Location = new System.Drawing.Point(12, 12);
            panel.Name = "panel";
            panel.Size = new System.Drawing.Size(376, 99);
            panel.TabIndex = 10;
            #endregion

            panel.Parent = this._Form;

            //btnCancel.Parent = _Form;
            Download dl = new Download(url, "", panel, pbPercent, lblName, lblSizeInfo, lblPercent, btnCancel);
            dl.SaveTo = Environment.GetEnvironmentVariable("USERPROFILE") + Path.DirectorySeparatorChar + "Downloads" + Path.DirectorySeparatorChar + dl.Name;
            btnCancel.Click += delegate(object sender, EventArgs e)
            {
                dl.Stop();
                dl.RemoveControls();
                panels.Remove(panel);
                panel.Dispose();
                RePosition();
            };

            DateTime start = DateTime.Now;
            dl.Start(start, delegate()
            {
                dl.RemoveControls();
                CommandLink btn = new CommandLink();
                btn.Parent = dl._Panel;
                btn.SetBounds(1, 1, dl._Panel.Width - 1, dl._Panel.Height - 10);
                btn.Text = "Open";
                btn.Note = "Open " + dl.Name;
                btn.Click += delegate(object sender, EventArgs args)
                {
                    try
                    {
                        ProcessStartInfo info = new ProcessStartInfo(dl.SaveTo);
                        Process.Start(info);
                    }
                    catch { }
                    dl.RemoveControls();
                    panels.Remove(dl._Panel);
                    dl._Panel.Dispose();
                    RePosition();
                };

            });

            downloads.AddLast(dl);
            panels.AddLast(panel);
            RePosition();
        }