首页 技术 正文
技术 2022年11月21日
0 收藏 345 点赞 3,861 浏览 1888 个字

界面效果:

C#自定义控件     类似于LinechartC#自定义控件     类似于Linechart


对外提供的属性设置

        /// <summary>        /// 背景色        /// </summary>        public Color BackColor;        /// <summary>        /// 边框颜色        /// </summary>        , , );        /// <summary>        /// 线条颜色        /// </summary>        , , );        /// <summary>        /// 折线颜色        /// </summary>        , , );        /// <summary>        /// 是否显示控件边框        /// </summary>        public bool rect_isvisable = false;
       /// <summary>        /// 边框线宽        /// </summary>        ;        /// <summary>        /// 垂直线条间距        /// </summary>        ;        /// <summary>        /// 水平线条间距        /// </summary>        ;        /// <summary>        /// 点密度,越小越稀疏        /// </summary>        private float point_density = 0.7f;        #region        public float Point_density        {            get            {                return point_density;            }            set            {                point_density = value;                 || value > )                {                    point_density = 0.7f;                }            }        }        public float Linewidth        {            get            {                return linewidth;            }            set            {                linewidth = value;                )                {                    linewidth = ;                }            }        }        public int Vertical_spacing        {            get            {                return vertical_spacing;            }            set            {                )                {                    value = ;                }                vertical_spacing = value;            }        }        public int Horizontal_spacing        {            get            {                return horizontal_spacing;            }            set            {                )                {                    value = ;                }                horizontal_spacing = value;            }        }        #endregion

这些要保证是大于0,我使用属性了,这样比频繁的类型转换要好


绘制

        protected override void OnPaint(PaintEventArgs pe)        {            this.drawtable();            this.drawpolygonal();            base.OnPaint(pe);        }        private void drawtable()//表格绘制        {            if (this.rect_isvisable)            {                this.rectanglelinecolor = Color.Black;            }            else            {                this.rectanglelinecolor = this.BackColor;            }            Graphics g = this.CreateGraphics();            g.FillRectangle(new SolidBrush(this.BackColor), this.ClientRectangle);            )+this.vertical_spacing;i<this.Height;i+=this.vertical_spacing)            {                g.DrawLine(), this.ClientRectangle.X, i, this.Width, i);            }            )+this.Horizontal_spacing;i<this.Width;i+=this.Horizontal_spacing)            {                g.DrawLine(), i,this.ClientRectangle.Y,i,  this.Height);            }            g.DrawRectangle(, , this.Width - this.linewidth, this.Height - this.linewidth);            g.Dispose();        }        /// <summary>        /// 折线绘制        /// </summary>        private void drawpolygonal()        {            Point ps=new Point();            Point pe;            Graphics g = this.CreateGraphics();            ,j=; i>=;i--,j++)            {                float f = this.polygonalpoint[i];                int w = this.Width - this.Horizontal_spacing_per_pp*j;                int h = this.Height - (int)(f * this.Height);                pe = ps;                ps = new Point(w, h);                )                {                    g.DrawLine(p,pe, ps);                }            }        }

链接:http://pan.baidu.com/s/1gdjod8J

添加到自己的项目里拖进去就可以了;和普通的控件一样使用

M$自己也有更好的linechart,不过插件肯定比较大的了

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893