官网

http://www.hzhcontrols.com

前提

入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。

GitHub:https://github.com/kwwwvagaa/NetWinformControl

码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

如果觉得写的还行,请点个 star 支持一下吧

欢迎前来交流探讨: 企鹅群568015492 

麻烦博客下方点个【推荐】,谢谢

NuGet

Install-Package HZH_Controls

目录

https://www.cnblogs.com/bfyx/p/11364884.html

用处及效果

调用示例

  this.ucBarChart1.SetDataSource(new double[] { random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ) });
this.ucBarChart2.SetDataSource(new double[] { random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ) }, new string[] { "张三", "李四", "王五", "赵六", "田七" });
this.ucBarChart3.SetDataSource(new double[] { random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ) }, new string[] { "张三", "李四", "王五", "赵六", "田七" }); this.ucBarChart4.SetDataSource(new double[] { random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ) }, new string[] { "张三", "李四", "王五", "赵六", "田七" });
this.ucBarChart4.AddAuxiliaryLine(, Color.Red, "及格线超长占位符"); this.ucBarChart5.SetDataSource(new double[] { random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ), random.Next(, ) }, new string[] { "张三", "李四", "王五", "赵六", "田七" });
this.ucBarChart5.AddAuxiliaryLine(, Color.Black, "及格线"); var ds = new double[][];
for (int i = ; i < ds.Length; i++)
{
ds[i] = new double[] { random.Next(, ), random.Next(, ), random.Next(, ) };
}
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, "数学") };
this.ucBarChart6.SetDataSource(ds, new string[] { "张三", "李四", "王五", "赵六", "田七" });
this.ucBarChart6.AddAuxiliaryLine(, Color.Black); var ds2 = new List<double[]>();
for (int i = ; i < ; i++)
{
ds2.Add(new double[] { random.Next(, ), random.Next(, ) });
}
var titles = new List<string>();
double dblSum = ds2.Sum(p=>p[]);
for (int i = ; i < ds2.Count; i++)
{
titles.Add("员工" + (i + ) + "\n" + (ds2[i][] / dblSum).ToString("0.0%"));
}
this.ucBarChart7.BarChartItems = new HZH_Controls.Controls.BarChartItem[] { new HZH_Controls.Controls.BarChartItem(Color.Green, "合格"), new HZH_Controls.Controls.BarChartItem(Color.Red, "次品") };
this.ucBarChart7.SetDataSource(ds2.ToArray(), titles.ToArray());
this.ucBarChart7.AddAuxiliaryLine(, Color.Black, "标准线");

准备工作

GDI画图,不懂可以先百度一下

另外用到了(一)c#Winform自定义控件-基类控件 不知道的可以先前往看一下

开始

我们先理一下思路,

我们需要值,x轴,y轴,辅助线,项列表,标题,以及一些颜色等

添加一个类UCBarChart ,继承UCControlBase

添加一些控制属性

 /// <summary>
/// The auxiliary lines
/// </summary>
private List<AuxiliaryLine> auxiliary_lines; /// <summary>
/// The value maximum left
/// </summary>
private int value_max_left = -; /// <summary>
/// The value minimum left
/// </summary>
private int value_min_left = ; /// <summary>
/// The value segment
/// </summary>
private int value_Segment = ; /// <summary>
/// The data values
/// </summary>
private double[][] data_values = null; /// <summary>
/// The data texts
/// </summary>
private string[] data_texts = null; ///// <summary>
///// The data colors
///// </summary>
//private Color[] data_colors = null; /// <summary>
/// The brush deep
/// </summary>
private Brush brush_deep = null; /// <summary>
/// The pen normal
/// </summary>
private Pen pen_normal = null; /// <summary>
/// The pen dash
/// </summary>
private Pen pen_dash = null; /// <summary>
/// The bar back color
/// </summary>
//private Color barBackColor = Color.FromArgb(255, 77, 59); /// <summary>
/// The use gradient
/// </summary>
private bool useGradient = false; /// <summary>
/// The color deep
/// </summary>
private Color color_deep = Color.FromArgb(, , , ); /// <summary>
/// The color dash
/// </summary>
private Color color_dash = Color.FromArgb(, , , ); /// <summary>
/// The format left
/// </summary>
private StringFormat format_left = null; /// <summary>
/// The format right
/// </summary>
private StringFormat format_right = null; /// <summary>
/// The format center
/// </summary>
private StringFormat format_center = null; /// <summary>
/// The value is render dash line
/// </summary>
private bool value_IsRenderDashLine = true; /// <summary>
/// The is show bar value
/// </summary>
private bool isShowBarValue = true; /// <summary>
/// The show bar value format
/// </summary>
private string showBarValueFormat = "{0}"; /// <summary>
/// The value title
/// </summary>
private string value_title = ""; /// <summary>
/// The bar percent width
/// </summary>
private float barPercentWidth = 0.9f; /// <summary>
/// The components
/// </summary>
private IContainer components = null; /// <summary>
/// 获取或设置控件的背景色。
/// </summary>
/// <value>The color of the back.</value>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
[Browsable(true)]
[Description("获取或设置控件的背景色")]
[Category("自定义")]
[DefaultValue(typeof(Color), "Transparent")]
[EditorBrowsable(EditorBrowsableState.Always)]
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
}
} /// <summary>
/// Gets or sets the text.
/// </summary>
/// <value>The text.</value>
[Browsable(true)]
[Description("获取或设置当前控件的文本")]
[Category("自定义")]
[EditorBrowsable(EditorBrowsableState.Always)]
[Bindable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
Invalidate();
}
} /// <summary>
/// 获取或设置控件的前景色。
/// </summary>
/// <value>The color of the fore.</value>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
[Browsable(true)]
[Description("获取或设置控件的前景色")]
[Category("自定义")]
[EditorBrowsable(EditorBrowsableState.Always)]
public override Color ForeColor
{
get
{
return base.ForeColor;
}
set
{
base.ForeColor = value;
}
} /// <summary>
/// Gets or sets the color lines and text.
/// </summary>
/// <value>The color lines and text.</value>
[Category("自定义")]
[Description("获取或设置坐标轴及相关信息文本的颜色")]
[Browsable(true)]
[DefaultValue(typeof(Color), "DimGray")]
public Color ColorLinesAndText
{
get
{
return color_deep;
}
set
{
color_deep = value;
InitializationColor();
Invalidate();
}
} /// <summary>
/// Gets or sets a value indicating whether [use gradient].
/// </summary>
/// <value><c>true</c> if [use gradient]; otherwise, <c>false</c>.</value>
[Category("自定义")]
[Description("获取或设置本条形图控件是否使用渐进色")]
[Browsable(true)]
[DefaultValue(false)]
public bool UseGradient
{
get
{
return useGradient;
}
set
{
useGradient = value;
Invalidate();
}
} /// <summary>
/// Gets or sets the color dash lines.
/// </summary>
/// <value>The color dash lines.</value>
[Category("自定义")]
[Description("获取或设置虚线的颜色")]
[Browsable(true)]
[DefaultValue(typeof(Color), "LightGray")]
public Color ColorDashLines
{
get
{
return color_dash;
}
set
{
color_dash = value;
if (pen_dash != null)
pen_dash.Dispose();
pen_dash = new Pen(color_dash);
Invalidate();
}
} /// <summary>
/// Gets or sets a value indicating whether this instance is render dash line.
/// </summary>
/// <value><c>true</c> if this instance is render dash line; otherwise, <c>false</c>.</value>
[Category("自定义")]
[Description("获取或设置虚线是否进行显示")]
[Browsable(true)]
[DefaultValue(true)]
public bool IsRenderDashLine
{
get
{
return value_IsRenderDashLine;
}
set
{
value_IsRenderDashLine = value;
Invalidate();
}
} /// <summary>
/// Gets or sets the value segment.
/// </summary>
/// <value>The value segment.</value>
[Category("自定义")]
[Description("获取或设置图形的纵轴分段数")]
[Browsable(true)]
[DefaultValue()]
public int ValueSegment
{
get
{
return value_Segment;
}
set
{
value_Segment = value;
Invalidate();
}
} /// <summary>
/// Gets or sets the value maximum left.
/// </summary>
/// <value>The value maximum left.</value>
[Category("自定义")]
[Description("获取或设置图形的左纵坐标的最大值,该值必须大于最小值,该值为负数,最大值即为自动适配。")]
[Browsable(true)]
[DefaultValue(-)]
public int ValueMaxLeft
{
get
{
return value_max_left;
}
set
{
value_max_left = value;
Invalidate();
}
} /// <summary>
/// Gets or sets the value minimum left.
/// </summary>
/// <value>The value minimum left.</value>
[Category("自定义")]
[Description("获取或设置图形的左纵坐标的最小值,该值必须小于最大值")]
[Browsable(true)]
[DefaultValue()]
public int ValueMinLeft
{
get
{
return value_min_left;
}
set
{
if (value < value_max_left)
{
value_min_left = value;
Invalidate();
}
}
} /// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
[Category("自定义")]
[Description("获取或设置图标的标题信息")]
[Browsable(true)]
[DefaultValue("")]
public string Title
{
get
{
return value_title;
}
set
{
value_title = value;
Invalidate();
}
} /// <summary>
/// Gets or sets a value indicating whether this instance is show bar value.
/// </summary>
/// <value><c>true</c> if this instance is show bar value; otherwise, <c>false</c>.</value>
[Category("自定义")]
[Description("获取或设置是否显示柱状图的值文本")]
[Browsable(true)]
[DefaultValue(true)]
public bool IsShowBarValue
{
get
{
return isShowBarValue;
}
set
{
isShowBarValue = value;
Invalidate();
}
} /// <summary>
/// Gets or sets the show bar value format.
/// </summary>
/// <value>The show bar value format.</value>
[Category("自定义")]
[Description("获取或设置柱状图显示值的格式化信息,可以带单位")]
[Browsable(true)]
[DefaultValue("")]
public string ShowBarValueFormat
{
get
{
return showBarValueFormat;
}
set
{
showBarValueFormat = value;
Invalidate();
}
} private BarChartItem[] barChartItems = new BarChartItem[] { new BarChartItem() };
[Category("自定义")]
[Description("获取或设置柱状图的项目")]
[Browsable(true)]
public BarChartItem[] BarChartItems
{
get { return barChartItems; }
set { barChartItems = value; }
}
[Category("自定义")]
[Description("获取或设置是否显示柱状图的项目名称")]
[Browsable(true)]
public bool ShowChartItemName { get; set; }

做一些初始化数据

  public UCBarChart()
{
InitializeComponent();
ConerRadius = ;
ForeColor = Color.FromArgb(, , , );
FillColor = Color.FromArgb(, , );
format_left = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Near
};
format_right = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Far
};
format_center = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
};
auxiliary_lines = new List<AuxiliaryLine>();
pen_dash = new Pen(color_dash);
pen_dash.DashStyle = DashStyle.Custom;
pen_dash.DashPattern = new float[]
{
5f,
5f
};
InitializationColor();
SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); if (DesignMode)
{
barChartItems = new BarChartItem[] { new BarChartItem() }; data_values = new double[][];
for (int i = ; i < data_values.Length; i++)
{
data_values[i] = new double[] { i + };
}
} }

设置数据源的函数

 /// <summary>
/// Sets the data source.
/// </summary>
/// <param name="data">The data.</param>
public void SetDataSource(double[] data)
{
SetDataSource(data, null);
} public void SetDataSource(double[][] data)
{
SetDataSource(data, null);
}
/// <summary>
/// Sets the data source.
/// </summary>
/// <param name="data">The data.</param>
/// <param name="texts">X texts</param>
public void SetDataSource(double[] data, string[] texts)
{
data_values = new double[data.Length][];
for (int i = ; i < data.Length; i++)
{
data_values[i] = new double[] { data[i] };
}
if (barChartItems == null || barChartItems.Length <= )
barChartItems = new BarChartItem[] { new BarChartItem() };
data_texts = texts;
Invalidate();
}
public void SetDataSource(double[][] data, string[] texts)
{
data_values = data;
if (barChartItems == null || barChartItems.Length <= )
barChartItems = new BarChartItem[] { new BarChartItem() };
data_texts = texts;
Invalidate();
}

重绘

 protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics graphics = e.Graphics;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
PaintMain(graphics, base.Width, base.Height);
} /// <summary>
/// Paints the main.
/// </summary>
/// <param name="g">The g.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
private void PaintMain(Graphics g, int width, int height)
{
if (barChartItems == null || barChartItems.Length <= )
{
if (DesignMode)
{
barChartItems = new BarChartItem[] { new BarChartItem() };
}
else
{
return;
}
}
if (data_values == null && DesignMode)
{
data_values = new double[][];
for (int i = ; i < data_values.Length; i++)
{
data_values[i] = new double[] { i + };
}
} double num = (data_values != null && data_values.Length != ) ? ChartsHelper.CalculateMaxSectionFrom(data_values) : ;
if (value_max_left > )
{
num = value_max_left;
}
int intLeftX = (int)g.MeasureString(num.ToString(), Font).Width + ;
if (intLeftX < )
{
intLeftX = ;
}
//处理辅助线左侧间距
if (auxiliary_lines != null && auxiliary_lines.Count > )
{
var maxAuxiliaryWidth = auxiliary_lines.Max(p => g.MeasureString((p.Tip + "" + p.Value), Font).Width);
if (intLeftX < maxAuxiliaryWidth)
{
intLeftX = (int)maxAuxiliaryWidth + ;
}
}
int intRightX = ;
//顶部距离
int intTopY = ;
if (!string.IsNullOrEmpty(value_title))
{
intTopY += ;
}
//写标题
if (!string.IsNullOrEmpty(value_title))
{
g.DrawString(value_title, Font, brush_deep, new Rectangle(, , width - , intTopY - ), format_center);
}
//画项目名称颜色
if (ShowChartItemName && !(barChartItems.Length == && string.IsNullOrEmpty(barChartItems[].ItemName)))
{
int intItemNameRowCount = ;
int intItemNameWidth = ;
int intItemNameComCount = ; intItemNameWidth = (int)barChartItems.Max(p => g.MeasureString(p.ItemName, Font).Width) + ;
intItemNameComCount = this.Width / intItemNameWidth;
intItemNameRowCount = barChartItems.Length / intItemNameComCount + (barChartItems.Length % intItemNameComCount != ? : );
int intItemNameHeight = (int)g.MeasureString("A", Font).Height; for (int i = ; i < intItemNameRowCount; i++)
{
int intLeft = (this.Width - (intItemNameWidth * ((i == intItemNameRowCount - ) ? (barChartItems.Length % intItemNameComCount) : intItemNameComCount))) / ;
int intTop = intTopY - + intItemNameHeight * i + ;
for (int j = i * intItemNameComCount; j < barChartItems.Length && j < (i + ) * intItemNameComCount; j++)
{
Rectangle rectColor = new Rectangle(intLeft + (j % intItemNameComCount) * intItemNameWidth, intTop, , intItemNameHeight);
g.FillRectangle(new SolidBrush(barChartItems[j].BarBackColor), rectColor);
g.DrawString(barChartItems[j].ItemName, Font, new SolidBrush(ForeColor), new Point(rectColor.Right + , rectColor.Top));
}
}
intTopY += intItemNameRowCount * (intItemNameHeight + );
} int intBottomY = ;
//处理x坐标文字高度
if (data_texts != null && data_texts.Length > )
{
var maxTextsHeight = data_texts.Max(p => g.MeasureString(p, Font).Height);
if (intBottomY < maxTextsHeight)
intBottomY = (int)maxTextsHeight + ;
}
//画xy轴
Point[] array2 = new Point[]
{
new Point(intLeftX, intTopY - ),
new Point(intLeftX, height - intBottomY),
new Point(width - intRightX+, height - intBottomY)
};
g.DrawLine(pen_normal, array2[], array2[]);
g.DrawLine(pen_normal, array2[], array2[]);
ChartsHelper.PaintTriangle(g, brush_deep, new Point(intLeftX, intTopY - ), , GraphDirection.Upward);
ChartsHelper.PaintTriangle(g, brush_deep, new Point(width - intRightX + , height - intBottomY), , GraphDirection.Rightward); //画横向分割线
for (int j = ; j <= value_Segment; j++)
{
float value = (float)((double)j * (double)(num - value_min_left) / (double)value_Segment + (double)value_min_left);
float num6 = ChartsHelper.ComputePaintLocationY((float)num, value_min_left, height - intTopY - intBottomY, value) + (float)intTopY;
if (IsNeedPaintDash(num6))
{
g.DrawLine(pen_normal, intLeftX - , num6, intLeftX - , num6);
g.DrawString(layoutRectangle: new RectangleF(0f, num6 - 19f, intLeftX - , 40f), s: value.ToString(), font: Font, brush: brush_deep, format: format_right);
if (j > && value_IsRenderDashLine)
{
g.DrawLine(pen_dash, intLeftX, num6, width - intRightX, num6);
}
}
}
//计算辅助线y坐标
for (int i = ; i < auxiliary_lines.Count; i++)
{
auxiliary_lines[i].PaintValue = ChartsHelper.ComputePaintLocationY((float)num, value_min_left, height - intTopY - intBottomY, auxiliary_lines[i].Value) + (float)intTopY;
} //画辅助线
for (int k = ; k < auxiliary_lines.Count; k++)
{
g.DrawLine(auxiliary_lines[k].GetPen(), intLeftX - , auxiliary_lines[k].PaintValue, intLeftX - , auxiliary_lines[k].PaintValue);
g.DrawString(layoutRectangle: new RectangleF(0f, auxiliary_lines[k].PaintValue - 9f, intLeftX - , 20f), s: auxiliary_lines[k].Tip + "" + auxiliary_lines[k].Value.ToString(), font: Font, brush: auxiliary_lines[k].LineTextBrush, format: format_right);
g.DrawLine(auxiliary_lines[k].GetPen(), intLeftX, auxiliary_lines[k].PaintValue, width - intRightX, auxiliary_lines[k].PaintValue);
}
if (data_values == null || data_values.Length == || data_values.Max(p => p.Length) <= )
{
return;
} //x轴分隔宽度
float fltSplitWidth = (float)(width - intLeftX - - intRightX) * 1f / (float)data_values.Length;
for (int i = ; i < data_values.Length; i++)
{
int intItemSplitCount = barChartItems.Length;
float _fltSplitWidth = fltSplitWidth * barPercentWidth / intItemSplitCount;
float _fltLeft = (float)i * fltSplitWidth + (1f - barPercentWidth) / 2f * fltSplitWidth + (float)intLeftX;
for (int j = ; j < data_values[i].Length; j++)
{
if (j >= intItemSplitCount)
{
break;
}
float fltValueY = ChartsHelper.ComputePaintLocationY((float)num, value_min_left, height - intTopY - intBottomY, (float)data_values[i][j]) + (float)intTopY; RectangleF rect = new RectangleF(_fltLeft + _fltSplitWidth * j + (1F - barChartItems[j].BarPercentWidth) * _fltSplitWidth / 2f, fltValueY,
_fltSplitWidth * barChartItems[j].BarPercentWidth, (float)(height - intBottomY) - fltValueY); Color color = barChartItems[j].BarBackColor; //画柱状
if (useGradient)
{
if (rect.Height > 0f)
{
using (LinearGradientBrush brush = new LinearGradientBrush(new PointF(rect.X, rect.Y + rect.Height), new PointF(rect.X, rect.Y), ChartsHelper.GetColorLight(color), color))
{
g.FillRectangle(brush, rect);
}
}
}
else
{
using (Brush brush2 = new SolidBrush(color))
{
g.FillRectangle(brush2, rect);
}
}
//写值文字
if (isShowBarValue)
{
using (Brush brush3 = new SolidBrush(ForeColor))
{
g.DrawString(layoutRectangle: new RectangleF(rect.Left - 50f, fltValueY - (float)Font.Height - 2f, _fltSplitWidth + 100f, Font.Height + ), s: string.Format(showBarValueFormat, data_values[i][j]), font: Font, brush: brush3, format: format_center);
}
}
} //写x轴文字
if (data_texts != null && i < data_texts.Length)
{
g.DrawString(layoutRectangle: new RectangleF((float)i * fltSplitWidth + (float)intLeftX - 50f, height - intBottomY - , fltSplitWidth + 100f, intBottomY + ), s: data_texts[i], font: Font, brush: brush_deep, format: format_center);
}
}
}

辅助线相关函数

 #region 辅助线    English:Guide
/// <summary>
/// Adds the left auxiliary.
/// </summary>
/// <param name="value">The value.</param>
public void AddAuxiliaryLine(float value, string strTip = "")
{
AddAuxiliaryLine(value, ColorLinesAndText, strTip);
} /// <summary>
/// Adds the left auxiliary.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="lineColor">Color of the line.</param>
public void AddAuxiliaryLine(float value, Color lineColor, string strTip = "")
{
AddAuxiliaryLine(value, lineColor, 1f, true, strTip);
} /// <summary>
/// Adds the left auxiliary.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="lineColor">Color of the line.</param>
/// <param name="lineThickness">The line thickness.</param>
/// <param name="isDashLine">if set to <c>true</c> [is dash line].</param>
public void AddAuxiliaryLine(float value, Color lineColor, float lineThickness, bool isDashLine, string strTip = "")
{
AddAuxiliary(value, lineColor, lineThickness, isDashLine, strTip);
} /// <summary>
/// Adds the auxiliary.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="lineColor">Color of the line.</param>
/// <param name="lineThickness">The line thickness.</param>
/// <param name="isDashLine">if set to <c>true</c> [is dash line].</param>
/// <param name="isLeft">if set to <c>true</c> [is left].</param>
private void AddAuxiliary(float value, Color lineColor, float lineThickness, bool isDashLine, string strTip = "")
{
auxiliary_lines.Add(new AuxiliaryLine
{
Value = value,
LineColor = lineColor,
PenDash = new Pen(lineColor)
{
DashStyle = DashStyle.Custom,
DashPattern = new float[]
{
5f,
5f
}
},
PenSolid = new Pen(lineColor),
IsDashStyle = isDashLine,
LineThickness = lineThickness,
LineTextBrush = new SolidBrush(lineColor),
Tip = strTip
});
Invalidate();
} /// <summary>
/// Removes the auxiliary.
/// </summary>
/// <param name="value">The value.</param>
public void RemoveAuxiliary(float value)
{
int num = ;
for (int num2 = auxiliary_lines.Count - ; num2 >= ; num2--)
{
if (auxiliary_lines[num2].Value == value)
{
auxiliary_lines[num2].Dispose();
auxiliary_lines.RemoveAt(num2);
num++;
}
}
if (num > )
{
Invalidate();
}
} /// <summary>
/// Removes all auxiliary.
/// </summary>
public void RemoveAllAuxiliary()
{
int count = auxiliary_lines.Count;
auxiliary_lines.Clear();
if (count > )
{
Invalidate();
}
}
#endregion

完整代码,请前往开源地址查看吧。

最后的话

如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧

(六十七)c#Winform自定义控件-柱状图的更多相关文章

  1. (二十六)c#Winform自定义控件-有确定取消的窗体(二)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  2. (八十六)c#Winform自定义控件-表格优化

    出处:http://www.hzhcontrols.com/原文:http://www.hzhcontrols.com/blog-149.html本文版权归www.hzhcontrols.com所有欢 ...

  3. (四十六)c#Winform自定义控件-水波进度条-HZHControls

    官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...

  4. (十六)c#Winform自定义控件-文本框哪里去了?-HZHControls

    官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...

  5. (六)c#Winform自定义控件-单选框

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  6. (七十六)c#Winform自定义控件-表单验证组件

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  7. (三十六)c#Winform自定义控件-步骤控件-HZHControls

    官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...

  8. (五十六)c#Winform自定义控件-瓶子(工业)-HZHControls

    官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...

  9. winform 自定义控件(高手)

    高手推荐:https://www.cnblogs.com/bfyx/p/11364884.html   c#Winform自定义控件-目录   前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件 ...

随机推荐

  1. mongoDB的CRUD的总结

    今天开始接触非关系型数据库的mongoDB,现在将自己做的笔记发出来,供大家参考,也便于自己以后忘记了可以查看. 首先,mongoDB,是一种数据库,但是又区别与mysql,sqlserver.orc ...

  2. redhat linux 5.3安装activeMQ

    安装环境:linux redhat enterprise 5.3 activemq版本:5.9.01.从http://activemq.apache.org/download.html地址下载apac ...

  3. golang timeoutHandler解析及kubernetes中的变种

    Golang里的http request timeout比较简单,但是稍不留心就容易出现错误,最近在kubernetes生产环境中出现了的一个问题让我有机会好好捋一捋golang中关于timeout中 ...

  4. JS 一些有意思的写法

    对于 C语言中的 &&(有一个为假,返回的为false) 和 || (有一个为真,即为真),但是对于 JS中的 && 和 || 运算是有所不同的. 详情见下面: &am ...

  5. 关于selenium自动化对iframe内嵌元素的处理

    今天上班闲来无聊,于是来练练自动化,结果碰上了可恶的iframe,楼主,以前也遇到过,但是一直也没搞懂怎么处理的,都是抄别人的代码,今天决定独立解决试试.首先先来认识什么是iframe,它就长下图这样 ...

  6. Top11 构建和测试API的工具

    立刻像专业人士一样构建API 组织正在改变他们已经在软件应用项目中成功的微服务架构模型,这就是大多数微服务项目使用API(应用程序接口)的原因. 我们要为微服务喝彩,因为它相对于其他的模型有各种先进的 ...

  7. deepin 15.11 安装 pyenv

    GitHub:官方环境:https://github.com/pyenv/pyenv/wiki/Common-build-problems GitHub:官方文档:https://github.com ...

  8. 随笔编号-07 JS针对时间操作

    //获取完整的当前日期 var date=new Date; var year=date.getFullYear(); var month=date.getMonth()+1; month =(mon ...

  9. MySQL数据库之单表查询中关键字的执行顺序

    目录 MySQL数据库之单表查询中关键字的执行顺序 1 语法顺序 2 执行顺序 3 关键字使用语法 MySQL数据库之单表查询中关键字的执行顺序 1 语法顺序 select distinct from ...

  10. Delphi - 获取文件大小

    GetFileSize获取文件大小 封装成如下函数,可以直接使用: ///函数功能:获取文件大小,单位取KB,小数自动进位 ///参数:sFilePath文件全路径 ///Result: 成功是返回文 ...