1、优化LOG显示与引用

2、添加PMA工具,工具内容待完善
3、修复流程树显示
4、添加开源项目,优化UI空间
5、其他BUG更改
This commit is contained in:
liu.wenjie
2021-11-23 15:51:37 +08:00
parent 47f77f5e64
commit a24dda2525
474 changed files with 91916 additions and 6429 deletions

View File

@@ -0,0 +1,38 @@
using System.Drawing;
namespace HZH_Controls.Controls
{
public class AuxiliaryLable
{
public string Text
{
get;
set;
}
public Brush TextBrush
{
get;
set;
}
public Brush TextBack
{
get;
set;
}
public float LocationX
{
get;
set;
}
public AuxiliaryLable()
{
TextBrush = Brushes.Black;
TextBack = Brushes.Transparent;
LocationX = 0.5f;
}
}
}

View File

@@ -0,0 +1,122 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-17
//
// ***********************************************************************
// <copyright file="AuxiliaryLine.cs">
// Copyright by Huang Zhenghui(»ÆÕý»Ô) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub£ºhttps://github.com/kwwwvagaa/NetWinformControl
// gitee£ºhttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Drawing;
namespace HZH_Controls.Controls
{
/// <summary>
/// Class AuxiliaryLine.
/// Implements the <see cref="System.IDisposable" />
/// </summary>
/// <seealso cref="System.IDisposable" />
internal class AuxiliaryLine : IDisposable
{
private bool disposedValue = false;
public float Value
{
get;
set;
}
public float PaintValue
{
get;
set;
}
public float PaintValueBackUp
{
get;
set;
}
public Color LineColor
{
get;
set;
}
public Pen PenDash
{
get;
set;
}
public Pen PenSolid
{
get;
set;
}
public float LineThickness
{
get;
set;
}
public Brush LineTextBrush
{
get;
set;
}
public bool IsLeftFrame
{
get;
set;
}
private bool isDashStyle = true;
public bool IsDashStyle
{
get { return isDashStyle; }
set { isDashStyle = value; }
}
public Pen GetPen()
{
return IsDashStyle ? PenDash : PenSolid;
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
if(PenDash==null)
PenDash.Dispose();
if(PenSolid==null)
PenSolid.Dispose();
if(LineTextBrush==null)
LineTextBrush.Dispose();
}
disposedValue = true;
}
}
public string Tip { get; set; }
public void Dispose()
{
Dispose(true);
}
}
}

View File

@@ -0,0 +1,41 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-26
//
// ***********************************************************************
// <copyright file="FunelChartAlignment.cs">
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHubhttps://github.com/kwwwvagaa/NetWinformControl
// giteehttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HZH_Controls.Controls
{
/// <summary>
/// Enum FunelChartAlignment
/// </summary>
public enum FunelChartAlignment
{
/// <summary>
/// The left
/// </summary>
Left,
/// <summary>
/// The center
/// </summary>
Center,
/// <summary>
/// The right
/// </summary>
Right
}
}

View File

@@ -0,0 +1,37 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-26
//
// ***********************************************************************
// <copyright file="FunelChartDirection.cs">
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHubhttps://github.com/kwwwvagaa/NetWinformControl
// giteehttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HZH_Controls.Controls
{
/// <summary>
/// Enum FunelChartDirection
/// </summary>
public enum FunelChartDirection
{
/// <summary>
/// Up
/// </summary>
UP,
/// <summary>
/// Down
/// </summary>
Down
}
}

View File

@@ -0,0 +1,49 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-26
//
// ***********************************************************************
// <copyright file="FunelChartItem.cs">
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHubhttps://github.com/kwwwvagaa/NetWinformControl
// giteehttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HZH_Controls.Controls
{
/// <summary>
/// Class FunelChartItem.
/// </summary>
public class FunelChartItem
{
/// <summary>
/// Gets or sets the text.
/// </summary>
/// <value>The text.</value>
public string Text { get; set; }
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>The value.</value>
public float Value { get; set; }
/// <summary>
/// Gets or sets the color of the value.
/// </summary>
/// <value>The color of the value.</value>
public System.Drawing.Color? ValueColor { get; set; }
/// <summary>
/// Gets or sets the color of the text fore.
/// </summary>
/// <value>The color of the text fore.</value>
public System.Drawing.Color? TextForeColor { get; set; }
}
}

View File

@@ -0,0 +1,506 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-26
//
// ***********************************************************************
// <copyright file="UCFunnelChart.cs">
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHubhttps://github.com/kwwwvagaa/NetWinformControl
// giteehttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace HZH_Controls.Controls
{
/// <summary>
/// Class UCFunnelChart.
/// Implements the <see cref="System.Windows.Forms.UserControl" />
/// </summary>
/// <seealso cref="System.Windows.Forms.UserControl" />
public class UCFunnelChart : UserControl
{
/// <summary>
/// The title
/// </summary>
private string title;
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置标题")]
public string Title
{
get { return title; }
set
{
title = value;
ResetTitleSize();
Invalidate();
}
}
/// <summary>
/// The title font
/// </summary>
private Font titleFont = new Font("微软雅黑", 12);
/// <summary>
/// Gets or sets the title font.
/// </summary>
/// <value>The title font.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置标题字体")]
public Font TitleFont
{
get { return titleFont; }
set
{
titleFont = value;
ResetTitleSize();
Invalidate();
}
}
/// <summary>
/// The title fore color
/// </summary>
private Color titleForeColor = Color.Black;
/// <summary>
/// Gets or sets the color of the title fore.
/// </summary>
/// <value>The color of the title fore.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置标题文字颜色")]
public Color TitleForeColor
{
get { return titleForeColor; }
set
{
titleForeColor = value;
Invalidate();
}
}
/// <summary>
/// The items
/// </summary>
private FunelChartItem[] items;
/// <summary>
/// Gets or sets the items.
/// </summary>
/// <value>The items.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置项目")]
public FunelChartItem[] Items
{
get { return items; }
set
{
items = value;
Invalidate();
}
}
/// <summary>
/// The direction
/// </summary>
private FunelChartDirection direction = FunelChartDirection.UP;
/// <summary>
/// Gets or sets the direction.
/// </summary>
/// <value>The direction.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置方向")]
public FunelChartDirection Direction
{
get { return direction; }
set
{
direction = value;
Invalidate();
}
}
/// <summary>
/// The alignment
/// </summary>
private FunelChartAlignment alignment = FunelChartAlignment.Center;
/// <summary>
/// Gets or sets the alignment.
/// </summary>
/// <value>The alignment.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置对齐方式")]
public FunelChartAlignment Alignment
{
get { return alignment; }
set
{
alignment = value;
Invalidate();
}
}
/// <summary>
/// The item text align
/// </summary>
private FunelChartAlignment itemTextAlign = FunelChartAlignment.Center;
/// <summary>
/// Gets or sets the item text align.
/// </summary>
/// <value>The item text align.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置文字位置")]
public FunelChartAlignment ItemTextAlign
{
get { return itemTextAlign; }
set
{
itemTextAlign = value;
ResetWorkingRect();
Invalidate();
}
}
/// <summary>
/// The show value
/// </summary>
private bool showValue = false;
/// <summary>
/// Gets or sets a value indicating whether [show value].
/// </summary>
/// <value><c>true</c> if [show value]; otherwise, <c>false</c>.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置是否显示值")]
public bool ShowValue
{
get { return showValue; }
set
{
showValue = value;
Invalidate();
}
}
/// <summary>
/// The value format
/// </summary>
private string valueFormat = "0.##";
/// <summary>
/// Gets or sets the value format.
/// </summary>
/// <value>The value format.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置值格式化")]
public string ValueFormat
{
get { return valueFormat; }
set
{
valueFormat = value;
Invalidate();
}
}
/// <summary>
/// The m rect working
/// </summary>
RectangleF m_rectWorking;
/// <summary>
/// The m title size
/// </summary>
SizeF m_titleSize = SizeF.Empty;
/// <summary>
/// The int split width
/// </summary>
int intSplitWidth = 1;
/// <summary>
/// Initializes a new instance of the <see cref="UCFunnelChart"/> class.
/// </summary>
public UCFunnelChart()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.Selectable, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.FontChanged += UCFunnelChart_FontChanged;
Font = new Font("微软雅黑", 8);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.SizeChanged += UCFunnelChart_SizeChanged;
Size = new System.Drawing.Size(150, 150);
items = new FunelChartItem[0];
if (ControlHelper.IsDesignMode())
{
items = new FunelChartItem[5];
for (int i = 0; i < 5; i++)
{
items[i] = new FunelChartItem()
{
Text = "item" + i,
Value = 10 * (i + 1)
};
}
}
}
/// <summary>
/// Handles the FontChanged event of the UCFunnelChart control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
void UCFunnelChart_FontChanged(object sender, EventArgs e)
{
ResetWorkingRect();
}
/// <summary>
/// Handles the SizeChanged event of the UCFunnelChart control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
void UCFunnelChart_SizeChanged(object sender, EventArgs e)
{
ResetWorkingRect();
}
/// <summary>
/// Resets the working rect.
/// </summary>
private void ResetWorkingRect()
{
if (itemTextAlign == FunelChartAlignment.Center)
{
m_rectWorking = new RectangleF(0, m_titleSize.Height == 0 ? 0 : (m_titleSize.Height + 10), this.Width, this.Height - (m_titleSize.Height == 0 ? 0 : (m_titleSize.Height + 10)));
}
else if (itemTextAlign == FunelChartAlignment.Left)
{
float fltMax = 0;
if (items != null && items.Length > 0)
{
using (Graphics g = this.CreateGraphics())
{
fltMax = items.Max(p => g.MeasureString(p.Text, Font).Width);
}
}
m_rectWorking = new RectangleF(fltMax, m_titleSize.Height == 0 ? 0 : (m_titleSize.Height + 10), this.Width - fltMax, this.Height - (m_titleSize.Height == 0 ? 0 : (m_titleSize.Height + 10)));
}
else
{
float fltMax = 0;
if (items != null && items.Length > 0)
{
using (Graphics g = this.CreateGraphics())
{
fltMax = items.Max(p => g.MeasureString(p.Text, Font).Width);
}
}
m_rectWorking = new RectangleF(0, m_titleSize.Height == 0 ? 0 : (m_titleSize.Height + 10), this.Width - fltMax, this.Height - (m_titleSize.Height == 0 ? 0 : (m_titleSize.Height + 10)));
}
}
/// <summary>
/// Resets the size of the title.
/// </summary>
private void ResetTitleSize()
{
if (string.IsNullOrEmpty(title))
{
m_titleSize = SizeF.Empty;
}
else
{
using (Graphics g = this.CreateGraphics())
{
m_titleSize = g.MeasureString(title, titleFont);
m_titleSize.Height += 20;
}
}
ResetWorkingRect();
}
/// <summary>
/// 引发 <see cref="E:System.Windows.Forms.Control.Paint" /> 事件。
/// </summary>
/// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" />。</param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var g = e.Graphics;
g.SetGDIHigh();
if (!string.IsNullOrEmpty(title))
{
g.DrawString(title, titleFont, new SolidBrush(titleForeColor), new RectangleF(0, 0, this.Width, m_titleSize.Height), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
}
if (items == null || items.Length <= 0)
{
g.DrawString("没有数据", Font, new SolidBrush(Color.Black), this.m_rectWorking, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
return;
}
List<FunelChartItem> lstItems;
if (direction == FunelChartDirection.UP)
{
lstItems = items.OrderBy(p => p.Value).ToList();
}
else
{
lstItems = items.OrderByDescending(p => p.Value).ToList();
}
List<RectangleF> lstRects = new List<RectangleF>();
List<GraphicsPath> lstPaths = new List<GraphicsPath>();
float maxValue = lstItems.Max(p => p.Value);
float dblSplitHeight = m_rectWorking.Height / lstItems.Count;
for (int i = 0; i < lstItems.Count; i++)
{
FunelChartItem item = lstItems[i];
if (item.ValueColor == null || item.ValueColor == Color.Empty || item.ValueColor == Color.Transparent)
item.ValueColor = ControlHelper.Colors[i];
switch (alignment)
{
case FunelChartAlignment.Left:
lstRects.Add(new RectangleF(m_rectWorking.Left, m_rectWorking.Top + dblSplitHeight * i, item.Value / maxValue * m_rectWorking.Width, dblSplitHeight));
break;
case FunelChartAlignment.Center:
lstRects.Add(new RectangleF(m_rectWorking.Left + (m_rectWorking.Width - (item.Value / maxValue * m_rectWorking.Width)) / 2, m_rectWorking.Top + dblSplitHeight * i, item.Value / maxValue * m_rectWorking.Width, dblSplitHeight));
break;
case FunelChartAlignment.Right:
lstRects.Add(new RectangleF(m_rectWorking.Right - (item.Value / maxValue * m_rectWorking.Width), m_rectWorking.Top + dblSplitHeight * i, item.Value / maxValue * m_rectWorking.Width, dblSplitHeight));
break;
}
}
for (int i = 0; i < lstRects.Count; i++)
{
var rect = lstRects[i];
GraphicsPath path = new GraphicsPath();
List<PointF> lstPoints = new List<PointF>();
if (direction == FunelChartDirection.UP)
{
switch (alignment)
{
case FunelChartAlignment.Left:
lstPoints.Add(new PointF(rect.Left, rect.Top));
if (i != 0)
{
lstPoints.Add(new PointF(lstRects[i - 1].Right, rect.Top));
}
break;
case FunelChartAlignment.Center:
if (i == 0)
{
lstPoints.Add(new PointF(rect.Left + rect.Width / 2, rect.Top));
}
else
{
lstPoints.Add(new PointF(lstRects[i - 1].Left, rect.Top));
lstPoints.Add(new PointF(lstRects[i - 1].Right, rect.Top));
}
break;
case FunelChartAlignment.Right:
if (i == 0)
{
lstPoints.Add(new PointF(rect.Right, rect.Top));
}
else
{
lstPoints.Add(new PointF(rect.Right - lstRects[i - 1].Width, rect.Top));
lstPoints.Add(new PointF(rect.Right, rect.Top));
}
break;
}
lstPoints.Add(new PointF(rect.Right, rect.Bottom - intSplitWidth));
lstPoints.Add(new PointF(rect.Left, rect.Bottom - intSplitWidth));
}
else
{
lstPoints.Add(new PointF(rect.Left, rect.Top + intSplitWidth));
lstPoints.Add(new PointF(rect.Right, rect.Top + intSplitWidth));
switch (alignment)
{
case FunelChartAlignment.Left:
if (i == lstRects.Count - 1)
{
lstPoints.Add(new PointF(rect.Left, rect.Bottom));
}
else
{
lstPoints.Add(new PointF(lstRects[i + 1].Right, rect.Bottom));
lstPoints.Add(new PointF(rect.Left, rect.Bottom));
}
break;
case FunelChartAlignment.Center:
if (i == lstRects.Count - 1)
{
lstPoints.Add(new PointF(rect.Left + rect.Width / 2, rect.Bottom));
}
else
{
lstPoints.Add(new PointF(lstRects[i + 1].Right, rect.Bottom));
lstPoints.Add(new PointF(lstRects[i + 1].Left, rect.Bottom));
}
break;
case FunelChartAlignment.Right:
if (i == lstRects.Count - 1)
{
lstPoints.Add(new PointF(rect.Right, rect.Bottom));
}
else
{
lstPoints.Add(new PointF(rect.Right, rect.Bottom));
lstPoints.Add(new PointF(lstRects[i + 1].Left, rect.Bottom));
}
break;
}
}
path.AddLines(lstPoints.ToArray());
path.CloseAllFigures();
// g.DrawPath(new Pen(new SolidBrush(lstItems[i].ValueColor.Value)), path);
g.FillPath(new SolidBrush(lstItems[i].ValueColor.Value), path);
//写字
if (itemTextAlign == FunelChartAlignment.Center)
{
g.DrawString(lstItems[i].Text + (ShowValue ? lstItems[i].Value.ToString("\n" + valueFormat) : ""), Font, new SolidBrush((lstItems[i].TextForeColor == null || lstItems[i].TextForeColor == Color.Empty || lstItems[i].TextForeColor == Color.Transparent) ? Color.White : lstItems[i].TextForeColor.Value), rect, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
}
else if (itemTextAlign == FunelChartAlignment.Left)
{
g.DrawString(lstItems[i].Text + (ShowValue ? lstItems[i].Value.ToString("\n" + valueFormat) : ""), Font, new SolidBrush((lstItems[i].TextForeColor == null || lstItems[i].TextForeColor == Color.Empty || lstItems[i].TextForeColor == Color.Transparent) ? lstItems[i].ValueColor.Value : lstItems[i].TextForeColor.Value), new RectangleF(0, rect.Top, rect.Left, rect.Height), new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center });
g.DrawLine(new Pen(new SolidBrush((lstItems[i].TextForeColor == null || lstItems[i].TextForeColor == Color.Empty || lstItems[i].TextForeColor == Color.Transparent) ? lstItems[i].ValueColor.Value : lstItems[i].TextForeColor.Value)), rect.Left, rect.Top + rect.Height / 2, rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);
}
else
{
g.DrawString(lstItems[i].Text + (ShowValue ? lstItems[i].Value.ToString("\n" + valueFormat) : ""), Font, new SolidBrush((lstItems[i].TextForeColor == null || lstItems[i].TextForeColor == Color.Empty || lstItems[i].TextForeColor == Color.Transparent) ? lstItems[i].ValueColor.Value : lstItems[i].TextForeColor.Value), new RectangleF(rect.Right, rect.Top, this.Width - rect.Right, rect.Height), new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center });
g.DrawLine(new Pen(new SolidBrush((lstItems[i].TextForeColor == null || lstItems[i].TextForeColor == Color.Empty || lstItems[i].TextForeColor == Color.Transparent) ? lstItems[i].ValueColor.Value : lstItems[i].TextForeColor.Value)), rect.Left + rect.Width / 2, rect.Top + rect.Height / 2, rect.Right, rect.Top + rect.Height / 2);
}
}
}
}
}

View File

@@ -0,0 +1,113 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-23
//
// ***********************************************************************
// <copyright file="MarkText.cs">
// Copyright by Huang Zhenghui(»ÆÕý»Ô) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub£ºhttps://github.com/kwwwvagaa/NetWinformControl
// gitee£ºhttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System.Drawing;
namespace HZH_Controls.Controls
{
/// <summary>
/// Class MarkText.
/// </summary>
public class MarkText
{
/// <summary>
/// The mark text offect
/// </summary>
public static readonly int MarkTextOffect = 5;
/// <summary>
/// Gets or sets the curve key.
/// </summary>
/// <value>The curve key.</value>
public string CurveKey
{
get;
set;
}
/// <summary>
/// Gets or sets the index.
/// </summary>
/// <value>The index.</value>
public int Index
{
get;
set;
}
/// <summary>
/// Gets or sets the mark text.
/// </summary>
/// <value>The mark text.</value>
public string Text
{
get;
set;
}
private Color? textColor = null;
public Color? TextColor
{
get { return textColor; }
set { textColor = value; }
}
/// <summary>
/// The position style
/// </summary>
private MarkTextPositionStyle positionStyle = MarkTextPositionStyle.Auto;
/// <summary>
/// Gets or sets the position style.
/// </summary>
/// <value>The position style.</value>
public MarkTextPositionStyle PositionStyle
{
get { return positionStyle; }
set { positionStyle = value; }
}
/// <summary>
/// Calculates the index of the direction from data.
/// </summary>
/// <param name="data">The data.</param>
/// <param name="Index">The index.</param>
/// <returns>MarkTextPositionStyle.</returns>
public static MarkTextPositionStyle CalculateDirectionFromDataIndex(float[] data, int Index)
{
float num = (Index == 0) ? data[Index] : data[Index - 1];
float num2 = (Index == data.Length - 1) ? data[Index] : data[Index + 1];
if (num < data[Index] && data[Index] < num2)
{
return MarkTextPositionStyle.Left;
}
if (num > data[Index] && data[Index] > num2)
{
return MarkTextPositionStyle.Right;
}
if (num <= data[Index] && data[Index] >= num2)
{
return MarkTextPositionStyle.Up;
}
if (num >= data[Index] && data[Index] <= num2)
{
return MarkTextPositionStyle.Down;
}
return MarkTextPositionStyle.Up;
}
}
}

View File

@@ -0,0 +1,11 @@
namespace HZH_Controls.Controls
{
public enum MarkTextPositionStyle
{
Up = 1,
Right = 2,
Down = 4,
Left = 8,
Auto = 16
}
}

View File

@@ -0,0 +1,55 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-25
//
// ***********************************************************************
// <copyright file="RadarLine.cs">
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHubhttps://github.com/kwwwvagaa/NetWinformControl
// giteehttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace HZH_Controls.Controls
{
/// <summary>
/// Class RadarLine.
/// </summary>
public class RadarLine
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the values.
/// </summary>
/// <value>The values.</value>
public double[] Values { get; set; }
/// <summary>
/// Gets or sets the color of the line.
/// </summary>
/// <value>The color of the line.</value>
public Color? LineColor { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [show value text].
/// </summary>
/// <value><c>true</c> if [show value text]; otherwise, <c>false</c>.</value>
public bool ShowValueText { get; set; }
/// <summary>
/// Gets or sets the color of the fill.
/// </summary>
/// <value>The color of the fill.</value>
public Color? FillColor { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HZH_Controls.Controls
{
public class RadarPosition
{
public string Text { get; set; }
public double MaxValue { get; set; }
}
}

View File

@@ -0,0 +1,663 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-25
//
// ***********************************************************************
// <copyright file="UCRadarChart.cs">
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHubhttps://github.com/kwwwvagaa/NetWinformControl
// giteehttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace HZH_Controls.Controls
{
/// <summary>
/// Class UCRadarChart.
/// Implements the <see cref="System.Windows.Forms.UserControl" />
/// </summary>
/// <seealso cref="System.Windows.Forms.UserControl" />
public class UCRadarChart : UserControl
{
/// <summary>
/// The split count
/// </summary>
private int splitCount = 5;
/// <summary>
/// Gets or sets the split count.
/// </summary>
/// <value>The split count.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置分隔份数")]
public int SplitCount
{
get { return splitCount; }
set
{
splitCount = value;
Invalidate();
}
}
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置是否使用圆代替连线进行分隔")]
public bool UseRoundSplit { get; set; }
/// <summary>
/// The split odd color
/// </summary>
private Color splitOddColor = Color.White;
/// <summary>
/// 分隔奇数栏背景色
/// </summary>
/// <value>The color of the split odd.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置分隔奇数栏背景色")]
public Color SplitOddColor
{
get { return splitOddColor; }
set
{
splitOddColor = value;
Invalidate();
}
}
/// <summary>
/// The split even color
/// </summary>
private Color splitEvenColor = Color.FromArgb(232, 232, 232);
/// <summary>
/// 分隔偶数栏背景色
/// </summary>
/// <value>The color of the split even.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置分隔偶数栏背景色")]
public Color SplitEvenColor
{
get { return splitEvenColor; }
set
{
splitEvenColor = value;
Invalidate();
}
}
/// <summary>
/// The line color
/// </summary>
private Color lineColor = Color.FromArgb(153, 153, 153);
/// <summary>
/// Gets or sets the color of the line.
/// </summary>
/// <value>The color of the line.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置线条色")]
public Color LineColor
{
get { return lineColor; }
set
{
lineColor = value;
Invalidate();
}
}
/// <summary>
/// The radar positions
/// </summary>
private RadarPosition[] radarPositions;
/// <summary>
/// 节点列表至少需要3个
/// </summary>
/// <value>The radar positions.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置节点至少需要3个")]
public RadarPosition[] RadarPositions
{
get { return radarPositions; }
set
{
radarPositions = value;
Invalidate();
}
}
/// <summary>
/// The title
/// </summary>
private string title;
/// <summary>
/// 标题
/// </summary>
/// <value>The title.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置标题")]
public string Title
{
get { return title; }
set
{
title = value;
ResetTitleSize();
Invalidate();
}
}
/// <summary>
/// The title font
/// </summary>
private Font titleFont = new Font("微软雅黑", 12);
/// <summary>
/// Gets or sets the title font.
/// </summary>
/// <value>The title font.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置标题字体")]
public Font TitleFont
{
get { return titleFont; }
set
{
titleFont = value;
ResetTitleSize();
Invalidate();
}
}
/// <summary>
/// The title color
/// </summary>
private Color titleColor = Color.Black;
/// <summary>
/// Gets or sets the color of the title.
/// </summary>
/// <value>The color of the title.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置标题文本颜色")]
public Color TitleColor
{
get { return titleColor; }
set
{
titleColor = value;
Invalidate();
}
}
/// <summary>
/// The lines
/// </summary>
private RadarLine[] lines;
/// <summary>
/// Gets or sets the lines.
/// </summary>
/// <value>The lines.</value>
[Browsable(true)]
[Category("自定义")]
[Description("获取或设置值线条Values长度必须与RadarPositions长度一致否则无法显示")]
public RadarLine[] Lines
{
get { return lines; }
set
{
lines = value;
Invalidate();
}
}
/// <summary>
/// The title size
/// </summary>
SizeF titleSize = SizeF.Empty;
/// <summary>
/// The m rect working
/// </summary>
private RectangleF m_rectWorking = Rectangle.Empty;
/// <summary>
/// The line value type size
/// </summary>
SizeF lineValueTypeSize = SizeF.Empty;
/// <summary>
/// The int line value COM count
/// </summary>
int intLineValueComCount = 0;
/// <summary>
/// The int line value row count
/// </summary>
int intLineValueRowCount = 0;
/// <summary>
/// Initializes a new instance of the <see cref="UCRadarChart"/> class.
/// </summary>
public UCRadarChart()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.Selectable, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.SizeChanged += UCRadarChart_SizeChanged;
Size = new System.Drawing.Size(150, 150);
radarPositions = new RadarPosition[0];
if (ControlHelper.IsDesignMode())
{
radarPositions = new RadarPosition[6];
for (int i = 0; i < 6; i++)
{
radarPositions[i] = new RadarPosition
{
Text = "Item" + (i + 1),
MaxValue = 100
};
}
}
lines = new RadarLine[0];
if (ControlHelper.IsDesignMode())
{
Random r = new Random();
lines = new RadarLine[2];
for (int i = 0; i < 2; i++)
{
lines[i] = new RadarLine()
{
Name = "line" + i
};
lines[i].Values = new double[radarPositions.Length];
for (int j = 0; j < radarPositions.Length; j++)
{
lines[i].Values[j] = r.Next(20, (int)radarPositions[j].MaxValue);
}
}
}
}
/// <summary>
/// Handles the SizeChanged event of the UCRadarChart control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
void UCRadarChart_SizeChanged(object sender, EventArgs e)
{
ResetWorkingRect();
}
/// <summary>
/// Resets the working rect.
/// </summary>
private void ResetWorkingRect()
{
if (lines != null && lines.Length > 0)
{
using (Graphics g = this.CreateGraphics())
{
foreach (var item in lines)
{
var s = g.MeasureString(item.Name, Font);
if (s.Width > lineValueTypeSize.Width)
lineValueTypeSize = s;
}
}
}
var lineTypePanelHeight = 0f;
if (lineValueTypeSize != SizeF.Empty)
{
intLineValueComCount = (int)(this.Width / (lineValueTypeSize.Width + 25));
intLineValueRowCount = lines.Length / intLineValueComCount;
if (lines.Length % intLineValueComCount != 0)
{
intLineValueRowCount++;
}
lineTypePanelHeight = (lineValueTypeSize.Height + 10) * intLineValueRowCount;
}
var min = Math.Min(this.Width, this.Height - titleSize.Height - lineTypePanelHeight);
var rectWorking = new RectangleF((this.Width - min) / 2 + 10, titleSize.Height + lineTypePanelHeight + 10, min - 10, min - 10);
//处理文字
float fltSplitAngle = 360F / radarPositions.Length;
float fltRadiusWidth = rectWorking.Width / 2;
float minX = rectWorking.Left;
float maxX = rectWorking.Right;
float minY = rectWorking.Top;
float maxY = rectWorking.Bottom;
using (Graphics g = this.CreateGraphics())
{
PointF centrePoint = new PointF(rectWorking.Left + rectWorking.Width / 2, rectWorking.Top + rectWorking.Height / 2);
for (int i = 0; i < radarPositions.Length; i++)
{
float fltAngle = 270 + fltSplitAngle * i;
fltAngle = fltAngle % 360;
PointF _point = GetPointByAngle(centrePoint, fltAngle, fltRadiusWidth);
var _txtSize = g.MeasureString(radarPositions[i].Text, Font);
if (_point.X < centrePoint.X)//左
{
if (_point.X - _txtSize.Width < minX)
{
minX = rectWorking.Left + _txtSize.Width;
}
}
else//右
{
if (_point.X + _txtSize.Width > maxX)
{
maxX = rectWorking.Right - _txtSize.Width;
}
}
if (_point.Y < centrePoint.Y)//上
{
if (_point.Y - _txtSize.Height < minY)
{
minY = rectWorking.Top + _txtSize.Height;
}
}
else//下
{
if (_point.Y + _txtSize.Height > maxY)
{
maxY = rectWorking.Bottom - _txtSize.Height;
}
}
}
}
min = Math.Min(maxX - minX, maxY - minY);
m_rectWorking = new RectangleF(minX, minY, min, min);
}
/// <summary>
/// 引发 <see cref="E:System.Windows.Forms.Control.Paint" /> 事件。
/// </summary>
/// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" />。</param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var g = e.Graphics;
g.SetGDIHigh();
if (!string.IsNullOrEmpty(title))
{
g.DrawString(title, titleFont, new SolidBrush(titleColor), new RectangleF(m_rectWorking.Left + (m_rectWorking.Width - titleSize.Width) / 2, m_rectWorking.Top - titleSize.Height - 10 - (intLineValueRowCount * (10 + lineValueTypeSize.Height)), titleSize.Width, titleSize.Height));
}
if (radarPositions.Length <= 2)
{
g.DrawString("至少需要3个顶点", Font, new SolidBrush(Color.Black), m_rectWorking, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
return;
}
var y = m_rectWorking.Top - 20 - (intLineValueRowCount * (10 + lineValueTypeSize.Height));
for (int i = 0; i < intLineValueRowCount; i++)
{
var x = 0f;
int intCount = intLineValueComCount;
if (i == intLineValueRowCount - 1)
{
intCount = lines.Length % intLineValueComCount;
}
x = m_rectWorking.Left + (m_rectWorking.Width - intCount * (lineValueTypeSize.Width + 25)) / 2;
for (int j = 0; j < intCount; j++)
{
g.FillRectangle(new SolidBrush(lines[i * intLineValueComCount + j].LineColor.Value), new RectangleF(x + (lineValueTypeSize.Width + 25) * j, y + lineValueTypeSize.Height * i, 15, lineValueTypeSize.Height));
g.DrawString(lines[i * intLineValueComCount + j].Name, Font, new SolidBrush(lines[i * intLineValueComCount + j].LineColor.Value), new PointF(x + (lineValueTypeSize.Width + 25) * j + 20, y + lineValueTypeSize.Height * i));
}
}
float fltSplitAngle = 360F / radarPositions.Length;
float fltRadiusWidth = m_rectWorking.Width / 2;
float fltSplitRadiusWidth = fltRadiusWidth / splitCount;
PointF centrePoint = new PointF(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + m_rectWorking.Height / 2);
List<List<PointF>> lstRingPoints = new List<List<PointF>>(splitCount);
//分割点
for (int i = 0; i < radarPositions.Length; i++)
{
float fltAngle = 270 + fltSplitAngle * i;
fltAngle = fltAngle % 360;
for (int j = 0; j < splitCount; j++)
{
if (i == 0)
{
lstRingPoints.Add(new List<PointF>());
}
PointF _point = GetPointByAngle(centrePoint, fltAngle, fltSplitRadiusWidth * (splitCount - j));
lstRingPoints[j].Add(_point);
}
}
if (UseRoundSplit)
{
for (int i = 0; i < splitCount; i++)
{
RectangleF rect = new RectangleF(centrePoint.X - fltSplitRadiusWidth * (splitCount - i), centrePoint.Y - fltSplitRadiusWidth * (splitCount - i), fltSplitRadiusWidth * (splitCount - i) * 2, fltSplitRadiusWidth * (splitCount - i) * 2);
if (i % 2 == 0)
{
g.FillEllipse(new SolidBrush(splitOddColor), rect);
}
else
{
g.FillEllipse(new SolidBrush(splitEvenColor), rect);
}
g.DrawEllipse(new Pen(new SolidBrush(lineColor)), rect);
}
}
else
{
//间隔颜色
for (int i = 0; i < lstRingPoints.Count; i++)
{
var ring = lstRingPoints[i];
GraphicsPath path = new GraphicsPath();
path.AddLines(ring.ToArray());
if ((lstRingPoints.Count - i) % 2 == 0)
{
g.FillPath(new SolidBrush(splitEvenColor), path);
}
else
{
g.FillPath(new SolidBrush(splitOddColor), path);
}
}
//画环
foreach (var ring in lstRingPoints)
{
ring.Add(ring[0]);
g.DrawLines(new Pen(new SolidBrush(lineColor)), ring.ToArray());
}
}
//分割线
foreach (var item in lstRingPoints[0])
{
g.DrawLine(new Pen(new SolidBrush(lineColor)), centrePoint, item);
}
//值
for (int i = 0; i < lines.Length; i++)
{
var line = lines[i];
if (line.Values.Length != radarPositions.Length)//如果数据长度和节点长度不一致则不绘制
continue;
if (line.LineColor == null || line.LineColor == Color.Empty || line.LineColor == Color.Transparent)
line.LineColor = ControlHelper.Colors[i + 13];
List<PointF> ps = new List<PointF>();
for (int j = 0; j < radarPositions.Length; j++)
{
float fltAngle = 270 + fltSplitAngle * j;
fltAngle = fltAngle % 360;
PointF _point = GetPointByAngle(centrePoint, fltAngle, fltRadiusWidth * (float)(line.Values[j] / radarPositions[i].MaxValue));
ps.Add(_point);
}
ps.Add(ps[0]);
if (line.FillColor != null && line.FillColor != Color.Empty && line.FillColor != Color.Transparent)
{
GraphicsPath path = new GraphicsPath();
path.AddLines(ps.ToArray());
g.FillPath(new SolidBrush(line.FillColor.Value), path);
}
g.DrawLines(new Pen(new SolidBrush(line.LineColor.Value), 2), ps.ToArray());
for (int j = 0; j < radarPositions.Length; j++)
{
var item = ps[j];
g.FillEllipse(new SolidBrush(Color.White), new RectangleF(item.X - 3, item.Y - 3, 6, 6));
g.DrawEllipse(new Pen(new SolidBrush(line.LineColor.Value)), new RectangleF(item.X - 3, item.Y - 3, 6, 6));
if (line.ShowValueText)
{
var valueSize = g.MeasureString(line.Values[j].ToString("0.##"), Font);
g.DrawString(line.Values[j].ToString("0.##"), Font, new SolidBrush(line.LineColor.Value), new PointF(item.X - valueSize.Width / 2, item.Y - valueSize.Height - 5));
}
}
}
//文本
for (int i = 0; i < radarPositions.Length; i++)
{
PointF point = lstRingPoints[0][i];
var txtSize = g.MeasureString(radarPositions[i].Text, Font);
if (point.X == centrePoint.X)
{
if (point.Y > centrePoint.Y)
{
g.DrawString(radarPositions[i].Text, Font, new SolidBrush(ForeColor), new PointF(point.X - txtSize.Width / 2, point.Y + 10));
}
else
{
g.DrawString(radarPositions[i].Text, Font, new SolidBrush(ForeColor), new PointF(point.X - txtSize.Width / 2, point.Y - 10 - txtSize.Height));
}
}
else if (point.Y == centrePoint.Y)
{
if (point.X < centrePoint.X)
g.DrawString(radarPositions[i].Text, Font, new SolidBrush(ForeColor), new PointF(point.X - 10 - txtSize.Width, point.Y - txtSize.Height / 2));
else
g.DrawString(radarPositions[i].Text, Font, new SolidBrush(ForeColor), new PointF(point.X + 10, point.Y - txtSize.Height / 2));
}
else if (point.X < centrePoint.X)//左
{
if (point.Y < centrePoint.Y)//左上
{
g.DrawString(radarPositions[i].Text, Font, new SolidBrush(ForeColor), new PointF(point.X - 10 - txtSize.Width, point.Y - 10 + txtSize.Height / 2));
}
else//左下
{
g.DrawString(radarPositions[i].Text, Font, new SolidBrush(ForeColor), new PointF(point.X - 10 - txtSize.Width, point.Y + 10 - txtSize.Height / 2));
}
}
else
{
if (point.Y < centrePoint.Y)//右上
{
g.DrawString(radarPositions[i].Text, Font, new SolidBrush(ForeColor), new PointF(point.X + 10, point.Y - 10 + txtSize.Height / 2));
}
else//右下
{
g.DrawString(radarPositions[i].Text, Font, new SolidBrush(ForeColor), new PointF(point.X + 10, point.Y + 10 - txtSize.Height / 2));
}
}
}
}
#region English:Calculating the coordinate points of circular edge according to the center point, angle and radius
/// <summary>
/// 功能描述:根据中心点、角度、半径计算圆边坐标点 English:Calculating the coordinate points of circular edge according to the center point, angle and radius
/// 作  者:HZH
/// 创建日期:2019-09-25 09:46:32
/// 任务编号:POS
/// </summary>
/// <param name="centrePoint">centrePoint</param>
/// <param name="fltAngle">fltAngle</param>
/// <param name="fltRadiusWidth">fltRadiusWidth</param>
/// <returns>返回值</returns>
private PointF GetPointByAngle(PointF centrePoint, float fltAngle, float fltRadiusWidth)
{
PointF p = centrePoint;
if (fltAngle == 0)
{
p.X += fltRadiusWidth;
}
else if (fltAngle == 90)
{
p.Y += fltRadiusWidth;
}
else if (fltAngle == 180)
{
p.X -= fltRadiusWidth;
}
else if (fltAngle == 270)
{
p.Y -= fltRadiusWidth;
}
else if (fltAngle > 0 && fltAngle < 90)
{
p.Y += (float)Math.Sin(Math.PI * (fltAngle / 180.00F)) * fltRadiusWidth;
p.X += (float)Math.Cos(Math.PI * (fltAngle / 180.00F)) * fltRadiusWidth;
}
else if (fltAngle > 90 && fltAngle < 180)
{
p.Y += (float)Math.Sin(Math.PI * ((180 - fltAngle) / 180.00F)) * fltRadiusWidth;
p.X -= (float)Math.Cos(Math.PI * ((180 - fltAngle) / 180.00F)) * fltRadiusWidth;
}
else if (fltAngle > 180 && fltAngle < 270)
{
p.Y -= (float)Math.Sin(Math.PI * ((fltAngle - 180) / 180.00F)) * fltRadiusWidth;
p.X -= (float)Math.Cos(Math.PI * ((fltAngle - 180) / 180.00F)) * fltRadiusWidth;
}
else if (fltAngle > 270 && fltAngle < 360)
{
p.Y -= (float)Math.Sin(Math.PI * ((360 - fltAngle) / 180.00F)) * fltRadiusWidth;
p.X += (float)Math.Cos(Math.PI * ((360 - fltAngle) / 180.00F)) * fltRadiusWidth;
}
return p;
}
#endregion
/// <summary>
/// Resets the size of the title.
/// </summary>
private void ResetTitleSize()
{
if (!string.IsNullOrEmpty(title))
{
using (Graphics g = this.CreateGraphics())
{
titleSize = g.MeasureString(title, titleFont);
}
}
else
{
titleSize = SizeF.Empty;
}
titleSize.Height += 20;
ResetWorkingRect();
}
}
}

View File

@@ -0,0 +1,36 @@
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-17
//
// ***********************************************************************
// <copyright file="ZoomType.cs">
// Copyright by Huang Zhenghui(»ÆÕý»Ô) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub£ºhttps://github.com/kwwwvagaa/NetWinformControl
// gitee£ºhttps://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
namespace HZH_Controls.Controls
{
/// <summary>
/// Enum ZoomType
/// </summary>
public enum ZoomType
{
/// <summary>
/// The none
/// </summary>
None,
/// <summary>
/// The enlarge
/// </summary>
Enlarge,
/// <summary>
/// The reduce
/// </summary>
Reduce
}
}