コード例 #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     //this.addressBox1.Text="https://bing.com.cn";
     //this.addressBox1.UrlTitle = "必应";
     try
     {
         //添加到ToolStripDropDown的Items中
         //将ComboBox列表中的项添加到ToolStripDropDown的Items中
         if (myToolStripDropDown != null)
         {
             myToolStripDropDown.AutoSize = true;
             myDownloadToolStrip dropDownItem = new myDownloadToolStrip("铁呀呀的牙");
             dropDownItem.AutoSize           = false;
             dropDownItem.DownloadSpeed      = "大小:81.93MB - 8.14MB/s";
             dropDownItem.ProgressPercentage = 85;
             dropDownItem.Image      = Resources.mnudownload;
             dropDownItem.ImageAlign = ContentAlignment.MiddleLeft;
             dropDownItem.TextAlign  = ContentAlignment.MiddleLeft;
             dropDownItem.Size       = new Size(this.panel1.Width, 60);
             //插入项"清空地址栏下列表"之前
             //myToolStripDropDown.Items.Insert(myToolStripDropDown.Items.Count, dropDownItem);
             myToolStripDropDown.Items.Add(dropDownItem);
             myToolStripDropDown.Update();
             //myToolStripDropDown.Items.Add(dropDownItem);
         }
     }
     catch (Exception ex)
     {
         //Win32API.OutputDebugStringA(string.Format("添加时遇到错误:{0}",ex.Message));
     }
 }
コード例 #2
0
        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                //tableLayoutPanel1.MaximumSize = new Size(tableLayoutPanel1.Width, 60 *toolStrip1.Items.Count);
                //tableLayoutPanel1.AutoScroll = true;

                this.toolStrip1.Width = panelOwner1.Width;
                myDownloadToolStrip item = new myDownloadToolStrip();
                item.AutoSize           = false;
                item.Text               = string.Format("PCQQ2020({0}).exe", DateTime.Now.ToString("ss"));
                item.DownloadSpeed      = "大小:81.93MB - 8.14MB/s";
                item.ProgressPercentage = 85;
                item.Image              = (Image)Properties.Resources.mnudownload;
                item.BackColor          = Color.DarkGray;
                item.NormalColor        = Color.White;
                item.Width              = panelOwner1.Width;
                item.Height             = 60;
                this.toolStrip1.Items.Add(item);
                this.toolStrip1.AutoSize = true;
                //listBox1.Items.Add(toolStrip1);
            }
            catch (Exception ex)
            {
                Win32API.OutputDebugStringA(ex.Message);
            }
        }
コード例 #3
0
 /// <summary>
 /// 添加新的下载任务
 /// </summary>
 public void AddDownloadTask()
 {
     try
     {
         if (PublicModule.bolDownFlag)
         {
             PublicModule.bolDownFlag = false;
             //添加到下载列表
             this.ToolStripDownloadList.Width = pnlDownloadList.Width;
             myDownloadToolStrip item = new myDownloadToolStrip();
             item.AutoSize      = false;
             item.Image         = (Image)Properties.Resources.mnudownload;
             item.BackColor     = Color.DarkGray;
             item.ForeColor     = Color.FromArgb(0x9b9b9b);
             item.NormalColor   = Color.White;
             item.SelectedColor = Color.Orange;
             //item.HoverColor = Color.Green;
             item.SeparateColor = Color.FromArgb(239, 239, 239);
             item.Width         = pnlDownloadList.Width;
             item.Height        = 60;
             //pnlDownloadList.AutoScrollMinSize = new Size(item.Width, item.Height);
             //this.ToolStripDownloadList.ImageScalingSize = new Size(item.Width, item.Height);
             //下载相关的参数,生成新的下载列表项
             item.DownloadUrl        = PublicModule.DownloadUrl;  //设置此项后初始化下载
             item.DownSavePath       = PublicModule.DownSavePath; //下载后保存的路径
             item.DownSaveSize       = PublicModule.DownSaveSize; //下载文件的大小
             item.DownSaveFile       = PublicModule.DownSaveFile; //设置此项后,开始下载
             item.ProgressPercentage = 0;
             item.DownloadCompleted  = false;
             //添加到列表中
             this.ToolStripDownloadList.Items.Add(item);
             item.StartDownload = true;
             //释放
             //下载列表项的窗口的自适应大小
             //this.ToolStripDownloadList.Height = this.ToolStripDownloadList.Items.Count * 60;
             this.ToolStripDownloadList.AutoSize = true;
             //
             foreach (myDownloadToolStrip itmeL in ToolStripDownloadList.Items)
             {
                 if (this.ToolStripDownloadList.Items.Count > 5)
                 {
                     itmeL.Width = pnlDownloadList.Width - SystemInformation.VerticalScrollBarWidth;
                 }
                 else
                 {
                     itmeL.Width = pnlDownloadList.Width;
                 }
                 pnlDownloadList.Invalidate();
             }
         }
     }
     catch (Exception ex)
     {
         //MsgBox("初始化参数出现错误,错误信息:" + ex.Message);
     }
 }
コード例 #4
0
        private void btnVirtualOne_Click(object sender, EventArgs e)
        {
            try
            {
                //tableLayoutPanel1.MaximumSize = new Size(tableLayoutPanel1.Width, 60 *toolStrip1.Items.Count);
                //tableLayoutPanel1.AutoScroll = true;
                //pnlDownloadList.VerticalScroll.Minimum = 60;
                //pnlDownloadList.VerticalScroll.Value = pnlDownloadList.VerticalScroll.Minimum;
                this.ToolStripDownloadList.Width = pnlDownloadList.Width;
                myDownloadToolStrip item = new myDownloadToolStrip();
                item.AutoSize           = false;
                item.Text               = string.Format("PCQQ2020({0}).exe", DateTime.Now.ToString("ss"));
                item.DownloadSpeed      = "大小:81.93MB - 8.14MB/s";
                item.ProgressPercentage = 85;
                item.Image              = (Image)Properties.Resources.mnudownload;
                item.BackColor          = Color.DarkGray;
                item.ForeColor          = Color.FromArgb(0x9b9b9b);
                item.NormalColor        = Color.White;
                item.SelectedColor      = Color.Orange;
                //item.HoverColor = Color.Green;
                item.SeparateColor = Color.FromArgb(239, 239, 239);
                item.Width         = pnlDownloadList.Width;
                item.Height        = 60;
                //pnlDownloadList.AutoScrollMinSize = new Size(item.Width, item.Height);
                //this.ToolStripDownloadList.ImageScalingSize = new Size(item.Width, item.Height);
                this.ToolStripDownloadList.Items.Add(item);

                //this.ToolStripDownloadList.Height = this.ToolStripDownloadList.Items.Count * 60;
                this.ToolStripDownloadList.AutoSize = true;
                //
                foreach (myDownloadToolStrip itmeL in ToolStripDownloadList.Items)
                {
                    //Win32API.EnableScrollBar(this.pnloDownloadList.Handle, Win32API.SBFlags.SB_VERT, Win32API.SBArrows.ESB_DISABLE_BOTH);
                    if (this.ToolStripDownloadList.Items.Count > 5)
                    {
                        itmeL.Width = pnlDownloadList.Width - SystemInformation.VerticalScrollBarWidth;
                        //pnlDownloadList.AutoScrollMinSize = new Size(pnlDownloadList.Width - SystemInformation.VerticalScrollBarWidth, pnlDownloadList.Height);
                    }
                    else
                    {
                        itmeL.Width = pnlDownloadList.Width;
                        //pnloDownloadList.AutoScrollMinSize = new Size(pnloDownloadList.Width, pnloDownloadList.Height);
                    }
                    pnlDownloadList.Invalidate();
                }
                //listBox1.Items.Add(toolStrip1);
            }
            catch (Exception ex)
            {
                Win32API.OutputDebugStringA(ex.Message);
            }
        }
コード例 #5
0
 private void button6_Click(object sender, EventArgs e)
 {
     try
     {
         if (listBox1.SelectedItem != null)
         {
             myDownloadToolStrip item = new myDownloadToolStrip();
             item = listBox1.SelectedItem as myDownloadToolStrip;
             if (item != null)
             {
                 MessageBox.Show(item.Text);
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
コード例 #6
0
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem lvitem = new ListViewItem();

                myDownloadToolStrip item = new myDownloadToolStrip();
                item.Text               = string.Format("PCQQ2020({0}).exe", DateTime.Now.ToString("ss"));
                item.DownloadSpeed      = "大小:81.93MB - 8.14MB/s";
                item.ProgressPercentage = 85;
                item.Image              = (Image)Properties.Resources.mnudownload;
                item.BackColor          = Color.DarkGray;
                item.Width              = listBox1.Width;
                item.Height             = 60;
                item.PercentageChanged += Item_PercentageChanged;;
                this.listBox1.Items.Add(item);
            }
            catch (Exception ex)
            {
                Win32API.OutputDebugStringA(ex.Message);
            }
        }
コード例 #7
0
 private void trackBar1_ValueChanged(object sender, EventArgs e)
 {
     try
     {
         this.DoubleBuffered = true;
         if (listBox1.SelectedItem != null)
         {
             myDownloadToolStrip item = new myDownloadToolStrip();
             item = listBox1.SelectedItem as myDownloadToolStrip;
             if (item != null)
             {
                 item.ProgressPercentage = trackBar1.Value;
                 Win32API.OutputDebugStringA(string.Format("item.bounds({0},{1},{2},{3})",
                                                           item.Bounds.X, item.Bounds.Y, item.Bounds.Width, item.Bounds.Height));
                 //listBox1.Invalidate(item.Bounds);
                 item.Invalidate();
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
コード例 #8
0
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            //listBox1.Invalidate(e.Bounds);
            try
            {
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    //e.DrawBackground();
                    e.Graphics.FillRectangle(new SolidBrush(Color.DarkGray), listBox1.GetItemRectangle(e.Index));
                }
                else if ((e.State & DrawItemState.HotLight) == DrawItemState.HotLight)
                {
                    //e.DrawBackground();
                    e.Graphics.FillRectangle(new SolidBrush(Color.Gray), listBox1.GetItemRectangle(e.Index));
                }
                else if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive)
                {
                    //e.DrawBackground();
                    e.Graphics.FillRectangle(new SolidBrush(Color.White), listBox1.GetItemRectangle(e.Index));
                }

                //e.DrawFocusRectangle();

                if (e.Index >= 0)
                {
                    myDownloadToolStrip item = new myDownloadToolStrip();
                    item = listBox1.Items[e.Index] as myDownloadToolStrip;
                    //item.Invalidate();
                    if (item != null)
                    {
                        e.Graphics.DrawLine(new Pen(Color.DarkGray), new Point(e.Bounds.Left, e.Bounds.Top + e.Bounds.Height - 1), new Point(e.Bounds.Width, e.Bounds.Top + e.Bounds.Height - 1));
                        if (item.Image != null)
                        {
                            e.Graphics.DrawImage(item.Image, e.Bounds.Left + 32 / 2, e.Bounds.Top + 32 / 2, 32, 32);
                        }
                        if (item.Text.Length > 0)
                        {
                            TextRenderer.DrawText(e.Graphics, item.Text, new Font("微软雅黑", 11), new Rectangle(e.Bounds.Left + 64, e.Bounds.Top + 12, e.Bounds.Width - 100, e.Bounds.Height), ForeColor, TextFormatFlags.Left | TextFormatFlags.Top);
                            //e.Graphics.DrawString(item.Text,  Font, ForeColor, 50, 8, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                        }
                        if (item.DownloadSpeed.Length > 0)
                        {
                            TextRenderer.DrawText(e.Graphics, item.DownloadSpeed, new Font("微软雅黑", 9), new Rectangle(e.Bounds.Left, e.Bounds.Top + 12, e.Bounds.Width - 100, e.Bounds.Height), ForeColor, TextFormatFlags.Right | TextFormatFlags.Top);
                            //e.Graphics.DrawString(item.Text,  Font, ForeColor, 50, 8, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                        }
                        //画进度条
                        //e.Graphics.DrawRectangle(new Pen(Color.Gray), e.Bounds.Left + 68, e.Bounds.Top + 32, e.Bounds.Width-168, 8 );
                        Rectangle rectfull = new Rectangle(e.Bounds.Left + 68, e.Bounds.Top + 36, e.Bounds.Width - 168, 4);

                        e.Graphics.FillRectangle(new SolidBrush(Color.Gray), rectfull);

                        //把进度条的宽度分成100份
                        float nowprec = rectfull.Width / 100F;


                        //Win32API.OutputDebugStringA(string.Format("item.ProgressPercentage({0}),nowprec=({1})", item.ProgressPercentage, nowprec.ToString()));
                        if (item.ProgressPercentage <= 30)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.DarkGray), new RectangleF(rectfull.Left, rectfull.Top, item.ProgressPercentage * nowprec, rectfull.Height));
                        }
                        else if (item.ProgressPercentage <= 50)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.Red), new RectangleF(rectfull.Left, rectfull.Top, item.ProgressPercentage * nowprec, rectfull.Height));
                        }
                        else if (item.ProgressPercentage <= 70)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.Blue), new RectangleF(rectfull.Left, rectfull.Top, item.ProgressPercentage * nowprec, rectfull.Height));
                        }
                        else if (item.ProgressPercentage <= 99)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.Green), new RectangleF(rectfull.Left, rectfull.Top, item.ProgressPercentage * nowprec, rectfull.Height));
                        }
                        else if (item.ProgressPercentage == 100)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.Green), new RectangleF(rectfull.Left, rectfull.Top, rectfull.Width, rectfull.Height));
                        }
                        string width2percentage = string.Format("width:{0}, {1}%, barwidth:{2}, step:{3}", rectfull.Width, item.ProgressPercentage, item.ProgressPercentage * nowprec, nowprec);

                        //TextRenderer.DrawText(e.Graphics, width2percentage, new Font("微软雅黑", 9), new Rectangle(e.Bounds.Left, e.Bounds.Top + 32, e.Bounds.Width - 100, e.Bounds.Height), ForeColor, TextFormatFlags.Right | TextFormatFlags.Top);

                        //画暂停/恢复按钮
                        Rectangle btnRectControl = new Rectangle(e.Bounds.Width - 60, e.Bounds.Top + 20, 16, 16);
                        if (btnRectControl.Contains(pMouseMove))
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.Red), btnRectControl);
                            if (btnRectControl.Contains(pMouseDown))
                            {
                                pMouseDown = new Point(0, 0);
                                e.Graphics.FillRectangle(new SolidBrush(Color.DarkOrange), btnRectControl);

                                bolIsStoped = !bolIsStoped;
                                IsStoped    = bolIsStoped;
                            }
                        }
                        else
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.Blue), btnRectControl);
                            //this.Invalidate();
                        }

                        if (IsStoped)
                        {
                            e.Graphics.DrawImage(Resources.bsuspend, btnRectControl.Left, btnRectControl.Top, 16, 16);
                        }
                        else
                        {
                            e.Graphics.DrawImage(Resources.bresume, btnRectControl.Left, btnRectControl.Top, 16, 16);
                        }
                        //画删除按钮
                        Rectangle btnRectDelete = new Rectangle(e.Bounds.Width - 30, e.Bounds.Top + 20, 16, 16);
                        if (btnRectDelete.Contains(pMouseMove))
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.Red), btnRectDelete);
                            if (btnRectDelete.Contains(pMouseDown))
                            {
                                pMouseDown = new Point(0, 0);
                                e.Graphics.FillRectangle(new SolidBrush(Color.DarkOrange), btnRectDelete);

                                //删除这一项
                                //DeleteItem(true);
                                //this.Dispose();
                                //bolIsStoped = !bolIsStoped;
                            }
                        }
                        else
                        {
                            e.Graphics.FillRectangle(new SolidBrush(Color.Blue), btnRectDelete);
                        }
                        e.Graphics.DrawImage(Resources.bstop, btnRectDelete.Left, btnRectDelete.Top, 16, 16);

                        //ControlPaint.DrawButton(e.Graphics, new Rectangle(e.Bounds.Width - 80, e.Bounds.Top + 16, 32, 32), ButtonState.Normal);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }