(六十七)c#Winform自定义控件-柱状图

(六⼗七)c#Winform⾃定义控件-柱状图前提
⼊⾏已经7,8年了,⼀直想做⼀套漂亮点的⾃定义控件,于是就有了本系列⽂章。
如果觉得写的还⾏,请点个 star ⽀持⼀下吧
欢迎前来交流探讨: 企鹅568015492
⿇烦博客下⽅点个【推荐】,谢谢
NuGet
Install-Package HZH_Controls
⽬录
⽤处及效果
agps是什么意思
调⽤⽰例
1  this.ucBarChart1.SetDataSource(new double[] { random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100) });
2            this.ucBarChart2.SetDataSource(new double[] { random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100) }, new string[] { "张三", "李四", "王五", "赵六", "⽥七" });
3            this.ucBarChart3.SetDataSource(new double[] { random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100) }, new string[] { "张三", "李四", "王五", "赵六", "⽥七" });
4
5            this.ucBarChart4.SetDataSource(new double[] { random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100) }, new string[] { "张三", "李四", "王五", "赵六", "⽥七" });
6            this.ucBarChart4.AddAuxiliaryLine(60, Color.Red, "及格线超长占位符");
7
8            this.ucBarChart5.SetDataSource(new double[] { random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100), random.Next(50, 100) }, new string[] { "张三", "
李四", "王五", "赵六", "⽥七" });
一机双号9            this.ucBarChart5.AddAuxiliaryLine(50, Color.Black, "及格线");
10
11
12            var ds = new double[5][];
13            for (int i = 0; i < ds.Length; i++)
14            {
15                ds[i] = new double[] { random.Next(50, 100), random.Next(50, 100), random.Next(50, 100) };
16            }
17            this.ucBarChart6.BarChartItems = new HZH_Controls.Controls.BarChartItem[] { new HZH_Controls.Controls.BarChartItem(Color.Red, "语⽂"), new HZH_Controls.Controls.BarChartItem(
Color.Blue, "英语"), new HZH_Controls.Controls.BarChartItem(Color.Orange, "数学") };
18            this.ucBarChart6.SetDataSource(ds, new string[] { "张三", "李四", "王五", "赵六", "⽥七" });
19            this.ucBarChart6.AddAuxiliaryLine(60, Color.Black);
20
21            var ds2 = new List<double[]>();脉冲氙灯
22            for (int i = 0; i < 20; i++)
23            {
24                ds2.Add(new double[] { random.Next(800, 2000), random.Next(100, 200) });
25            }
26            var titles = new List<string>();
27            double dblSum = ds2.Sum(p=>p[0]);
28            for (int i = 0; i < ds2.Count; i++)
29            {
30                titles.Add("员⼯" + (i + 1) + "\n" + (ds2[i][0] / dblSum).ToString("0.0%"));
31            }
32            this.ucBarChart7.BarChartItems = new HZH_Controls.Controls.BarChartItem[] { new HZH_Controls.Controls.BarChartItem(Color.Green, "合格"), new HZH_Controls.Controls.BarChartItem(Color.Red, "次品") };
33            this.ucBarChart7.SetDataSource(ds2.ToArray(), titles.ToArray());
34            this.ucBarChart7.AddAuxiliaryLine(1000, Color.Black, "标准线");
准备⼯作
GDI画图,不懂可以先百度⼀下
另外⽤到了 不知道的可以先前往看⼀下
开始
我们先理⼀下思路,
我们需要值,x轴,y轴,辅助线,项列表,标题,以及⼀些颜⾊等
血浆分离器添加⼀个类UCBarChart ,继承UCControlBase
添加⼀些控制属性
1 /// <summary>
7        /// The value maximum left
8        /// </summary>
9        private int value_max_left = -1;
10
11        /// <summary>
12        /// The value minimum left
13        /// </summary>
14        private int value_min_left = 0;
15
16        /// <summary>
17        /// The value segment
太赫兹时域光谱18        /// </summary>
19        private int value_Segment = 5;
20
21        /// <summary>
22        /// The data values
23        /// </summary>
24        private double[][] data_values = null;
25
26        /// <summary>
27        /// The data texts
28        /// </summary>
29        private string[] data_texts = null;
30
31        / <summary>
32        / The data colors
33        / </summary>
34        //private Color[] data_colors = null;
35
36        /// <summary>
37        /// The brush deep
38        /// </summary>
39        private Brush brush_deep = null;
40
41        /// <summary>
42        /// The pen normal
43        /// </summary>
44        private Pen pen_normal = null;
45
46        /// <summary>
47        /// The pen dash
48        /// </summary>
49        private Pen pen_dash = null;
50
51        /// <summary>
52        /// The bar back color
53        /// </summary>
54        //private Color barBackColor = Color.FromArgb(255, 77, 59);
55
56        /// <summary>
57        /// The use gradient
58        /// </summary>
59        private bool useGradient = false;
60
61        /// <summary>
62        /// The color deep
63        /// </summary>
64        private Color color_deep = Color.FromArgb(150, 255, 77, 59);
65
66        /// <summary>
72        /// The format left
73        /// </summary>
74        private StringFormat format_left = null;
75
76        /// <summary>
77        /// The format right
78        /// </summary>
79        private StringFormat format_right = null;
80
81        /// <summary>
82        /// The format center
83        /// </summary>
84        private StringFormat format_center = null;
85
86        /// <summary>
87        /// The value is render dash line
88        /// </summary>
89        private bool value_IsRenderDashLine = true;
90
91        /// <summary>
92        /// The is show bar value
93        /// </summary>
94        private bool isShowBarValue = true;
95
96        /// <summary>
97        /// The show bar value format
98        /// </summary>
99        private string showBarValueFormat = "{0}";
100
101        /// <summary>
102        /// The value title
103        /// </summary>
104        private string value_title = "";
105
106        /// <summary>
107        /// The bar percent width
108        /// </summary>
109        private float barPercentWidth = 0.9f;
110
111        /// <summary>
112        /// The components
113        /// </summary>
114        private IContainer components = null;
115
116        /// <summary>
117        /// 获取或设置控件的背景⾊。
118        /// </summary>
119        /// <value>The color of the back.</value>
120        /// <PermissionSet>
121        ///  <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
122        /// </PermissionSet>
123        [Browsable(true)]
124        [Description("获取或设置控件的背景⾊")]
125        [Category("⾃定义")]
126        [DefaultValue(typeof(Color), "Transparent")]
127        [EditorBrowsable(EditorBrowsableState.Always)]
128        public override Color BackColor
129        {
130            get
134            set
135            {
136                base.BackColor = value;
137            }
138        }
139
140        /// <summary>
141        /// Gets or sets the text.
142        /// </summary>
143        /// <value>The text.</value>
144        [Browsable(true)]
145        [Description("获取或设置当前控件的⽂本")]
146        [Category("⾃定义")]
147        [EditorBrowsable(EditorBrowsableState.Always)]
148        [Bindable(true)]
149        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
150        public override string Text
151        {
152            get
153            {
154                return base.Text;
155            }
156            set
157            {
158                base.Text = value;
159                Invalidate();
160            }
161        }
162
163        /// <summary>
164        /// 获取或设置控件的前景⾊。
165        /// </summary>
166        /// <value>The color of the fore.</value>
167        /// <PermissionSet>
168        ///  <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
169        /// </PermissionSet>
170        [Browsable(true)]
171        [Description("获取或设置控件的前景⾊")]
埃及开始拓宽苏伊士运河
172        [Category("⾃定义")]
173        [EditorBrowsable(EditorBrowsableState.Always)]
174        public override Color ForeColor
175        {
176            get
177            {
178                return base.ForeColor;
179            }
180            set
181            {
182                base.ForeColor = value;
183            }
184        }
185
186        /// <summary>
187        /// Gets or sets the color lines and text.
188        /// </summary>
189        /// <value>The color lines and text.</value>
190        [Category("⾃定义")]
191        [Description("获取或设置坐标轴及相关信息⽂本的颜⾊")]
192        [Browsable(true)]
193        [DefaultValue(typeof(Color), "DimGray")]
194        public Color ColorLinesAndText

本文发布于:2024-09-20 23:17:27,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/415826.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:控件   设置   添加
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议