首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

看到野比叔发了一个山寨进度条 小弟我也来发一个

2012-08-30 
看到野比叔发了一个山寨进度条 我也来发一个这是使用form为载体的 优点:ShowDialog后无法操作调用方如果只

看到野比叔发了一个山寨进度条 我也来发一个
这是使用form为载体的 优点:ShowDialog后无法操作调用方

如果只是作为1个简单的进度条 可以把 Form 改成 重载成 Control

因为是自己用的 所以没有把字符串什么的自定义出来 可以自己改进



C#:
调用:

C# code
 using (MyProgressBar ms = new MyProgressBar())            {                ms.ShowDialog();            }

C# code
public class MyProgressBar : Form    {        public MyProgressBar()            : base()        {            MouseMove += User_MouseMove;            MouseUp += User_MouseUp;            MouseDown += User_MouseDown;            Load += StartupLoad_Load;            this.SuspendLayout();            this.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;            this.DoubleBuffered = true;            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;            this.ShowInTaskbar = false;            this.Text = "进度条";            this.Opacity = 0.7;            this.TopMost = true;            this.ResumeLayout(false);        }        private void StartupLoad_Load(object sender, System.EventArgs e)        {            this.Size = new System.Drawing.Size(258, 30);            timer = new System.Threading.Timer(new System.Threading.TimerCallback(TimerChangeInvoke), null, 10, 30);        }        protected override void Dispose(bool disposing)        {            try            {                if (timer != null)                {                    timer.Dispose();                    timer = null;                }            }            finally            {                base.Dispose(disposing);            }        }        /// <summary>        /// 阴影坐标        /// </summary>        /// <remarks></remarks>        private Rectangle backlint = new Rectangle(0, 0, 101, 0);        /// <summary>        /// 重绘工作区域        /// </summary>        /// <param name="e"></param>        /// <remarks></remarks>        protected override void OnSizeChanged(System.EventArgs e)        {            base.OnSizeChanged(e);            using (GraphicsPath r = new GraphicsPath())            {                Rectangle[] re = new Rectangle[] {                new Rectangle(2, 0, Width - 4, 1),                new Rectangle(1, 1, Width - 2, 1),                new Rectangle(0, 2, Width, Height - 4),                new Rectangle(1, Height - 2, Width - 2, 1),                new Rectangle(2, Height - 1, Width - 4, 1)            };                r.AddRectangles(re);                this.Region = new Region(r);                backlint.Height = this.Height;            }            this.Refresh();        }        /// <summary>        /// 重绘窗体        /// </summary>        /// <param name="e"></param>        /// <remarks></remarks>        protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)        {            if (e != null)            {                Color bordercol = Color.FromArgb(81, 169, 215);                Color backcol = Color.FromArgb(228, 242, 249);                Color titlecol = Color.FromArgb(24, 122, 174);                Color jianbiancol = Color.FromArgb(182, 225, 247);                e.Graphics.Clear(Color.White);                using (LinearGradientBrush br = new LinearGradientBrush(DisplayRectangle, Color.Transparent, Color.Transparent, 80f))                {                    ColorBlend sb = new ColorBlend();                    sb.Colors = new Color[] {                    backcol,                    Color.FromArgb(60, backcol),                    Color.FromArgb(30, backcol),                    Color.FromArgb(60, backcol),                    Color.FromArgb(100, backcol),                    Color.FromArgb(130, backcol)                };                    sb.Positions = new float[] {                    0f,                    3.5f / 5f,                    4.0f / 5f,                    4.5f / 5f,                    4.7f / 5f,                    1f                };                    br.InterpolationColors = sb;                    e.Graphics.FillRectangle(br, DisplayRectangle);                }                //动态背景                using (LinearGradientBrush br = new LinearGradientBrush(backlint, Color.Transparent, Color.Transparent, 0f))                {                    ColorBlend sb = new ColorBlend();                    sb.Colors = new Color[] {                    Color.Transparent,                    Color.FromArgb(60, jianbiancol),                    Color.FromArgb(150, jianbiancol),                    Color.FromArgb(180, jianbiancol),                    Color.FromArgb(100, jianbiancol),                    Color.FromArgb(10, jianbiancol)                };                    sb.Positions = new float[] {                    0f,                    1.5f / 5f,                    2.8f / 5f,                    3.7f / 5f,                    4.5f / 5f,                    1f                };                    br.InterpolationColors = sb;                    e.Graphics.FillRectangle(br, backlint);                }                //                using (SolidBrush br = new SolidBrush(titlecol))                {                    using (StringFormat sf = new StringFormat())                    {                        sf.Alignment = StringAlignment.Center;                        sf.LineAlignment = StringAlignment.Center;                        e.Graphics.DrawString("正在初始化,请稍后...", SystemFonts.DefaultFont, br, this.DisplayRectangle, sf);                    }                }                //边框                using (Pen p = new Pen(bordercol, 2))                {                    e.Graphics.DrawRectangle(p, DisplayRectangle);                }                using (Pen p = new Pen(bordercol, 1))                {                    e.Graphics.DrawLine(p, 0, 0, 1, 1);                    e.Graphics.DrawLine(p, 1, Height - 2, 0, Height - 1);                    e.Graphics.DrawLine(p, Width - 2, 1, Width - 1, 0);                    e.Graphics.DrawLine(p, Width - 2, Height - 2, Width - 1, Height - 1);                }            }        }        #region "移动窗体"        private Point mousepoint;        private bool ismousedown;        private void User_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e)        {            mousepoint = PointToClient(MousePosition);            ismousedown = true;        }        private void User_MouseUp(System.Object sender, System.Windows.Forms.MouseEventArgs e)        {            ismousedown = false;        }        private void User_MouseMove(System.Object sender, System.Windows.Forms.MouseEventArgs e)        {            if (ismousedown)            {                int x = MousePosition.X - mousepoint.X;                int y = MousePosition.Y - mousepoint.Y;                int max = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - base.Width;                int may = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - base.Height;                if (x < 0)                {                    x = 0;                }                else if (x > max)                {                    x = max;                }                if (y < 0)                {                    y = 0;                }                else if (y > may)                {                    y = may;                }                Location = new Point(x, y);            }        }        #endregion        #region "定时回调"        private delegate void Async();        private System.Threading.Timer timer;        private void TimerChangeInvoke(object state)        {            this.BeginInvoke(new Async(TimerChange));        }        private void TimerChange()        {            Rectangle oldlint = backlint;            backlint.X += 5;            if (backlint.X > Width)            {                backlint.X = -backlint.Width;            }            this.Invalidate(oldlint);            this.Invalidate(backlint);            this.Update();        }        #endregion    } 





[解决办法]
泡了一天了
吃饭去
求丰盛晚餐




[解决办法]
好的 徐学习了
[解决办法]
虽然是野比的粉丝 但是每次野比的源文件下下来之后总是不想 留着以后看吧

[解决办法]
进来标记下,明天再研究
[解决办法]
如此漂亮,学习了!
[解决办法]
最近rayyu很给力,支持 

只是我为啥就成了欧吉桑了
[解决办法]
探讨

引用:

最近rayyu很给力,支持

只是我为啥就成了欧吉桑了


哈哈 我经常看见你宣传你自己 喝着小酒看着韩剧啊

好像我这个不是进度条 因为没有进度, 不如叫 缓冲动态提示好了

[解决办法]
支持原创,支持分享
[解决办法]
不错学习了 今天看了好几个帖子 大家都在呼叫野比,,再这么下去俺也要成为野比粉丝了。。
[解决办法]
探讨
最近rayyu很给力,支持

只是我为啥就成了欧吉桑了

[解决办法]
楼主大哥,你能给一行注释了,菜鸟表示看着压力很大

热点排行