175 lines
5.1 KiB
C#
175 lines
5.1 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.Design;
|
|
using System.Drawing;
|
|
using System.Drawing.Design;
|
|
using System.Reflection;
|
|
using DevComponents.DotNetBar.Charts;
|
|
using DevComponents.DotNetBar.Charts.Style;
|
|
|
|
namespace DevComponents.Charts.Design
|
|
{
|
|
public class ChartContainerCollectionEditor : BaseCollectionEditor
|
|
{
|
|
#region Private variables
|
|
|
|
private ChartPanel _ChartPanel;
|
|
|
|
#endregion
|
|
|
|
public ChartContainerCollectionEditor(Type type)
|
|
: base(type)
|
|
{
|
|
}
|
|
|
|
#region EditValue
|
|
|
|
public override object EditValue(
|
|
ITypeDescriptorContext context, IServiceProvider provider, object value)
|
|
{
|
|
_ChartPanel = context.Instance as ChartPanel;
|
|
|
|
object retval = base.EditValue(context, provider, value);
|
|
|
|
return (retval);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreateInstance
|
|
|
|
protected override object CreateInstance(Type itemType)
|
|
{
|
|
if (itemType == typeof(ChartXy))
|
|
{
|
|
ChartXy chartXy = (ChartXy)base.CreateInstance(itemType);
|
|
|
|
if (_ChartPanel != null)
|
|
chartXy.Name = _ChartPanel.ChartContainers.GetUniqueName("ChartXy");
|
|
|
|
SetChartDefaults(chartXy);
|
|
|
|
return (chartXy);
|
|
}
|
|
|
|
if (itemType == typeof(PieChart))
|
|
{
|
|
PieChart pieChart = (PieChart)base.CreateInstance(itemType);
|
|
|
|
if (_ChartPanel != null)
|
|
pieChart.Name = _ChartPanel.ChartContainers.GetUniqueName("PieChart");
|
|
|
|
SetChartDefaults(pieChart);
|
|
|
|
return (pieChart);
|
|
}
|
|
|
|
if (itemType == typeof(ChartPanel))
|
|
{
|
|
ChartPanel panel = (ChartPanel)base.CreateInstance(itemType);
|
|
|
|
if (_ChartPanel != null)
|
|
panel.Name = _ChartPanel.ChartContainers.GetUniqueName("ChartPanel");
|
|
|
|
SetPanelDefaults(panel);
|
|
|
|
return (panel);
|
|
}
|
|
|
|
return (base.CreateInstance(itemType));
|
|
}
|
|
|
|
private void SetPanelDefaults(ChartPanel panel)
|
|
{
|
|
panel.ContainerVisualStyles.Default.BorderThickness = new Thickness(1);
|
|
panel.ContainerVisualStyles.Default.BorderColor = new BorderColor(Color.Black);
|
|
panel.ContainerVisualStyles.Default.Background = new Background(Color.Gray);
|
|
panel.ContainerVisualStyles.Default.Margin = new Padding(4);
|
|
}
|
|
|
|
private void SetChartDefaults(ChartXy chartXy)
|
|
{
|
|
chartXy.ContainerVisualStyles.Default.BorderThickness = new Thickness(1);
|
|
chartXy.ContainerVisualStyles.Default.BorderColor = new BorderColor(Color.Black);
|
|
chartXy.ContainerVisualStyles.Default.Background = new Background(Color.White);
|
|
chartXy.ContainerVisualStyles.Default.Margin = new Padding(4);
|
|
}
|
|
|
|
private void SetChartDefaults(PieChart pieChart)
|
|
{
|
|
pieChart.ContainerVisualStyles.Default.BorderThickness = new Thickness(1);
|
|
pieChart.ContainerVisualStyles.Default.BorderColor = new BorderColor(Color.Black);
|
|
pieChart.ContainerVisualStyles.Default.Background = new Background(Color.White);
|
|
pieChart.ContainerVisualStyles.Default.Margin = new Padding(4);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CopyButton_Click
|
|
|
|
protected override void CopyButton_Click(object sender, EventArgs e)
|
|
{
|
|
ChartContainer item = ChartItem as ChartContainer;
|
|
|
|
if (item != null)
|
|
{
|
|
if (AddButton != null)
|
|
{
|
|
ChartControlDesigner ccd = GetDesigner(_ChartPanel.ChartControl);
|
|
ChartContainerCollection ccc = _ChartPanel.ChartContainers;
|
|
|
|
ccd.InCopyItem = true;
|
|
|
|
if (item is ChartPanel)
|
|
_ItemTypes[0] = typeof(ChartPanel);
|
|
|
|
try
|
|
{
|
|
AddButton.PerformClick();
|
|
|
|
ChartContainer clone = ccc[ccc.Count - 1];
|
|
|
|
string name = clone.Name;
|
|
item.CopyTo(clone);
|
|
clone.Name = name;
|
|
}
|
|
finally
|
|
{
|
|
if (item is ChartPanel)
|
|
_ItemTypes[0] = typeof(ChartXy);
|
|
|
|
ccd.InCopyItem = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreateCollectionItemType
|
|
|
|
protected override Type CreateCollectionItemType()
|
|
{
|
|
return typeof(ChartContainer);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreateNewItemTypes
|
|
|
|
private Type[] _ItemTypes = new Type[]
|
|
{
|
|
typeof(ChartXy),
|
|
typeof(PieChart),
|
|
typeof(ChartPanel),
|
|
};
|
|
|
|
protected override Type[] CreateNewItemTypes()
|
|
{
|
|
return (_ItemTypes);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|