2613 lines
74 KiB
C#
2613 lines
74 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.Design;
|
|
using System.Drawing;
|
|
using System.Drawing.Design;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms.Design;
|
|
using System.Windows.Forms.Design.Behavior;
|
|
using DevComponents.DotNetBar;
|
|
using DevComponents.DotNetBar.Charts;
|
|
using DevComponents.DotNetBar.Charts.Style;
|
|
using Microsoft.Win32;
|
|
|
|
namespace DevComponents.Charts.Design
|
|
{
|
|
/// <summary>
|
|
/// ChartControlDesigner
|
|
/// </summary>
|
|
public class ChartControlDesigner : ControlDesigner
|
|
{
|
|
static Random _Rand = new Random();
|
|
|
|
#region Private variables
|
|
|
|
private ChartControl _ChartControl;
|
|
|
|
private IDesignerHost _DesignerHost;
|
|
private DesignerActionListCollection _ActionLists;
|
|
private DesignerActionUIService _ActionUIService;
|
|
|
|
private IComponentChangeService _ChangeService;
|
|
private ISelectionService _SelectionService;
|
|
private IMenuCommandService _MenuCommandService;
|
|
private IMenuEditorService _MenuEditorService;
|
|
private IToolboxService _ToolboxService;
|
|
|
|
private bool _InCopyItem;
|
|
private bool _DragMoving;
|
|
|
|
private bool _UseGlyphs;
|
|
|
|
#endregion
|
|
|
|
#region Public properties
|
|
|
|
#region ChangeService
|
|
|
|
public IComponentChangeService ChangeService
|
|
{
|
|
get { return (_ChangeService); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ControlDesigner
|
|
|
|
public ControlDesigner ControlDesigner
|
|
{
|
|
get { return (this); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DesignerHost
|
|
|
|
public IDesignerHost DesignerHost
|
|
{
|
|
get { return (_DesignerHost); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InCopyItem
|
|
|
|
public bool InCopyItem
|
|
{
|
|
get { return (_InCopyItem); }
|
|
set { _InCopyItem = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InCopyItem
|
|
|
|
public bool DragMoving
|
|
{
|
|
get { return (_DragMoving); }
|
|
set { _DragMoving = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SelectionService
|
|
|
|
public ISelectionService SelectionService
|
|
{
|
|
get { return (_SelectionService); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region MenuEditorService
|
|
|
|
public IMenuEditorService MenuEditorService
|
|
{
|
|
get { return (_MenuEditorService); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region MenuCommandService
|
|
|
|
public IMenuCommandService MenuCommandService
|
|
{
|
|
get { return (_MenuCommandService); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ToolboxService
|
|
|
|
public IToolboxService ToolboxService
|
|
{
|
|
get { return (_ToolboxService); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Initialize
|
|
|
|
/// <summary>
|
|
/// Initializes our designer
|
|
/// </summary>
|
|
/// <param name="component"></param>
|
|
public override void Initialize(IComponent component)
|
|
{
|
|
base.Initialize(component);
|
|
|
|
if (component.Site.DesignMode == true)
|
|
_ChartControl = component as ChartControl;
|
|
|
|
_DesignerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;
|
|
|
|
if (_DesignerHost != null)
|
|
_DesignerHost.LoadComplete += DhLoadComplete;
|
|
|
|
InitializeServices();
|
|
}
|
|
|
|
#region InitializeServices
|
|
|
|
private void InitializeServices()
|
|
{
|
|
_ChangeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService;
|
|
_SelectionService = GetService(typeof(ISelectionService)) as ISelectionService;
|
|
_ActionUIService = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
|
|
_MenuCommandService = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
|
|
_MenuEditorService = GetService(typeof(IMenuEditorService)) as IMenuEditorService;
|
|
_ToolboxService = GetService(typeof(IToolboxService)) as IToolboxService;
|
|
|
|
_ChangeService.ComponentChanged += ChangeService_ComponentChanged;
|
|
_ChangeService.ComponentAdded += ChangeService_ComponentAdded;
|
|
_ChangeService.ComponentRemoved += ChangeService_ComponentRemoved;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region InitializeNewComponent
|
|
|
|
public override void InitializeNewComponent(IDictionary defaultValues)
|
|
{
|
|
base.InitializeNewComponent(defaultValues);
|
|
|
|
ChartStyleDialog csd = new ChartStyleDialog();
|
|
|
|
csd.ShowDialog();
|
|
|
|
if (Component != null && Component.Site != null && Component.Site.DesignMode == true)
|
|
{
|
|
if (_ChartControl != null)
|
|
{
|
|
IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost));
|
|
|
|
if (dh == null)
|
|
return;
|
|
|
|
DesignerTransaction dt = dh.CreateTransaction();
|
|
|
|
try
|
|
{
|
|
IComponentChangeService change =
|
|
GetService(typeof(IComponentChangeService)) as IComponentChangeService;
|
|
|
|
if (change != null)
|
|
change.OnComponentChanging(this.Component, null);
|
|
|
|
CreateNewChart(csd);
|
|
|
|
if (change != null)
|
|
change.OnComponentChanged(_ChartControl, null, null, null);
|
|
}
|
|
finally
|
|
{
|
|
dt.Commit();
|
|
}
|
|
}
|
|
}
|
|
|
|
#if !TRIAL
|
|
ChartControl chartControl = Control as ChartControl;
|
|
|
|
if (chartControl != null)
|
|
chartControl.LicenseKey = GetLicenseKey();
|
|
#endif
|
|
}
|
|
|
|
#region CreateNewChart
|
|
|
|
private void CreateNewChart(ChartStyleDialog csd)
|
|
{
|
|
SetupScrollBarStyles();
|
|
|
|
switch (csd.CbSelected)
|
|
{
|
|
case "cbPointPlot":
|
|
InitDefaultPlot(SeriesType.Point);
|
|
break;
|
|
|
|
case "cbLinePlot":
|
|
InitDefaultPlot(SeriesType.Line);
|
|
break;
|
|
|
|
case "cbMultiAxis":
|
|
InitMultiAxis();
|
|
break;
|
|
|
|
case "cbVDotPlot":
|
|
InitDotPlot(SeriesType.HorizontalDot);
|
|
break;
|
|
|
|
case "cbHDotPlot":
|
|
InitDotPlot(SeriesType.VerticalDot);
|
|
break;
|
|
|
|
case "cbMultiChart":
|
|
InitMultiChart();
|
|
break;
|
|
|
|
case "cbBubblePlot":
|
|
InitBubblePlot();
|
|
break;
|
|
|
|
case "cbStepLine":
|
|
ChartSeries series1 = InitDefaultPlot(SeriesType.Line);
|
|
|
|
if (series1 != null)
|
|
series1.ChartLineDisplayMode = ChartLineDisplayMode.DisplayStepLine;
|
|
break;
|
|
|
|
case "cbLineArea":
|
|
ChartSeries series2 = InitDefaultPlot(SeriesType.Line);
|
|
|
|
if (series2 != null)
|
|
series2.ChartLineAreaDisplayMode = ChartLineAreaDisplayMode.DisplayLine;
|
|
break;
|
|
|
|
case "cbBarV":
|
|
InitBar(SeriesType.VerticalBar, false);
|
|
break;
|
|
|
|
case "cbBarH":
|
|
InitBar(SeriesType.HorizontalBar, false);
|
|
break;
|
|
|
|
case "cbRangeBarV":
|
|
InitBar(SeriesType.VerticalBar, true);
|
|
break;
|
|
|
|
case "cbRangeBarH":
|
|
InitBar(SeriesType.HorizontalBar, true);
|
|
break;
|
|
|
|
case "cbHiLoVBox":
|
|
InitHiLoBar(SeriesType.VerticalHiLoBar, HiLoBarType.Box);
|
|
break;
|
|
|
|
case "cbHiLoHBox":
|
|
InitHiLoBar(SeriesType.HorizontalHiLoBar, HiLoBarType.Box);
|
|
break;
|
|
|
|
case "cbHiLoVLine":
|
|
InitHiLoBar(SeriesType.VerticalHiLoBar, HiLoBarType.Line);
|
|
break;
|
|
|
|
case "cbHiLoHLine":
|
|
InitHiLoBar(SeriesType.HorizontalHiLoBar, HiLoBarType.Line);
|
|
break;
|
|
|
|
case "cbPieSimple":
|
|
InitPieSimple();
|
|
break;
|
|
|
|
case "cbPieDonut":
|
|
InitPieDonut();
|
|
break;
|
|
|
|
case "cbPieExtent":
|
|
InitPieExtent();
|
|
break;
|
|
|
|
case "cbPieExtentFill":
|
|
InitPieExtentFill();
|
|
break;
|
|
|
|
case "cbPieMultiRing":
|
|
InitPieMultiRing();
|
|
break;
|
|
|
|
case "cbPieMultiRingRev":
|
|
InitPieMultiRingRev();
|
|
break;
|
|
|
|
case "cbPieMultiSeries":
|
|
InitPieMultiSeries();
|
|
break;
|
|
|
|
case "cbPieShowSingleRing":
|
|
InitPieShowSingleRing();
|
|
break;
|
|
|
|
case "cbPieGridAngle":
|
|
InitPieGridAngle();
|
|
break;
|
|
|
|
case "cbPieOverlay":
|
|
InitPieOverlay();
|
|
break;
|
|
|
|
default:
|
|
InitBlankChart();
|
|
break;
|
|
}
|
|
}
|
|
|
|
#region InitDefaultPie
|
|
|
|
private PieChart InitDefaultPie(int seriesCount, int ringCount, bool extent)
|
|
{
|
|
PieChart pieChart = AddPieChart();
|
|
|
|
if (pieChart != null)
|
|
{
|
|
for (int i = 0; i < seriesCount; i++)
|
|
{
|
|
PieSeries series = GetNewPieSeries(pieChart);
|
|
|
|
if (series != null)
|
|
AddSimulatedPieData(series, ringCount, extent);
|
|
|
|
pieChart.ChartSeries.Add(series);
|
|
}
|
|
|
|
_ChartControl.ChartPanel.ChartContainers.Add(pieChart);
|
|
}
|
|
|
|
return (pieChart);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieSimple
|
|
|
|
private void InitPieSimple()
|
|
{
|
|
InitDefaultPie(1, 1, false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieDonut
|
|
|
|
private void InitPieDonut()
|
|
{
|
|
PieChart pieChart = InitDefaultPie(1, 1, false);
|
|
|
|
pieChart.InnerRadius = .2;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieExtent
|
|
|
|
private void InitPieExtent()
|
|
{
|
|
InitDefaultPie(1, 1, true);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieExtentFill
|
|
|
|
private void InitPieExtentFill()
|
|
{
|
|
PieChart pieChart = InitDefaultPie(1, 1, true);
|
|
|
|
pieChart.SubSliceVisualLayout.ShowSliceWhiteSpace = Tbool.True;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieMultiRing
|
|
|
|
private void InitPieMultiRing()
|
|
{
|
|
InitDefaultPie(1, 2, false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieMultiRingRev
|
|
|
|
private void InitPieMultiRingRev()
|
|
{
|
|
PieChart pieChart = InitDefaultPie(1, 2, false);
|
|
|
|
pieChart.ReverseRingOrder = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieMultiSeries
|
|
|
|
private void InitPieMultiSeries()
|
|
{
|
|
InitDefaultPie(2, 1, false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieShowSingleRing
|
|
|
|
private void InitPieShowSingleRing()
|
|
{
|
|
PieChart pieChart = InitDefaultPie(1, 2, false);
|
|
|
|
pieChart.InnerRadius = .3;
|
|
pieChart.ShowAllRings = Tbool.False;
|
|
pieChart.MouseDoubleClickSliceAction = MouseDoubleClickSliceAction.ChangeActiveRing;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieGridAngle
|
|
|
|
private void InitPieGridAngle()
|
|
{
|
|
PieChart pieChart = InitDefaultPie(1, 1, true);
|
|
|
|
pieChart.ShowPieGrid = true;
|
|
pieChart.SubSliceVisualLayout.AngleMargin = 2;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitPieOverlay
|
|
|
|
private void InitPieOverlay()
|
|
{
|
|
PieChart pieChart = InitDefaultPie(2, 1, true);
|
|
|
|
pieChart.ShowPieGrid = true;
|
|
pieChart.SeriesOverlayEnabled = true;
|
|
|
|
pieChart.ChartControl.UpdateLayout();
|
|
|
|
pieChart.SubSliceVisualLayout.AngleMargin = 2;
|
|
|
|
for (int i = 0; i < pieChart.ChartSeries.Count; i++)
|
|
{
|
|
PieSeries series = pieChart.ChartSeries[i];
|
|
|
|
UpdateOverlayBackground(series.SeriesPoints);
|
|
}
|
|
}
|
|
|
|
#region UpdateOverlayBackground
|
|
|
|
private void UpdateOverlayBackground(PieSeriesPointCollection spc)
|
|
{
|
|
if (spc.Count > 0)
|
|
{
|
|
foreach (PieSeriesPoint psp in spc)
|
|
{
|
|
psp.SliceVisualStyles.Default.Background =
|
|
new Background(Color.FromArgb(110, psp.DefaultPaletteColor));
|
|
|
|
UpdateOverlayBackground(psp.SeriesPoints);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region AddPieChart
|
|
|
|
private PieChart AddPieChart()
|
|
{
|
|
PieChart pieChart = new PieChart();
|
|
|
|
if (pieChart != null)
|
|
{
|
|
pieChart.Name = _ChartControl.ChartPanel.ChartContainers.GetUniqueName("PieChart");
|
|
|
|
pieChart.IsExploded = true;
|
|
|
|
SetupPieChartStyle(pieChart);
|
|
SetupContainerStyle(pieChart);
|
|
SetupPieLegend(pieChart);
|
|
|
|
AddChartTitle(pieChart);
|
|
}
|
|
|
|
return (pieChart);
|
|
}
|
|
|
|
#region SetupPieChartStyle
|
|
|
|
private void SetupPieChartStyle(PieChart pieChart)
|
|
{
|
|
PieChartVisualStyle pstyle = pieChart.ChartVisualStyle;
|
|
|
|
pstyle.Background = new Background(Color.White);
|
|
pstyle.BorderThickness = new Thickness(1);
|
|
pstyle.BorderColor = new BorderColor(Color.Black);
|
|
|
|
pstyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(6);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SetupPieLegend
|
|
|
|
private void SetupPieLegend(BaseChart baseChart)
|
|
{
|
|
ChartLegend legend = baseChart.Legend;
|
|
|
|
legend.ShowCheckBoxes = false;
|
|
|
|
legend.Placement = Placement.Outside;
|
|
legend.Alignment = Alignment.BottomCenter;
|
|
legend.Direction = Direction.LeftToRight;
|
|
|
|
legend.AlignVerticalItems = true;
|
|
|
|
legend.MaxVerticalPct = 90;
|
|
|
|
ChartLegendVisualStyle lstyle = legend.ChartLegendVisualStyles.Default;
|
|
|
|
lstyle.BorderThickness = new Thickness(1);
|
|
lstyle.BorderColor = new BorderColor(Color.Black);
|
|
|
|
lstyle.Margin = new DevComponents.DotNetBar.Charts.Style.Padding(4);
|
|
lstyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(4);
|
|
|
|
lstyle.Background = new Background(Color.FromArgb(200, Color.White));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddPieTitle
|
|
|
|
private void AddPieTitle(ChartXy chartXy)
|
|
{
|
|
ChartTitle title = new ChartTitle();
|
|
|
|
title.Name = chartXy.Titles.GetUniqueName();
|
|
|
|
title.Text = "PieChart Title";
|
|
title.XyAlignment = XyAlignment.Top;
|
|
|
|
ChartTitleVisualStyle tstyle = title.ChartTitleVisualStyle;
|
|
|
|
tstyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(8);
|
|
tstyle.Font = new Font("Georgia", 16);
|
|
tstyle.TextColor = Color.Navy;
|
|
tstyle.Alignment = Alignment.MiddleCenter;
|
|
|
|
chartXy.Titles.Add(title);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region InitBlankChart
|
|
|
|
private void InitBlankChart()
|
|
{
|
|
ChartPanel chartPanel = _ChartControl.ChartPanel;
|
|
|
|
chartPanel.EmptyText = "No Charts Defined.";
|
|
|
|
chartPanel.ContainerVisualStyles.Default.BorderColor = new BorderColor(Color.Black);
|
|
chartPanel.ContainerVisualStyles.Default.BorderThickness = new Thickness(1);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitDefaultPlot
|
|
|
|
private ChartSeries InitDefaultPlot(SeriesType seriesType)
|
|
{
|
|
ChartXy chartXy = AddChartXy();
|
|
|
|
if (chartXy != null)
|
|
{
|
|
ChartSeries series = GetNewChartSeries(chartXy, seriesType);
|
|
|
|
if (series != null)
|
|
AddSimulatedData(series);
|
|
|
|
_ChartControl.ChartPanel.ChartContainers.Add(chartXy);
|
|
|
|
chartXy.ChartSeries.Add(series);
|
|
|
|
return (series);
|
|
}
|
|
|
|
return (null);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitMultiAxis
|
|
|
|
private void InitMultiAxis()
|
|
{
|
|
ChartXy chartXy = AddChartXy();
|
|
|
|
if (chartXy != null)
|
|
{
|
|
ChartAxisX axisX = new ChartAxisX();
|
|
axisX.Name = chartXy.AncillaryAxesX.GetUniqueName();
|
|
|
|
chartXy.AncillaryAxesX.Add(axisX);
|
|
|
|
ChartAxisY axisY = new ChartAxisY();
|
|
axisY.Name = chartXy.AncillaryAxesY.GetUniqueName();
|
|
axisY.AxisAlignment = AxisAlignment.Near;
|
|
|
|
chartXy.AncillaryAxesY.Add(axisY);
|
|
|
|
ChartSeries series = GetNewChartSeries(chartXy, SeriesType.Line);
|
|
|
|
if (series != null)
|
|
{
|
|
series.ChartLineDisplayMode = ChartLineDisplayMode.DisplayPoints;
|
|
|
|
AddSimulatedData(series);
|
|
|
|
series.SeriesPoints.Add(new SeriesPoint(0d, 50d));
|
|
series.SeriesPoints.Add(new SeriesPoint(12d, 0d));
|
|
|
|
chartXy.ChartSeries.Add(series);
|
|
}
|
|
|
|
series = GetNewChartSeries(chartXy, SeriesType.Line);
|
|
|
|
if (series != null)
|
|
{
|
|
series.ChartLineDisplayMode = ChartLineDisplayMode.DisplaySpline;
|
|
|
|
AddSimulatedData(series);
|
|
|
|
series.SeriesPoints.Add(new SeriesPoint(0d, 0d));
|
|
series.SeriesPoints.Add(new SeriesPoint(12d, 50d));
|
|
|
|
series.AxisX = axisX;
|
|
series.AxisY = axisY;
|
|
|
|
chartXy.ChartSeries.Add(series);
|
|
}
|
|
|
|
_ChartControl.ChartPanel.ChartContainers.Add(chartXy);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitDotPlot
|
|
|
|
private void InitDotPlot(SeriesType chartType)
|
|
{
|
|
ChartXy chartXy = AddChartXy();
|
|
|
|
if (chartXy != null)
|
|
{
|
|
chartXy.Legend.Alignment = Alignment.TopRight;
|
|
|
|
chartXy.AxisX.MinGridInterval = 20;
|
|
chartXy.AxisY.MinGridInterval = 20;
|
|
|
|
chartXy.AxisX.MinorTickmarks.TickmarkCount = 0;
|
|
chartXy.AxisY.MinorTickmarks.TickmarkCount = 0;
|
|
|
|
chartXy.MinContentSize = new Size(100, 100);
|
|
|
|
ChartSeries series = GetNewChartSeries(chartXy, chartType);
|
|
|
|
if (series != null)
|
|
{
|
|
PointMarkerVisualStyle mstyle = series.ChartSeriesVisualStyle.MarkerVisualStyle;
|
|
|
|
mstyle.Size = new Size(10, 10);
|
|
mstyle.Background = new Background(Color.CornflowerBlue);
|
|
mstyle.BorderColor = Color.Black;
|
|
mstyle.BorderWidth = 1;
|
|
|
|
AddSimulatedDotPlotData(series);
|
|
}
|
|
|
|
_ChartControl.ChartPanel.ChartContainers.Add(chartXy);
|
|
|
|
chartXy.ChartSeries.Add(series);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitMultiChart
|
|
|
|
private void InitMultiChart()
|
|
{
|
|
for (int i = 0; i < 4; i++)
|
|
InitDefaultPlot(SeriesType.Line);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitBubblePlot
|
|
|
|
private void InitBubblePlot()
|
|
{
|
|
ChartXy chartXy = AddChartXy();
|
|
|
|
if (chartXy != null)
|
|
{
|
|
ChartSeries series = GetNewChartSeries(chartXy, SeriesType.Bubble);
|
|
|
|
if (series != null)
|
|
{
|
|
PointMarkerVisualStyle mstyle =
|
|
series.ChartSeriesVisualStyle.MarkerVisualStyle;
|
|
|
|
mstyle.Background = new Background(Color.FromArgb(150, Color.DarkGreen));
|
|
mstyle.BorderWidth = 1;
|
|
mstyle.BorderColor = Color.DarkGreen;
|
|
|
|
AddSimulatedBubbleData(series);
|
|
|
|
chartXy.ChartSeries.Add(series);
|
|
}
|
|
|
|
series = GetNewChartSeries(chartXy, SeriesType.Bubble);
|
|
|
|
if (series != null)
|
|
{
|
|
PointMarkerVisualStyle mstyle =
|
|
series.ChartSeriesVisualStyle.MarkerVisualStyle;
|
|
|
|
mstyle.Background = new Background(Color.FromArgb(150, Color.DarkBlue));
|
|
mstyle.BorderWidth = 1;
|
|
mstyle.BorderColor = Color.DarkBlue;
|
|
|
|
AddSimulatedBubbleData(series);
|
|
|
|
chartXy.ChartSeries.Add(series);
|
|
}
|
|
|
|
_ChartControl.ChartPanel.ChartContainers.Add(chartXy);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitBar
|
|
|
|
private void InitBar(SeriesType seriesType, bool rangeBar)
|
|
{
|
|
ChartXy chartXy = AddChartXy();
|
|
|
|
if (chartXy != null)
|
|
{
|
|
chartXy.BarShadingEnabled = Tbool.True;
|
|
|
|
ChartSeries series = GetNewChartSeries(chartXy, seriesType);
|
|
|
|
if (series != null)
|
|
{
|
|
if (rangeBar == true)
|
|
AddSimulatedRangeData(series);
|
|
else
|
|
AddSimulatedData(series);
|
|
|
|
_ChartControl.ChartPanel.ChartContainers.Add(chartXy);
|
|
|
|
chartXy.ChartSeries.Add(series);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InitHiLoBar
|
|
|
|
private void InitHiLoBar(SeriesType seriesType, HiLoBarType hiloType)
|
|
{
|
|
ChartXy chartXy = AddChartXy();
|
|
|
|
if (chartXy != null)
|
|
{
|
|
chartXy.BarShadingEnabled = Tbool.True;
|
|
|
|
chartXy.AxisX.GridSpacing = 1;
|
|
chartXy.AxisY.GridSpacing = 1;
|
|
|
|
if (seriesType == SeriesType.VerticalHiLoBar)
|
|
{
|
|
chartXy.AxisX.AxisMargins = 0;
|
|
chartXy.AxisX.MinorTickmarks.TickmarkCount = 0;
|
|
chartXy.AxisY.MinorTickmarks.TickmarkCount = 1;
|
|
}
|
|
else
|
|
{
|
|
chartXy.AxisY.AxisMargins = 0;
|
|
chartXy.AxisX.MinorTickmarks.TickmarkCount = 1;
|
|
chartXy.AxisY.MinorTickmarks.TickmarkCount = 0;
|
|
}
|
|
|
|
ChartSeries series = GetNewChartSeries(chartXy, seriesType);
|
|
|
|
if (series != null)
|
|
{
|
|
series.HiLoBarType = hiloType;
|
|
|
|
ChartHiLoBarVisualStyle style = series.ChartSeriesVisualStyle.HiLoBarVisualStyle;
|
|
|
|
style.ShowWhiskerCaps = Tbool.True;
|
|
style.UseAlternateSegmentStyle = Tbool.True;
|
|
|
|
style.DefaultSegmentStyle.BoxBackground = new Background(Color.Green);
|
|
style.DefaultSegmentStyle.Default.LineColor = Color.Green;
|
|
style.DefaultSegmentStyle.Default.LineWidth = 2;
|
|
|
|
style.AlternateSegmentStyle.BoxBackground = new Background(Color.Red);
|
|
style.AlternateSegmentStyle.Default.LineColor = Color.Crimson;
|
|
style.AlternateSegmentStyle.Default.LineWidth = 2;
|
|
|
|
AddSimulatedHiLoData(series);
|
|
|
|
_ChartControl.ChartPanel.ChartContainers.Add(chartXy);
|
|
|
|
chartXy.ChartSeries.Add(series);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SetupScrollBarStyles
|
|
|
|
private void SetupScrollBarStyles()
|
|
{
|
|
ScrollBarVisualStyle moStyle =
|
|
_ChartControl.DefaultVisualStyles.HScrollBarVisualStyles.MouseOver;
|
|
|
|
moStyle.ArrowBackground = new Background(Color.AliceBlue);
|
|
moStyle.ThumbBackground = new Background(Color.AliceBlue);
|
|
|
|
ScrollBarVisualStyle smoStyle =
|
|
_ChartControl.DefaultVisualStyles.HScrollBarVisualStyles.SelectedMouseOver;
|
|
|
|
smoStyle.ArrowBackground = new Background(Color.White);
|
|
smoStyle.ThumbBackground = new Background(Color.White);
|
|
|
|
moStyle = _ChartControl.DefaultVisualStyles.VScrollBarVisualStyles.MouseOver;
|
|
|
|
moStyle.ArrowBackground = new Background(Color.AliceBlue);
|
|
moStyle.ThumbBackground = new Background(Color.AliceBlue);
|
|
|
|
smoStyle = _ChartControl.DefaultVisualStyles.VScrollBarVisualStyles.SelectedMouseOver;
|
|
|
|
smoStyle.ArrowBackground = new Background(Color.White);
|
|
smoStyle.ThumbBackground = new Background(Color.White);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddChartXy
|
|
|
|
private ChartXy AddChartXy()
|
|
{
|
|
ChartXy chartXy = new ChartXy();
|
|
|
|
if (chartXy != null)
|
|
{
|
|
chartXy.Name = _ChartControl.ChartPanel.ChartContainers.GetUniqueName("ChartXy");
|
|
|
|
chartXy.ChartCrosshair.AxisOrientation = AxisOrientation.X;
|
|
|
|
chartXy.ChartCrosshair.ShowValueXLine = true;
|
|
chartXy.ChartCrosshair.ShowValueYLine = true;
|
|
chartXy.ChartCrosshair.ShowValueXLabels = true;
|
|
chartXy.ChartCrosshair.ShowValueYLabels = true;
|
|
|
|
chartXy.ChartCrosshair.HighlightPoints = true;
|
|
|
|
chartXy.ChartCrosshair.ShowCrosshairLabels = true;
|
|
chartXy.ChartCrosshair.CrosshairLabelMode = CrosshairLabelMode.NearestSeries;
|
|
|
|
chartXy.ChartCrosshair.CrosshairVisualStyle.Background = new Background(Color.White);
|
|
|
|
SetupChartStyle(chartXy);
|
|
SetupContainerStyle(chartXy);
|
|
SetupChartAxes(chartXy);
|
|
SetupChartLegend(chartXy);
|
|
|
|
AddChartTitle(chartXy);
|
|
}
|
|
|
|
return (chartXy);
|
|
}
|
|
|
|
#region SetupChartAxes
|
|
|
|
private void SetupChartAxes(ChartXy chartXy)
|
|
{
|
|
// X Axis
|
|
|
|
ChartAxis axis = chartXy.AxisX;
|
|
|
|
axis.MajorGridLines.GridLinesVisualStyle.LineColor = Color.Gainsboro;
|
|
axis.MinorGridLines.GridLinesVisualStyle.LineColor = Color.WhiteSmoke;
|
|
|
|
// Y Axis
|
|
|
|
axis = chartXy.AxisY;
|
|
|
|
axis.AxisAlignment = AxisAlignment.Far;
|
|
|
|
axis.MajorGridLines.GridLinesVisualStyle.LineColor = Color.Gainsboro;
|
|
axis.MinorGridLines.GridLinesVisualStyle.LineColor = Color.WhiteSmoke;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SetupChartStyle
|
|
|
|
private void SetupChartStyle(ChartXy chartXy)
|
|
{
|
|
ChartXyVisualStyle xystyle = chartXy.ChartVisualStyle;
|
|
|
|
xystyle.Background = new Background(Color.White);
|
|
xystyle.BorderThickness = new Thickness(1);
|
|
xystyle.BorderColor = new BorderColor(Color.Black);
|
|
|
|
xystyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(6);
|
|
|
|
ChartSeriesVisualStyle cstyle = chartXy.ChartSeriesVisualStyle;
|
|
PointMarkerVisualStyle pstyle = cstyle.MarkerHighlightVisualStyle;
|
|
|
|
pstyle.Background = new Background(Color.Yellow);
|
|
pstyle.Type = PointMarkerType.Ellipse;
|
|
pstyle.Size = new Size(15, 15);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region SetupContainerStyle
|
|
|
|
private void SetupContainerStyle(BaseChart baseChart)
|
|
{
|
|
ContainerVisualStyle dstyle = baseChart.ContainerVisualStyles.Default;
|
|
|
|
dstyle.Background = new Background(Color.White);
|
|
dstyle.BorderColor = new BorderColor(Color.DimGray);
|
|
dstyle.BorderThickness = new Thickness(1);
|
|
|
|
dstyle.DropShadow.Enabled = Tbool.True;
|
|
dstyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(6);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SetupChartLegend
|
|
|
|
private void SetupChartLegend(BaseChart baseChart)
|
|
{
|
|
ChartLegend legend = baseChart.Legend;
|
|
|
|
legend.ShowCheckBoxes = false;
|
|
legend.Placement = Placement.Inside;
|
|
legend.Alignment = Alignment.TopLeft;
|
|
legend.AlignVerticalItems = true;
|
|
legend.Direction = Direction.LeftToRight;
|
|
|
|
legend.MaxHorizontalPct = 75;
|
|
|
|
ChartLegendVisualStyle lstyle = legend.ChartLegendVisualStyles.Default;
|
|
|
|
lstyle.BorderThickness = new Thickness(1);
|
|
lstyle.BorderColor = new BorderColor(Color.Black);
|
|
|
|
lstyle.Margin = new DevComponents.DotNetBar.Charts.Style.Padding(8);
|
|
lstyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(4);
|
|
|
|
lstyle.Background = new Background(Color.FromArgb(200, Color.White));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddChartTitle
|
|
|
|
private void AddChartTitle(BaseChart baseChart)
|
|
{
|
|
ChartTitle title = new ChartTitle();
|
|
|
|
title.Name = baseChart.Titles.GetUniqueName();
|
|
|
|
title.Text = "Chart Title";
|
|
title.XyAlignment = XyAlignment.Top;
|
|
|
|
ChartTitleVisualStyle tstyle = title.ChartTitleVisualStyle;
|
|
|
|
tstyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(8);
|
|
tstyle.Font = new Font("Georgia", 16);
|
|
tstyle.TextColor = Color.Navy;
|
|
tstyle.Alignment = Alignment.MiddleCenter;
|
|
|
|
baseChart.Titles.Add(title);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetNewChartSeries
|
|
|
|
private ChartSeries GetNewChartSeries(ChartXy chartXy, SeriesType chartType)
|
|
{
|
|
ChartSeries series = new ChartSeries(chartType);
|
|
|
|
if (series != null)
|
|
{
|
|
series.Name = chartXy.ChartSeries.GetUniqueName();
|
|
|
|
series.CrosshairHighlightPoints = Tbool.True;
|
|
}
|
|
|
|
return (series);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetNewPieSeries
|
|
|
|
private PieSeries GetNewPieSeries(PieChart pieChart)
|
|
{
|
|
PieSeries series = new PieSeries();
|
|
|
|
if (series != null)
|
|
series.Name = pieChart.ChartSeries.GetUniqueName();
|
|
|
|
return (series);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddSimulatedData
|
|
|
|
private void AddSimulatedData(ChartSeries series)
|
|
{
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
double d = Convert.ToDouble(i);
|
|
|
|
series.SeriesPoints.Add(
|
|
new SeriesPoint(d, Convert.ToDouble(_Rand.Next(2, 50))));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddSimulatedDotPlotData
|
|
|
|
private void AddSimulatedDotPlotData(ChartSeries series)
|
|
{
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
series.SeriesPoints.Add(
|
|
new SeriesPoint(i, _Rand.Next(0, 10)));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddSimulatedBubbleData
|
|
|
|
private void AddSimulatedBubbleData(ChartSeries series)
|
|
{
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
double d = Convert.ToDouble(i);
|
|
|
|
series.SeriesPoints.Add(
|
|
new SeriesPoint(d,
|
|
Convert.ToDouble(_Rand.Next(0, 10)),
|
|
Convert.ToDouble(_Rand.Next(10, 1000))));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddSimulatedRangeData
|
|
|
|
private void AddSimulatedRangeData(ChartSeries series)
|
|
{
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
double d = Convert.ToDouble(i);
|
|
|
|
double v1 = Convert.ToDouble(_Rand.Next(2, 50));
|
|
double v2 = v1 + Convert.ToDouble(_Rand.Next(10, 20));
|
|
|
|
series.SeriesPoints.Add(new SeriesPoint(d, v1, v2));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddSimulatedHiLoData
|
|
|
|
private void AddSimulatedHiLoData(ChartSeries series)
|
|
{
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
double d = Convert.ToDouble(i);
|
|
|
|
double lo = _Rand.NextDouble() * 5;
|
|
double hi = lo + _Rand.NextDouble() * 5 + 10;
|
|
|
|
double mid = Math.Floor((hi + lo) / 2);
|
|
|
|
double open = mid - _Rand.NextDouble() * 5;
|
|
double close = mid + _Rand.NextDouble() * 5;
|
|
|
|
if (i % 2 == 1)
|
|
{
|
|
double swap = open;
|
|
|
|
open = close;
|
|
close = swap;
|
|
}
|
|
|
|
series.SeriesPoints.Add(new SeriesPoint(d, new object[] { hi, lo, close, open }));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddSimulatedPieData
|
|
|
|
private void AddSimulatedPieData(PieSeries series, int ringCount, bool extent)
|
|
{
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
PieSeriesPoint psp = (extent == true) ?
|
|
new PieSeriesPoint("PX" + i, _Rand.Next(30, 100), _Rand.Next(30, 100)) :
|
|
new PieSeriesPoint("P" + i, _Rand.Next(30, 100));
|
|
|
|
series.SeriesPoints.Add(psp);
|
|
|
|
AddPieRing(psp, ringCount - 1);
|
|
}
|
|
}
|
|
|
|
#region AddPieRing
|
|
|
|
private void AddPieRing(PieSeriesPoint psp, int ringCount)
|
|
{
|
|
if (ringCount > 0)
|
|
{
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
PieSeriesPoint psp2 = new PieSeriesPoint("P" + i, 50);
|
|
|
|
psp.SeriesPoints.Add(psp2);
|
|
|
|
AddPieRing(psp, ringCount - 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region ChangeService
|
|
|
|
#region ChangeService_ComponentChanged
|
|
|
|
void ChangeService_ComponentChanged(object sender, ComponentChangedEventArgs e)
|
|
{
|
|
if (InCopyItem == false)
|
|
{
|
|
_ChartControl.UpdateLayout();
|
|
|
|
if (e.Member != null)
|
|
{
|
|
switch (e.Member.Name)
|
|
{
|
|
case "AncillaryAxesX":
|
|
case "AncillaryAxesY":
|
|
case "ChartContainers":
|
|
case "Location":
|
|
case "Titles":
|
|
case "Visible":
|
|
UpdateGlyphs();
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UpdateGlyphs();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ChangeService_ComponentAdded
|
|
|
|
void ChangeService_ComponentAdded(object sender, ComponentEventArgs e)
|
|
{
|
|
CheckGlyphUse();
|
|
|
|
UpdateGlyphs();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ChangeService_ComponentRemoved
|
|
|
|
void ChangeService_ComponentRemoved(object sender, ComponentEventArgs e)
|
|
{
|
|
CheckGlyphUse();
|
|
|
|
UpdateGlyphs();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CheckGlyphUse
|
|
|
|
private void CheckGlyphUse()
|
|
{
|
|
_UseGlyphs = true;
|
|
|
|
if (_DesignerHost is IContainer)
|
|
{
|
|
foreach (IComponent comp in ((IContainer)_DesignerHost).Components)
|
|
{
|
|
if (comp is ContextMenuStrip)
|
|
{
|
|
_UseGlyphs = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region UpdateGlyphs
|
|
|
|
private void UpdateGlyphs()
|
|
{
|
|
RemoveAdorners();
|
|
|
|
AddContainerGlyphs(_ChartControl.ChartPanel);
|
|
|
|
ICollection ic = _SelectionService.GetSelectedComponents();
|
|
|
|
if (ic != null)
|
|
{
|
|
_SelectionService.SetSelectedComponents(null);
|
|
_SelectionService.SetSelectedComponents(ic);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region RemoveAdorners
|
|
|
|
private void RemoveAdorners()
|
|
{
|
|
List<Adorner> adornerList = new List<Adorner>();
|
|
|
|
for (int i = 0; i < BehaviorService.Adorners.Count; i++)
|
|
{
|
|
Adorner adorner = BehaviorService.Adorners[i];
|
|
|
|
if (adorner.Glyphs != null && adorner.Glyphs.Count > 0)
|
|
{
|
|
SelectionGlyph sg = adorner.Glyphs[0] as SelectionGlyph;
|
|
|
|
if (sg != null && sg.ControlDesigner == this)
|
|
adornerList.Add(adorner);
|
|
}
|
|
}
|
|
|
|
foreach (Adorner ad in adornerList)
|
|
{
|
|
for (int i = ad.Glyphs.Count - 1; i >= 0; i--)
|
|
{
|
|
SelectionGlyph sg = (SelectionGlyph)ad.Glyphs[i];
|
|
|
|
ad.Glyphs.RemoveAt(i);
|
|
|
|
sg.Dispose();
|
|
}
|
|
|
|
BehaviorService.Adorners.Remove(ad);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ActionLists
|
|
|
|
/// <summary>
|
|
/// Gets our DesignerActionListCollection list
|
|
/// </summary>
|
|
public override DesignerActionListCollection ActionLists
|
|
{
|
|
get
|
|
{
|
|
if (_ActionLists == null)
|
|
{
|
|
_ActionLists = new DesignerActionListCollection();
|
|
|
|
_ActionLists.Add(new ChartControlActionList(_ChartControl));
|
|
}
|
|
|
|
return (_ActionLists);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Load complete
|
|
|
|
private void DhLoadComplete(object sender, EventArgs e)
|
|
{
|
|
IDesignerHost dh = GetService(typeof(IDesignerHost)) as IDesignerHost;
|
|
|
|
if (dh != null)
|
|
dh.LoadComplete -= DhLoadComplete;
|
|
|
|
ChartControl chartControl = Control as ChartControl;
|
|
|
|
if (chartControl != null)
|
|
{
|
|
CheckGlyphUse();
|
|
|
|
ValidateLicenseKey(chartControl);
|
|
|
|
AddContainerGlyphs(chartControl.ChartPanel);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddContainerGlyphs
|
|
|
|
private void AddContainerGlyphs(ChartContainer cc)
|
|
{
|
|
if (_UseGlyphs == true)
|
|
{
|
|
if (cc.Visible == true)
|
|
{
|
|
AddSelectionAdorner(cc);
|
|
|
|
if (cc.Legend.Visible == true)
|
|
AddSelectionAdorner(cc.Legend);
|
|
|
|
if (cc.Titles != null)
|
|
{
|
|
foreach (ChartTitle title in cc.Titles)
|
|
{
|
|
if (title.Visible == true)
|
|
AddSelectionAdorner(title);
|
|
}
|
|
}
|
|
|
|
if (cc is ChartPanel)
|
|
{
|
|
ChartPanel cp = (ChartPanel)cc;
|
|
|
|
foreach (ChartContainer cont in cp.ChartContainers)
|
|
{
|
|
if (cont.Visible == true)
|
|
AddContainerGlyphs(cont);
|
|
}
|
|
}
|
|
else if (cc is ChartXy)
|
|
{
|
|
ChartXy chartXy = (ChartXy)cc;
|
|
|
|
if (chartXy.AxisX.Visible == true)
|
|
AddSelectionAdorner(chartXy.AxisX);
|
|
|
|
if (chartXy.AxisY.Visible == true)
|
|
AddSelectionAdorner(chartXy.AxisY);
|
|
|
|
foreach (ChartAxis axis in chartXy.AncillaryAxesX)
|
|
{
|
|
if (axis.Visible == true)
|
|
AddSelectionAdorner(axis);
|
|
}
|
|
|
|
foreach (ChartAxis axis in chartXy.AncillaryAxesY)
|
|
{
|
|
if (axis.Visible == true)
|
|
AddSelectionAdorner(axis);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#region AddSelectionAdorner
|
|
|
|
private void AddSelectionAdorner(ChartVisualElement visualItem)
|
|
{
|
|
if (visualItem.Visible == true)
|
|
{
|
|
Adorner adorner = new Adorner();
|
|
|
|
adorner.Glyphs.Add(new SelectionGlyph(this, visualItem, adorner));
|
|
|
|
BehaviorService.Adorners.Add(adorner);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region OnSetCursor
|
|
|
|
protected override void OnSetCursor()
|
|
{
|
|
if (ToolboxService == null ||
|
|
ToolboxService.GetSelectedToolboxItem() == null)
|
|
{
|
|
if (DragMoving == true)
|
|
{
|
|
Cursor.Current = Cursors.SizeAll;
|
|
}
|
|
else
|
|
{
|
|
if (SelectionBehavior.ContextMenuActive == true)
|
|
Cursor.Current = Cursors.Arrow;
|
|
else
|
|
base.OnSetCursor();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Control ctl1 = (Control)Component;
|
|
|
|
Form form = ctl1.FindForm();
|
|
|
|
if (form != null)
|
|
base.OnSetCursor();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OnMouseDragBegin
|
|
|
|
protected override void OnMouseDragBegin(int x, int y)
|
|
{
|
|
DragMoving = true;
|
|
|
|
base.OnMouseDragBegin(x, y);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OnMouseDragEnd
|
|
|
|
protected override void OnMouseDragEnd(bool cancel)
|
|
{
|
|
DragMoving = false;
|
|
|
|
base.OnMouseDragEnd(cancel);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetLicenseKey
|
|
|
|
#if !TRIAL
|
|
private string GetLicenseKey()
|
|
{
|
|
string key = "";
|
|
|
|
RegistryKey regkey =
|
|
Registry.LocalMachine.OpenSubKey("Software\\DevComponents\\Licenses", false);
|
|
|
|
if (regkey != null)
|
|
{
|
|
object keyValue = regkey.GetValue("DevComponents.DotNetBar.DotNetBarManager2");
|
|
|
|
if (keyValue != null)
|
|
key = keyValue.ToString();
|
|
}
|
|
|
|
return (key);
|
|
}
|
|
#endif
|
|
|
|
#endregion
|
|
|
|
#region ValidateLicenseKey
|
|
|
|
private void ValidateLicenseKey(ChartControl chartControl)
|
|
{
|
|
#if !TRIAL
|
|
string key = GetLicenseKey();
|
|
|
|
if (key != "" && chartControl != null && chartControl.LicenseKey == "" && chartControl.LicenseKey != key)
|
|
TypeDescriptor.GetProperties(chartControl)["LicenseKey"].SetValue(chartControl, key);
|
|
#endif
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SelectionGlyph
|
|
|
|
public class SelectionGlyph : Glyph, IDisposable
|
|
{
|
|
#region Private variables
|
|
|
|
private ChartControlDesigner _ControlDesigner;
|
|
|
|
private Adorner _SelectionAdorner;
|
|
private Control _RelatedControl;
|
|
|
|
private Rectangle _Bounds;
|
|
private ChartVisualElement _VisualItem;
|
|
|
|
private bool _IsSelected;
|
|
|
|
private Brush _SelBrush;
|
|
private Brush _SelBrush2;
|
|
|
|
#endregion
|
|
|
|
public SelectionGlyph(ChartControlDesigner controlDesigner, ChartVisualElement visualItem, Adorner selectionAdorner)
|
|
: base(new SelectionBehavior(controlDesigner))
|
|
{
|
|
_VisualItem = visualItem;
|
|
_ControlDesigner = controlDesigner;
|
|
_SelectionAdorner = selectionAdorner;
|
|
|
|
_RelatedControl = _ControlDesigner.Component as Control;
|
|
|
|
_ControlDesigner.SelectionService.SelectionChanged += SelectionService_SelectionChanged;
|
|
_ControlDesigner.ChangeService.ComponentChanged += ChangeService_ComponentChanged;
|
|
|
|
_VisualItem.ChartControl.UpdateLayout();
|
|
|
|
CalcGlyphBounds();
|
|
}
|
|
|
|
#region Public properties
|
|
|
|
#region Bounds
|
|
|
|
public override Rectangle Bounds
|
|
{
|
|
get { return (_Bounds); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ControlDesigner
|
|
|
|
public ChartControlDesigner ControlDesigner
|
|
{
|
|
get { return (_ControlDesigner); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SelectionAdorner
|
|
|
|
public Adorner SelectionAdorner
|
|
{
|
|
get { return (_SelectionAdorner); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region VisualItem
|
|
|
|
public ChartVisualElement VisualItem
|
|
{
|
|
get { return (_VisualItem); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Private properties
|
|
|
|
#region SelBrush
|
|
|
|
private Brush SelBrush
|
|
{
|
|
get
|
|
{
|
|
if (_SelBrush == null)
|
|
{
|
|
_SelBrush = new HatchBrush(HatchStyle.BackwardDiagonal,
|
|
Color.FromArgb(20, Color.Purple), Color.Transparent);
|
|
}
|
|
|
|
return (_SelBrush);
|
|
}
|
|
|
|
set
|
|
{
|
|
if (_SelBrush != null)
|
|
_SelBrush.Dispose();
|
|
|
|
_SelBrush = null;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SelBrush2
|
|
|
|
private Brush SelBrush2
|
|
{
|
|
get
|
|
{
|
|
if (_SelBrush2 == null)
|
|
{
|
|
_SelBrush2 = new HatchBrush(HatchStyle.BackwardDiagonal,
|
|
Color.FromArgb(60, Color.White), Color.Transparent);
|
|
}
|
|
|
|
return (_SelBrush2);
|
|
}
|
|
|
|
set
|
|
{
|
|
if (_SelBrush2 != null)
|
|
_SelBrush2.Dispose();
|
|
|
|
_SelBrush2 = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Paint
|
|
|
|
public override void Paint(PaintEventArgs e)
|
|
{
|
|
if (_ControlDesigner.SelectionService.GetComponentSelected(_VisualItem) == true)
|
|
{
|
|
Graphics g = e.Graphics;
|
|
|
|
int n = (_VisualItem is ChartPanel || _VisualItem is ChartXy) ? -2 : 2;
|
|
|
|
Rectangle r = Bounds;
|
|
r.Inflate(n, n);
|
|
|
|
g.RenderingOrigin = new Point(1, 0);
|
|
g.FillRectangle(SelBrush, r);
|
|
|
|
g.RenderingOrigin = new Point(0, 0);
|
|
g.FillRectangle(SelBrush2, r);
|
|
|
|
ControlPaint.DrawFocusRectangle(g, r);
|
|
|
|
r.Inflate(1, 1);
|
|
|
|
using (Pen pen = new Pen(Color.FromArgb(170, Color.White)))
|
|
{
|
|
pen.DashStyle = DashStyle.Dot;
|
|
|
|
r.Height--;
|
|
r.Width--;
|
|
|
|
g.DrawRectangle(pen, r);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetHitTest
|
|
|
|
public override Cursor GetHitTest(Point p)
|
|
{
|
|
Control control = GetIt(p);
|
|
|
|
if (control == _RelatedControl)
|
|
{
|
|
if (control.Parent != null && control.Parent.Visible == true)
|
|
{
|
|
ChartControlDesigner ccd = _ControlDesigner;
|
|
|
|
if (ccd.ToolboxService == null ||
|
|
ccd.ToolboxService.GetSelectedToolboxItem() == null)
|
|
{
|
|
if (ccd.DragMoving == false)
|
|
{
|
|
if (Bounds.Contains(p))
|
|
return (Cursors.Hand);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return (null);
|
|
}
|
|
|
|
#region GetIt
|
|
|
|
private Control GetIt(Point pt)
|
|
{
|
|
if (_RelatedControl != null)
|
|
{
|
|
Control ctl = _RelatedControl.Parent;
|
|
Control ctl2 = _ControlDesigner.DesignerHost.RootComponent as Control;
|
|
|
|
if (ctl != null && ctl2 != null && ctl2.Parent != null)
|
|
{
|
|
Point pt1 = ctl.PointToScreen(Point.Empty);
|
|
Point pt2 = ctl2.Parent.PointToScreen(ctl2.Parent.Location);
|
|
|
|
pt.X -= (pt1.X - pt2.X);
|
|
pt.Y -= (pt1.Y - pt2.Y);
|
|
|
|
return (ctl.GetChildAtPoint(pt));
|
|
}
|
|
}
|
|
|
|
return (null);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region SelectionService_SelectionChanged
|
|
|
|
void SelectionService_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
bool selected = _ControlDesigner.SelectionService.GetComponentSelected(_VisualItem);
|
|
|
|
if (selected == true)
|
|
CalcGlyphBounds();
|
|
|
|
if (_IsSelected != selected)
|
|
{
|
|
_IsSelected = selected;
|
|
|
|
Control ctl = _ControlDesigner.DesignerHost.RootComponent as Control;
|
|
|
|
if (ctl != null)
|
|
ctl.Invalidate(true);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ChangeService_ComponentChanged
|
|
|
|
void ChangeService_ComponentChanged(object sender, ComponentChangedEventArgs e)
|
|
{
|
|
if (_ControlDesigner.InCopyItem == false)
|
|
{
|
|
if (_IsSelected == true)
|
|
{
|
|
if (_VisualItem != null && _VisualItem.ChartControl != null)
|
|
{
|
|
_VisualItem.ChartControl.UpdateLayout();
|
|
|
|
CalcGlyphBounds();
|
|
|
|
_RelatedControl.Invalidate();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CalcGlyphBounds
|
|
|
|
private void CalcGlyphBounds()
|
|
{
|
|
Rectangle bounds = _VisualItem.Bounds;
|
|
|
|
if (_RelatedControl != null)
|
|
{
|
|
if (_VisualItem is ChartContainer)
|
|
{
|
|
ChartContainer cc = (ChartContainer)_VisualItem;
|
|
|
|
bounds = GetAdjustedBounds(bounds, cc.EffectiveContainerStyles[StyleType.Default].Margin);
|
|
}
|
|
else if (_VisualItem is ChartXy)
|
|
{
|
|
ChartXy bc = (ChartXy)_VisualItem;
|
|
|
|
bounds = GetAdjustedBounds(bounds, bc.EffectiveChartStyle.Margin);
|
|
}
|
|
else if (_VisualItem is ChartTitle)
|
|
{
|
|
ChartTitle ct = (ChartTitle)_VisualItem;
|
|
|
|
bounds = GetAdjustedBounds(bounds, ct.EffectiveTitleStyle.Margin);
|
|
}
|
|
|
|
Point pt = _ControlDesigner.BehaviorService.ControlToAdornerWindow(_RelatedControl);
|
|
|
|
bounds.Offset(pt);
|
|
}
|
|
|
|
_Bounds = bounds;
|
|
}
|
|
|
|
#region GetAdjustedBounds
|
|
|
|
internal Rectangle GetAdjustedBounds(Rectangle bounds, Thickness padding)
|
|
{
|
|
if (padding.IsEmpty == false)
|
|
{
|
|
if (bounds.Height > padding.Vertical)
|
|
{
|
|
bounds.Y += padding.Top;
|
|
bounds.Height -= padding.Vertical;
|
|
}
|
|
|
|
if (bounds.Width > padding.Horizontal)
|
|
{
|
|
bounds.X += padding.Left;
|
|
bounds.Width -= padding.Horizontal;
|
|
}
|
|
}
|
|
|
|
return (bounds);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Dispose
|
|
|
|
public void Dispose()
|
|
{
|
|
SelBrush = null;
|
|
SelBrush2 = null;
|
|
|
|
if (_ControlDesigner != null)
|
|
{
|
|
_ControlDesigner.SelectionService.SelectionChanged -= SelectionService_SelectionChanged;
|
|
_ControlDesigner.ChangeService.ComponentChanged -= ChangeService_ComponentChanged;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SelectionBehavior
|
|
|
|
internal class SelectionBehavior : Behavior
|
|
{
|
|
#region Static variables
|
|
|
|
static public bool ContextMenuActive;
|
|
|
|
#endregion
|
|
|
|
#region Private variables
|
|
|
|
private IDesigner _ControlDesigner;
|
|
private Control _RelatedControl;
|
|
private Point _DragPoint;
|
|
private bool _MouseDown;
|
|
|
|
#endregion
|
|
|
|
internal SelectionBehavior(IDesigner controlDesigner)
|
|
{
|
|
_ControlDesigner = controlDesigner;
|
|
_RelatedControl = controlDesigner.Component as Control;
|
|
}
|
|
|
|
#region OnMouseDown
|
|
|
|
public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
|
|
{
|
|
SelectionGlyph sg = g as SelectionGlyph;
|
|
|
|
if (button == MouseButtons.Left)
|
|
{
|
|
if (sg.ControlDesigner.SelectionService.GetComponentSelected(sg.VisualItem) == false)
|
|
{
|
|
if (ContextMenuActive == false)
|
|
SelectVisualElement(sg, sg.VisualItem);
|
|
}
|
|
}
|
|
else if (button == MouseButtons.Right)
|
|
{
|
|
object primarySelection = sg.ControlDesigner.SelectionService.PrimarySelection;
|
|
|
|
if (CanSelectVisualItem(primarySelection, sg.VisualItem) == true)
|
|
SelectVisualElement(sg, sg.VisualItem);
|
|
}
|
|
|
|
ContextMenuActive = false;
|
|
|
|
_DragPoint = Control.MousePosition;
|
|
|
|
_MouseDown = true;
|
|
|
|
return (true);
|
|
}
|
|
|
|
#region CanSelectVisualItem
|
|
|
|
private bool CanSelectVisualItem(
|
|
object primarySelection, ChartVisualElement cve)
|
|
{
|
|
if (cve is ChartLegend || cve is ChartTitle || cve is ChartAxis)
|
|
return (true);
|
|
|
|
if (primarySelection == null)
|
|
return (true);
|
|
|
|
if (primarySelection is ChartControl)
|
|
return (false);
|
|
|
|
ChartVisualElement pcve = primarySelection as ChartVisualElement;
|
|
|
|
if (pcve == null)
|
|
return (true);
|
|
|
|
return (IsChildItem(cve, pcve) == false);
|
|
}
|
|
|
|
#region IsChildItem
|
|
|
|
private bool IsChildItem(ChartVisualElement cve, ChartVisualElement pcve)
|
|
{
|
|
ChartVisualElement parent = cve.Parent as ChartVisualElement;
|
|
|
|
while (parent != null)
|
|
{
|
|
if (parent == pcve)
|
|
return (true);
|
|
|
|
parent = parent.Parent as ChartVisualElement;
|
|
}
|
|
|
|
return (false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region SelectVisualElement
|
|
|
|
private void SelectVisualElement(SelectionGlyph sg, ChartVisualElement cve)
|
|
{
|
|
if (cve != null)
|
|
sg.ControlDesigner.SelectionService.SetSelectedComponents(new object[] { cve });
|
|
else
|
|
sg.ControlDesigner.SelectionService.SetSelectedComponents(new object[] { _RelatedControl });
|
|
|
|
_RelatedControl.Invalidate();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region OnMouseUp
|
|
|
|
public override bool OnMouseUp(Glyph g, MouseButtons button)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
_MouseDown = false;
|
|
|
|
bool value = base.OnMouseUp(g, button);
|
|
|
|
if (button == MouseButtons.Right)
|
|
{
|
|
SelectionGlyph sg = g as SelectionGlyph;
|
|
|
|
if (sg != null)
|
|
{
|
|
if (ShowGlyphContextMenu(g as SelectionGlyph) == true)
|
|
return (true);
|
|
|
|
return (true);
|
|
}
|
|
}
|
|
|
|
return (value);
|
|
}
|
|
|
|
#region ShowGlyphContextMenu
|
|
|
|
private bool ShowGlyphContextMenu(SelectionGlyph sg)
|
|
{
|
|
if (sg != null)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
Point pt = _RelatedControl.PointToClient(Control.MousePosition);
|
|
|
|
ContextMenu cm = GetContextMenu(sg, ccd);
|
|
|
|
if (cm != null)
|
|
{
|
|
ContextMenuActive = true;
|
|
|
|
cm.Show(_RelatedControl, pt);
|
|
|
|
return (true);
|
|
}
|
|
}
|
|
|
|
return (false);
|
|
}
|
|
|
|
#region GetContextMenu
|
|
|
|
private ContextMenu GetContextMenu(SelectionGlyph sg, ChartControlDesigner ccd)
|
|
{
|
|
ContextMenu cm = new ContextMenu();
|
|
|
|
MenuItem mi = AddMenuItem(cm, null, "View Code", new EventHandler(MenuViewCode));
|
|
|
|
ChartVisualElement cve = ccd.SelectionService.PrimarySelection as ChartVisualElement;
|
|
|
|
if (cve != null)
|
|
{
|
|
AddMenuItem(cm, cve, "-", null);
|
|
|
|
if (cve is ChartPanel)
|
|
{
|
|
AddMenuItem(cm, cve, "Hide Panel", new EventHandler(HideVisualItem));
|
|
|
|
if (cve.Parent != null)
|
|
AddMenuItem(cm, cve, "Delete Panel", new EventHandler(DeleteChartPanel));
|
|
}
|
|
else if (cve is BaseChart)
|
|
{
|
|
AddMenuItem(cm, cve, "Hide Chart", new EventHandler(HideVisualItem));
|
|
AddMenuItem(cm, cve, "Delete Chart", new EventHandler(DeleteChartPanel));
|
|
}
|
|
else if (cve is ChartTitle)
|
|
{
|
|
AddMenuItem(cm, cve, "Hide Title", new EventHandler(HideVisualItem));
|
|
AddMenuItem(cm, cve, "Delete Title", new EventHandler(DeleteTitle));
|
|
AddMenuItem(cm, cve, "-", null);
|
|
|
|
mi = AddMenuItem(cm, cve, "XyAlignment", null);
|
|
|
|
AddSubMenuItem(mi, cve, "Top", new EventHandler(AlignTitleTop));
|
|
AddSubMenuItem(mi, cve, "Left", new EventHandler(AlignTitleLeft));
|
|
AddSubMenuItem(mi, cve, "Bottom", new EventHandler(AlignTitleBottom));
|
|
AddSubMenuItem(mi, cve, "Right", new EventHandler(AlignTitleRight));
|
|
}
|
|
else if (cve is ChartAxis)
|
|
{
|
|
ChartAxis axis = (ChartAxis)cve;
|
|
|
|
AddMenuItem(cm, cve, "Hide Axis", new EventHandler(HideVisualItem));
|
|
|
|
if (axis.IsPrimaryAxis == false)
|
|
AddMenuItem(cm, cve, "Delete Axis", new EventHandler(DeleteAxis));
|
|
|
|
AddMenuItem(cm, cve, "-", null);
|
|
|
|
mi = AddMenuItem(cm, cve, "Alignment", null);
|
|
|
|
AddSubMenuItem(mi, cve, "Near", new EventHandler(AlignAxisNear));
|
|
AddSubMenuItem(mi, cve, "Far", new EventHandler(AlignAxisFar));
|
|
}
|
|
else if (cve is ChartLegend)
|
|
{
|
|
ChartLegend legend = (ChartLegend)cve;
|
|
|
|
AddMenuItem(cm, cve, "Hide Legend", new EventHandler(HideVisualItem));
|
|
}
|
|
}
|
|
|
|
AddMenuItem(cm, null, "-", null);
|
|
|
|
int n = cm.MenuItems.Count;
|
|
|
|
AddParentSelect(cm, ccd.SelectionService.PrimarySelection);
|
|
|
|
if (cm.MenuItems.Count == n)
|
|
cm.MenuItems.RemoveAt(cm.MenuItems.Count - 1);
|
|
|
|
return (cm);
|
|
}
|
|
|
|
#region AddMenuItem
|
|
|
|
private MenuItem AddMenuItem(ContextMenu cm,
|
|
ChartVisualElement cve, string text, EventHandler e)
|
|
{
|
|
MenuItem mi = new MenuItem(text, e);
|
|
|
|
mi.Tag = cve;
|
|
|
|
cm.MenuItems.Add(mi);
|
|
|
|
return (mi);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddSubMenuItem
|
|
|
|
private MenuItem AddSubMenuItem(MenuItem mi,
|
|
ChartVisualElement cve, string text, EventHandler e)
|
|
{
|
|
MenuItem submi = new MenuItem(text, e);
|
|
|
|
submi.Tag = cve;
|
|
|
|
mi.MenuItems.Add(submi);
|
|
|
|
return (submi);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AddParentSelect
|
|
|
|
private void AddParentSelect(ContextMenu cm, object psel)
|
|
{
|
|
ChartVisualElement cve = psel as ChartVisualElement;
|
|
|
|
if (cve != null)
|
|
{
|
|
ChartVisualElement parent = cve.Parent as ChartVisualElement;
|
|
|
|
while (parent != null)
|
|
{
|
|
if (string.IsNullOrEmpty(parent.Name) == false)
|
|
{
|
|
AddMenuItem(cm, parent,
|
|
"Select '" + parent.Name + "'", new EventHandler(SelectVisualItem));
|
|
}
|
|
|
|
parent = parent.Parent as ChartVisualElement;
|
|
}
|
|
|
|
string s = string.IsNullOrEmpty(_RelatedControl.Name)
|
|
? "ChartControl" : _RelatedControl.Name;
|
|
|
|
AddMenuItem(cm, null,
|
|
"Select '" + s + "'", new EventHandler(SelectVisualItem));
|
|
}
|
|
|
|
Control ctl = _RelatedControl.Parent;
|
|
|
|
while (ctl != null)
|
|
{
|
|
if (string.IsNullOrEmpty(ctl.Name) == false)
|
|
{
|
|
MenuItem mi = AddMenuItem(cm, null,
|
|
"Select '" + ctl.Name + "'", new EventHandler(SelectControl));
|
|
|
|
mi.Tag = ctl;
|
|
}
|
|
|
|
ctl = ctl.Parent;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Item click support
|
|
|
|
#region SelectVisualItem
|
|
|
|
private void SelectVisualItem(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
ChartVisualElement cve = mi.Tag as ChartVisualElement;
|
|
|
|
if (cve != null)
|
|
ccd.SelectionService.SetSelectedComponents(new object[] { cve });
|
|
else
|
|
ccd.SelectionService.SetSelectedComponents(new object[] { _RelatedControl });
|
|
}
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SelectControl
|
|
|
|
private void SelectControl(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
ccd.SelectionService.SetSelectedComponents(new object[] { mi.Tag });
|
|
}
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AlignAxis
|
|
|
|
#region AlignAxisNear
|
|
|
|
private void AlignAxisNear(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
{
|
|
ChartAxis axis = mi.Tag as ChartAxis;
|
|
|
|
if (axis != null)
|
|
SetValue(axis, "AxisAlignment", AxisAlignment.Near);
|
|
}
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AlignAxisFar
|
|
|
|
private void AlignAxisFar(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
{
|
|
ChartAxis axis = mi.Tag as ChartAxis;
|
|
|
|
if (axis != null)
|
|
SetValue(axis, "AxisAlignment", AxisAlignment.Far);
|
|
}
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region AlignTitle
|
|
|
|
private void AlignTitleTop(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
AlignTitle(mi.Tag as ChartTitle, XyAlignment.Top);
|
|
}
|
|
|
|
private void AlignTitleLeft(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
AlignTitle(mi.Tag as ChartTitle, XyAlignment.Left);
|
|
}
|
|
|
|
private void AlignTitleBottom(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
AlignTitle(mi.Tag as ChartTitle, XyAlignment.Bottom);
|
|
}
|
|
|
|
private void AlignTitleRight(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
AlignTitle(mi.Tag as ChartTitle, XyAlignment.Right);
|
|
}
|
|
|
|
private void AlignTitle(ChartTitle title, XyAlignment xyAlignment)
|
|
{
|
|
if (title != null)
|
|
SetValue(title, "XyAlignment", xyAlignment);
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DeleteAxis
|
|
|
|
private void DeleteAxis(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
{
|
|
ChartAxis axis = mi.Tag as ChartAxis;
|
|
|
|
if (axis != null)
|
|
{
|
|
ChartXy chartXy = axis.Parent as ChartXy;
|
|
|
|
if (chartXy != null)
|
|
{
|
|
DialogResult result = MessageBoxEx.Show(
|
|
"Are you sure you want to delete the selected Axis?",
|
|
"Confirm Delete", MessageBoxButtons.YesNo);
|
|
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
ccd.ChangeService.OnComponentChanging(chartXy, null);
|
|
|
|
if (axis.AxisOrientation == AxisOrientation.X)
|
|
chartXy.AncillaryAxesX.Remove(axis);
|
|
else
|
|
chartXy.AncillaryAxesY.Remove(axis);
|
|
|
|
//axis.Dispose();
|
|
|
|
ccd.ChangeService.OnComponentChanged(chartXy, null, null, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DeleteTitle
|
|
|
|
private void DeleteTitle(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
{
|
|
ChartTitle title = mi.Tag as ChartTitle;
|
|
|
|
if (title != null)
|
|
{
|
|
ChartContainer parent = title.Parent as ChartContainer;
|
|
|
|
if (parent != null)
|
|
{
|
|
DialogResult result = MessageBoxEx.Show(
|
|
"Are you sure you want to delete the selected Title?",
|
|
"Confirm Delete", MessageBoxButtons.YesNo);
|
|
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
ccd.ChangeService.OnComponentChanging(parent.Titles, null);
|
|
|
|
parent.Titles.Remove(title);
|
|
//title.Dispose();
|
|
|
|
ccd.ChangeService.OnComponentChanged(parent.Titles, null, null, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DeleteChartPanel
|
|
|
|
private void DeleteChartPanel(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
{
|
|
ChartContainer cc = mi.Tag as ChartContainer;
|
|
|
|
if (cc != null)
|
|
{
|
|
ChartPanel parent = cc.Parent as ChartPanel;
|
|
|
|
if (parent != null)
|
|
{
|
|
DialogResult result = MessageBoxEx.Show(
|
|
"Are you sure you want to delete the selected " +
|
|
(cc is ChartPanel ? "ChartPanel?" : "Chart?"),
|
|
"Confirm Delete", MessageBoxButtons.YesNo);
|
|
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
ccd.ChangeService.OnComponentChanging(parent.ChartContainers, null);
|
|
|
|
parent.ChartContainers.Remove(cc);
|
|
//cc.Dispose();
|
|
|
|
ccd.ChangeService.OnComponentChanged(parent.ChartContainers, null, null, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region HideVisualItem
|
|
|
|
private void HideVisualItem(object sender, EventArgs e)
|
|
{
|
|
MenuItem mi = sender as MenuItem;
|
|
|
|
if (mi != null)
|
|
{
|
|
ChartVisualElement cve = mi.Tag as ChartVisualElement;
|
|
|
|
if (cve != null)
|
|
SetValue(cve, "Visible", false);
|
|
}
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region MenuViewCode
|
|
|
|
private void MenuViewCode(object sender, EventArgs e)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
IMenuCommandService mcs = ccd.MenuCommandService;
|
|
|
|
mcs.GlobalInvoke(StandardCommands.ViewCode);
|
|
|
|
SelectionBehavior.ContextMenuActive = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region OnMouseMove
|
|
|
|
public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
|
|
{
|
|
if (Control.MouseButtons == 0)
|
|
_MouseDown = false;
|
|
|
|
if (_MouseDown == true && Control.MouseButtons != 0)
|
|
{
|
|
Point pt = Control.MousePosition;
|
|
|
|
if (Math.Abs(_DragPoint.X - pt.X) > 4 || Math.Abs(_DragPoint.Y - pt.Y) > 4)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
ccd.OnMouseDragBegin(pt.X, pt.Y);
|
|
|
|
return (true);
|
|
}
|
|
}
|
|
|
|
return base.OnMouseMove(g, button, mouseLoc);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SetValue
|
|
|
|
private void SetValue(object item, string property, object value)
|
|
{
|
|
ChartControlDesigner ccd = (ChartControlDesigner)_ControlDesigner;
|
|
|
|
ccd.ChangeService.OnComponentChanging(item, null);
|
|
|
|
GetPropertyByName(item, property).SetValue(item, value);
|
|
|
|
ccd.ChangeService.OnComponentChanged(item, null, null, null);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetPropertyByName
|
|
|
|
private PropertyDescriptor GetPropertyByName(object item, string propName)
|
|
{
|
|
PropertyDescriptor prop =
|
|
TypeDescriptor.GetProperties(item)[propName];
|
|
|
|
if (prop == null)
|
|
throw new ArgumentException("Matching property not found.", propName);
|
|
|
|
return (prop);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Dispose
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
if (ChangeService != null)
|
|
{
|
|
ChangeService.ComponentChanged -= ChangeService_ComponentChanged;
|
|
ChangeService.ComponentAdded -= ChangeService_ComponentAdded;
|
|
ChangeService.ComponentRemoved -= ChangeService_ComponentRemoved;
|
|
}
|
|
|
|
if (BehaviorService != null)
|
|
RemoveAdorners();
|
|
}
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|