C#自定义控件 类似于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,不过插件肯定比较大的了
C#自定义控件 类似于Linechart的更多相关文章
- MPAndroidChart Wiki(译文)~Part 2
7. 填充数据 这一章节将讲解给各式各样的图表设置数据的方法. 7.1 LineChart(线形图) 想给图表添加数据,使用如下方法: public void setData(ChartData da ...
- 自定义控件--CircleImageView(类似于QQ、微信圆形头像自定义控件)
现在基本上所有的需要用户注册的APP都有一个需要用户上传头像的需求,上传的头像基本都是类似于QQ.微信等社交应用圆形头像.最近,正在做的一个社交应用多处需要用到这种圆形头像的处理,总不能每次都对图片做 ...
- android自定义控件一站式入门
自定义控件 Android系统提供了一系列UI相关的类来帮助我们构造app的界面,以及完成交互的处理. 一般的,所有可以在窗口中被展示的UI对象类型,最终都是继承自View的类,这包括展示最终内容的非 ...
- ASP.NET MVC学习之母版页和自定义控件的使用
一.母板页_Layout.cshtml类似于传统WebForm中的.master文件,起到页面整体框架重用的目地1.母板页代码预览 <!DOCTYPE html> <html> ...
- android第一行代码-6.自定义控件的实现
0.假设一个应用中标题栏控件都是共用的,如果每个activity都需要设置button,绑定方法,那代码就会很臃肿.那我们可以自定义控件,然后继承这个控件就行了. 自定义控件为TitleLayout, ...
- android自定义控件(3)-自定义当前按钮属性
那么还是针对我们之前写的自定义控件:开关按钮为例来说,在之前的基础上,我们来看看有哪些属性是可以自定义的:按钮的背景图片,按钮的滑块图片,和按钮的状态(是开还是关),实际上都应该是可以在xml文件中直 ...
- android自定义控件(1)-点击实现开关按钮切换
自定义控件的步骤.用到的主要方法: 1.首先需要定义一个类,继承自View:对于继承View的类,会需要实现至少一个构造方法:实际上这里一共有三个构造方法: public View (Contex ...
- android 自定义控件 使用declare-styleable进行配置属性(源码角度)
android自定义styleableattrs源码 最近在模仿今日头条,发现它的很多属性都是通过自定义控件并设定相关的配置属性进行配置,于是便查询了解了下declare-styleabl ...
- c#自定义控件属性面板及选择资源设置
博客转移到 http://jacean.github.io/ 继续分享编程经验 因为要做流体布局,但两个控件没办法组合,就做自定义控件.这个控件需要一个text设置文本,一个pic设置图片显示,图片通 ...
随机推荐
- android 在githup中的资源整理(转)
1.Github开源Android组件资源整理(一) 个性化控件(View) 2.Github开源Android组件资源整理(二)ActionBar和Menu 3. Github开源Android组件 ...
- WPF中的ListBox实现按块显示元素的方法
本文实例讲述了WPF中的ListBox实现按块显示元素的方法.分享给大家供大家参考,具体如下: 注意:需要设置ListBox的属性 ScrollViewer.HorizontalScrollBarVi ...
- LeetCode(100)题解--Same Tree
https://leetcode.com/problems/same-tree/ 题目: Given two binary trees, write a function to check if th ...
- 【SSH进阶之路】Hibernate映射——一对一单向关联映射(五)
[SSH进阶之路]Hibernate基本原理(一) ,小编介绍了Hibernate的基本原理以及它的核心,採用对象化的思维操作关系型数据库. [SSH进阶之路]Hibernate搭建开发环境+简单实例 ...
- activemq 搭建--集群
linux activmemq 集群安装,配置和高可用测试 从 ActiveMQ 5.9 开始,ActiveMQ 的集群实现方式取消了传统的Master-Slave 方式,增加了基于Z ...
- .net 平台下的AI框架
Aforge.net之旅——开篇:从识别验证码开始 基于AForge.Net框架的扑克牌识别 人工神经网络入门(4) —— AFORGE.NET简介 .NET开源工程推荐(Accord,AForge, ...
- HDU - 4990 Reading comprehension 【矩阵快速幂】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4990 题意 初始的ans = 0 给出 n, m for i in 1 -> n 如果 i 为奇 ...
- BZOJ 3083 遥远的国度 树链剖分+线段树
有换根的树链剖分的裸题. 在换根的时候注意讨论. 注意数据范围要开unsigned int或longlong #include<iostream> #include<cstdio&g ...
- easyui datagrid行合并
easyui datagrid行合并 合并方法 /** * EasyUI DataGrid根据字段动态合并单元格 * 参数 tableID 要合并table的id * 参数 colList 要合并的列 ...
- Uncaught TypeError: Illegal invocation解决
jquery中报了这个错,仔细一看,有个使用ajax的地方,其中有个参数是从页面某个文本框获取的,本应该 $('#id').value ,被我写成了 $('id') .所以报错,目前已解决.