* UIDataGridView:更新默认设置为原生控件设置
This commit is contained in:
parent
12227b3404
commit
f3adc6af6e
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
BIN
Bin/SunnyUI.pdb
BIN
Bin/SunnyUI.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,6 @@
|
||||
namespace Sunny.UI.Demo.Charts
|
||||
using System.Drawing;
|
||||
|
||||
namespace Sunny.UI.Demo.Charts
|
||||
{
|
||||
public partial class FBarChart : UITitlePage
|
||||
{
|
||||
@ -52,6 +54,9 @@
|
||||
option.XAxis.Name = "日期";
|
||||
option.YAxis.Name = "数值";
|
||||
|
||||
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 12 });
|
||||
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = -20 });
|
||||
|
||||
BarChart.SetOption(option);
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
||||
series.Name = "Star count";
|
||||
series.Center = new UICenter(50, 55);
|
||||
series.Radius = 70;
|
||||
series.Label.Show = true;
|
||||
|
||||
//增加数据
|
||||
series.AddData("2020-05-19", 38);
|
||||
|
@ -81,7 +81,7 @@ namespace Sunny.UI
|
||||
{
|
||||
if (YAxisStart >= 0)
|
||||
{
|
||||
float h = Math.Abs((float)(DrawSize.Height * (series.Data[j]- start *interval) / ((end -start) * interval)));
|
||||
float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));
|
||||
|
||||
Bars[i].Add(new BarInfo()
|
||||
{
|
||||
@ -91,9 +91,9 @@ namespace Sunny.UI
|
||||
x2, h)
|
||||
});
|
||||
}
|
||||
else if (YAxisEnd<=0)
|
||||
else if (YAxisEnd <= 0)
|
||||
{
|
||||
float h = Math.Abs((float)(DrawSize.Height * (end * interval-series.Data[j]) / ((end - start) * interval)));
|
||||
float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
|
||||
Bars[i].Add(new BarInfo()
|
||||
{
|
||||
Rect = new RectangleF(
|
||||
@ -294,6 +294,7 @@ namespace Sunny.UI
|
||||
DrawSeries(g, BarOption.Series);
|
||||
if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line) DrawToolTip(g);
|
||||
DrawLegend(g, BarOption.Legend);
|
||||
DrawAxisScales(g);
|
||||
}
|
||||
|
||||
private void DrawToolTip(Graphics g)
|
||||
@ -314,8 +315,8 @@ namespace Sunny.UI
|
||||
|
||||
private void DrawAxis(Graphics g)
|
||||
{
|
||||
if (YAxisStart>=0) g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X + DrawSize.Width, DrawOrigin.Y));
|
||||
if (YAxisEnd <= 0) g.DrawLine(ChartStyle.ForeColor, new Point(DrawOrigin.X, BarOption.Grid.Top), new Point(DrawOrigin.X + DrawSize.Width, BarOption.Grid.Top));
|
||||
if (YAxisStart >= 0) g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X + DrawSize.Width, DrawOrigin.Y));
|
||||
if (YAxisEnd <= 0) g.DrawLine(ChartStyle.ForeColor, new Point(DrawOrigin.X, BarOption.Grid.Top), new Point(DrawOrigin.X + DrawSize.Width, BarOption.Grid.Top));
|
||||
|
||||
g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X, DrawOrigin.Y - DrawSize.Height));
|
||||
|
||||
@ -367,7 +368,7 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
SizeF sfname = g.MeasureString(BarOption.XAxis.Name, SubFont);
|
||||
g.DrawString(BarOption.XAxis.Name,SubFont,ChartStyle.ForeColor, DrawOrigin.X +(DrawSize.Width-sfname.Width)/2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length +sfname.Height);
|
||||
g.DrawString(BarOption.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfname.Width) / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + sfname.Height);
|
||||
}
|
||||
|
||||
if (BarOption.YAxis.AxisTick.Show)
|
||||
@ -420,9 +421,23 @@ namespace Sunny.UI
|
||||
|
||||
SizeF sfname = g.MeasureString(BarOption.YAxis.Name, SubFont);
|
||||
int x = (int)(DrawOrigin.X - BarOption.YAxis.AxisTick.Length - wmax - sfname.Height);
|
||||
int y = (int) (BarOption.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
|
||||
g.DrawString(BarOption.YAxis.Name,SubFont,ChartStyle.ForeColor, new Point(x,y),
|
||||
new StringFormat(){Alignment = StringAlignment.Center}, 270);
|
||||
int y = (int)(BarOption.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
|
||||
g.DrawString(BarOption.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(x, y),
|
||||
new StringFormat() { Alignment = StringAlignment.Center }, 270);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawAxisScales(Graphics g)
|
||||
{
|
||||
foreach (var line in BarOption.YAxisScaleLines)
|
||||
{
|
||||
double ymin = YAxisStart * YAxisInterval;
|
||||
double ymax = YAxisEnd * YAxisInterval;
|
||||
float pos = (float)((line.Value - ymin) * (Height - BarOption.Grid.Top - BarOption.Grid.Bottom) / (ymax - ymin));
|
||||
pos = (Height - BarOption.Grid.Bottom - pos);
|
||||
g.DrawLine(line.Color, DrawOrigin.X, pos, Width - BarOption.Grid.Right, pos);
|
||||
SizeF sf = g.MeasureString(line.Name, SubFont);
|
||||
g.DrawString(line.Name, SubFont, line.Color, DrawOrigin.X + 4, pos - 2 - sf.Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,9 @@ namespace Sunny.UI
|
||||
|
||||
public UIChartGrid Grid = new UIChartGrid();
|
||||
|
||||
//public UIPieLegend Legend;
|
||||
public readonly List<UIScaleLine> XAxisScaleLines = new List<UIScaleLine>();
|
||||
|
||||
//public UIPieToolTip ToolTip;
|
||||
public readonly List<UIScaleLine> YAxisScaleLines = new List<UIScaleLine>();
|
||||
|
||||
public void AddSeries(UIBarSeries series)
|
||||
{
|
||||
@ -43,7 +43,7 @@ namespace Sunny.UI
|
||||
|
||||
public string ValueFormat { get; set; } = "F0";
|
||||
|
||||
public UIAxisPointer AxisPointer= new UIAxisPointer();
|
||||
public UIAxisPointer AxisPointer = new UIAxisPointer();
|
||||
}
|
||||
|
||||
public class UIAxisPointer
|
||||
@ -53,7 +53,7 @@ namespace Sunny.UI
|
||||
|
||||
public enum UIAxisPointerType
|
||||
{
|
||||
Line,Shadow
|
||||
Line, Shadow
|
||||
}
|
||||
|
||||
public class UIAxis
|
||||
@ -111,13 +111,13 @@ namespace Sunny.UI
|
||||
/// </summary>
|
||||
public int Interval { get; set; } = 0;
|
||||
|
||||
public delegate string DoFormatter(double value,int index);
|
||||
public delegate string DoFormatter(double value, int index);
|
||||
|
||||
public event DoFormatter Formatter;
|
||||
|
||||
public string GetLabel(double value, int index)
|
||||
{
|
||||
return Formatter != null ? Formatter?.Invoke(value, index) : value.ToString("F"+ DecimalCount);
|
||||
return Formatter != null ? Formatter?.Invoke(value, index) : value.ToString("F" + DecimalCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -92,7 +92,7 @@ namespace Sunny.UI
|
||||
}
|
||||
}
|
||||
|
||||
public class UILiveChartStyle:UIChartStyle
|
||||
public class UILiveChartStyle : UIChartStyle
|
||||
{
|
||||
public override Color BackColor => Color.FromArgb(16, 36, 71);
|
||||
|
||||
@ -106,10 +106,10 @@ namespace Sunny.UI
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
Color.FromArgb(33, 149, 242),
|
||||
Color.FromArgb(254, 192, 7),
|
||||
Color.FromArgb(243, 67, 54),
|
||||
Color.FromArgb(96, 125, 138),
|
||||
Color.FromArgb(33, 149, 242),
|
||||
Color.FromArgb(254, 192, 7),
|
||||
Color.FromArgb(243, 67, 54),
|
||||
Color.FromArgb(96, 125, 138),
|
||||
Color.FromArgb(0,187,211),
|
||||
Color.FromArgb(232,30,99),
|
||||
Color.FromArgb(254,87,34),
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
@ -30,6 +31,13 @@ namespace Sunny.UI
|
||||
public UILegend Legend;
|
||||
}
|
||||
|
||||
public class UIScaleLine
|
||||
{
|
||||
public double Value { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Color Color { get; set; }
|
||||
}
|
||||
|
||||
public class UILegend
|
||||
{
|
||||
public UILeftAlignment Left { get; set; } = UILeftAlignment.Center;
|
||||
|
@ -130,6 +130,26 @@ namespace Sunny.UI
|
||||
RectangleF rectx = new RectangleF(rect.X - 10, rect.Y - 10, rect.Width + 20, rect.Width + 20);
|
||||
g.FillPie(color, (ActivePieIndex == pieIndex && ActiveAzIndex == azIndex) ? rectx : rect, Angles[pieIndex][azIndex].Start - 90, Angles[pieIndex][azIndex].Sweep);
|
||||
Angles[pieIndex][azIndex].TextSize = g.MeasureString(Angles[pieIndex][azIndex].Text, LegendFont);
|
||||
|
||||
if (pie.Label.Show)
|
||||
{
|
||||
double az = Angles[pieIndex][azIndex].Start + Angles[pieIndex][azIndex].Sweep / 2;
|
||||
double x = Math.Abs(Math.Sin(az * Math.PI / 180));
|
||||
double y = Math.Abs(Math.Cos(az * Math.PI / 180));
|
||||
|
||||
SizeF sf = g.MeasureString(pie.Data[0].Value.ToString("F0"), SubFont);
|
||||
PointF pf;
|
||||
if (az >= 0 && az < 90)
|
||||
pf = new PointF((float)(DrawCenter(pie).X + RadiusSize(pie) * x + 6), (float)(DrawCenter(pie).Y - RadiusSize(pie) * y - sf.Height - 6));
|
||||
else if (az >= 90 && az < 180)
|
||||
pf = new PointF((float)(DrawCenter(pie).X + RadiusSize(pie) * x + 6), (float)(DrawCenter(pie).Y + RadiusSize(pie) * y + 6));
|
||||
else if (az >= 180 && az < 270)
|
||||
pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - 6) - sf.Width, (float)(DrawCenter(pie).Y + RadiusSize(pie) * y + 6));
|
||||
else
|
||||
pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - 6) - sf.Width, (float)(DrawCenter(pie).Y - RadiusSize(pie) * y) - sf.Height - 6);
|
||||
|
||||
g.DrawString(pie.Data[azIndex].Value.ToString("F0"), SubFont, color, pf.X, pf.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -232,6 +252,24 @@ namespace Sunny.UI
|
||||
return new RectangleF(left - halfRadius, top - halfRadius, halfRadius * 2, halfRadius * 2);
|
||||
}
|
||||
|
||||
private Point DrawCenter(UIPieSeries series)
|
||||
{
|
||||
int left = series.Center.Left;
|
||||
int top = series.Center.Top;
|
||||
left = Width * left / 100;
|
||||
top = Height * top / 100;
|
||||
return new Point(left, top);
|
||||
}
|
||||
|
||||
private float RadiusSize(UIPieSeries series)
|
||||
{
|
||||
int left = series.Center.Left;
|
||||
int top = series.Center.Top;
|
||||
left = Width * left / 100;
|
||||
top = Height * top / 100;
|
||||
return Math.Min(Width, Height) * series.Radius / 200.0f;
|
||||
}
|
||||
|
||||
private class Angle
|
||||
{
|
||||
public float Start { get; set; }
|
||||
|
@ -18,6 +18,7 @@
|
||||
*
|
||||
* 2020-01-01: V2.2.0 增加文件说明
|
||||
* 2020-04-25: V2.2.4 功能增强、美化
|
||||
* 2020-07-15: V2.2.6 更改默认配置为原生
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -29,25 +30,22 @@ namespace Sunny.UI
|
||||
{
|
||||
public sealed class UIDataGridView : DataGridView, IStyleInterface
|
||||
{
|
||||
private readonly UIScrollBar Bar = new UIScrollBar();
|
||||
private readonly UIScrollBar VBar = new UIScrollBar();
|
||||
|
||||
public UIDataGridView()
|
||||
{
|
||||
BackgroundColor = UIColor.White;
|
||||
GridColor = UIColor.Blue;
|
||||
Font = UIFontColor.Font;
|
||||
ScrollBars = ScrollBars.Vertical;
|
||||
DoubleBuffered = true;
|
||||
Bar.Parent = this;
|
||||
Bar.Visible = false;
|
||||
Bar.FillColor = UIColor.LightBlue;
|
||||
Bar.ForeColor = UIColor.Blue;
|
||||
Bar.StyleCustomMode = true;
|
||||
Bar.ValueChanged += Bar_ValueChanged;
|
||||
SetBarPosition();
|
||||
|
||||
//列占满行
|
||||
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
VBar.Parent = this;
|
||||
VBar.Visible = false;
|
||||
VBar.FillColor = UIColor.LightBlue;
|
||||
VBar.ForeColor = UIColor.Blue;
|
||||
VBar.StyleCustomMode = true;
|
||||
VBar.ValueChanged += VBarValueChanged;
|
||||
SetBarPosition();
|
||||
|
||||
//支持自定义标题行风格
|
||||
EnableHeadersVisualStyles = false;
|
||||
@ -67,11 +65,25 @@ namespace Sunny.UI
|
||||
RowTemplate.MinimumHeight = 29;
|
||||
AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
|
||||
|
||||
//设置奇偶数行颜色
|
||||
StripeEvenColor = UIColor.White;
|
||||
StripeOddColor = UIColor.LightBlue;
|
||||
|
||||
VerticalScrollBar.ValueChanged += VerticalScrollBar_ValueChanged;
|
||||
|
||||
Style = UIStyle.Blue;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
//列占满行
|
||||
//AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
|
||||
//行选
|
||||
SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
|
||||
//禁止调整数据行行高
|
||||
//AllowUserToResizeRows = false;
|
||||
AllowUserToResizeRows = false;
|
||||
|
||||
//允许调整标题行行宽
|
||||
AllowUserToResizeColumns = true;
|
||||
@ -83,36 +95,44 @@ namespace Sunny.UI
|
||||
//MultiSelect = false;
|
||||
|
||||
//自动生成行
|
||||
AutoGenerateColumns = true;
|
||||
//AutoGenerateColumns = true;
|
||||
|
||||
//禁用最后一行空白,自动新增行
|
||||
AllowUserToAddRows = false;
|
||||
AllowUserToDeleteRows = false;
|
||||
|
||||
//禁止只读
|
||||
ReadOnly = false;
|
||||
//ReadOnly = false;
|
||||
|
||||
//不显示表格线
|
||||
CellBorderStyle = DataGridViewCellBorderStyle.None;
|
||||
}
|
||||
|
||||
StripeEvenColor = UIColor.White;
|
||||
StripeOddColor = UIColor.LightBlue;
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
VerticalScrollBar.ValueChanged += VerticalScrollBar_ValueChanged;
|
||||
if (ShowRect)
|
||||
{
|
||||
Color color = RectColor;
|
||||
color = Enabled ? color : UIDisableColor.Fill;
|
||||
e.Graphics.DrawRectangle(color, new Rectangle(0, 0, Width - 1, Height - 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void VerticalScrollBar_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Bar.Value = FirstDisplayedScrollingRowIndex;
|
||||
VBar.Value = FirstDisplayedScrollingRowIndex;
|
||||
}
|
||||
|
||||
private void Bar_ValueChanged(object sender, EventArgs e)
|
||||
private void VBarValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
FirstDisplayedScrollingRowIndex = Bar.Value;
|
||||
FirstDisplayedScrollingRowIndex = VBar.Value;
|
||||
}
|
||||
|
||||
public void SetScrollInfo()
|
||||
{
|
||||
if (Bar == null)
|
||||
if (VBar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -120,28 +140,28 @@ namespace Sunny.UI
|
||||
if (VerticalScrollBar.Visible)
|
||||
{
|
||||
SetBarPosition();
|
||||
Bar.Maximum = RowCount - 1;
|
||||
Bar.Value = FirstDisplayedScrollingRowIndex;
|
||||
Bar.Visible = true;
|
||||
VBar.Maximum = RowCount - 1;
|
||||
VBar.Value = FirstDisplayedScrollingRowIndex;
|
||||
VBar.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Bar.Visible = false;
|
||||
VBar.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
if (Bar.Visible)
|
||||
if (VBar.Visible)
|
||||
{
|
||||
if (e.Delta > 10)
|
||||
{
|
||||
Bar.SetValue(Bar.Value - Bar.Maximum / 20);
|
||||
VBar.SetValue(VBar.Value - VBar.Maximum / 20);
|
||||
}
|
||||
else if (e.Delta < -10)
|
||||
{
|
||||
Bar.SetValue(Bar.Value + Bar.Maximum / 20);
|
||||
VBar.SetValue(VBar.Value + VBar.Maximum / 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,11 +187,11 @@ namespace Sunny.UI
|
||||
|
||||
private void SetBarPosition()
|
||||
{
|
||||
Bar.Left = Width - ScrollBarInfo.VerticalScrollBarWidth() - 2;
|
||||
Bar.Top = 0;
|
||||
Bar.Width = ScrollBarInfo.VerticalScrollBarWidth() + 1;
|
||||
Bar.Height = Height;
|
||||
Bar.BringToFront();
|
||||
VBar.Left = Width - ScrollBarInfo.VerticalScrollBarWidth() - 2;
|
||||
VBar.Top = 1;
|
||||
VBar.Width = ScrollBarInfo.VerticalScrollBarWidth() + 1;
|
||||
VBar.Height = Height - 2;
|
||||
VBar.BringToFront();
|
||||
}
|
||||
|
||||
protected override void OnColumnAdded(DataGridViewColumnEventArgs e)
|
||||
@ -243,8 +263,8 @@ namespace Sunny.UI
|
||||
StripeEvenColor = uiColor.GridStripeEvenColor;
|
||||
StripeOddColor = uiColor.GridStripeOddColor;
|
||||
|
||||
Bar.FillColor = uiColor.GridStripeOddColor;
|
||||
Bar.ForeColor = uiColor.PrimaryColor;
|
||||
VBar.FillColor = uiColor.GridStripeOddColor;
|
||||
VBar.ForeColor = uiColor.PrimaryColor;
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
@ -256,25 +276,6 @@ namespace Sunny.UI
|
||||
|
||||
public string TagString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 重新设置边框
|
||||
/// </summary>
|
||||
/// <param name="m">当前的Windows消息</param>
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
if (IsDisposed || Disposing) return;
|
||||
if (ShowRect)
|
||||
{
|
||||
if (m.Msg == 0xf || m.Msg == 0x133)
|
||||
{
|
||||
Color color = RectColor;
|
||||
color = Enabled ? color : UIDisableColor.Fill;
|
||||
ControlEx.ResetBorderColor(m, this, 1, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示边框
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user