* UIDataGridView:更新默认设置为原生控件设置

This commit is contained in:
Sunny 2020-07-15 21:26:07 +08:00
parent 12227b3404
commit f3adc6af6e
12 changed files with 145 additions and 77 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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);
}

View File

@ -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);

View File

@ -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)
@ -426,6 +427,20 @@ namespace Sunny.UI
}
}
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);
}
}
private void DrawSeries(Graphics g, List<UIBarSeries> series)
{
if (series == null || series.Count == 0) return;

View File

@ -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)
{

View File

@ -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;

View File

@ -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; }

View File

@ -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>