📄 defaultcs.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Telerik.QuickStart;
using Telerik.WebControls;
namespace Telerik.ChartExamplesCS.Borders
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public class DefaultCS: XhtmlPage
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList ddlChartElement;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.DropDownList ddlBorderColor;
protected System.Web.UI.WebControls.TextBox txtBoxBorderWidth;
protected System.Web.UI.WebControls.CheckBox cbTopLeft;
protected System.Web.UI.WebControls.CheckBox cbTopRight;
protected System.Web.UI.WebControls.CheckBox cbBottomLeft;
protected System.Web.UI.WebControls.CheckBox cbBottomRight;
protected System.Web.UI.WebControls.TextBox txtBoxRoundSize;
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
protected System.Web.UI.WebControls.RangeValidator RangeValidator2;
protected Telerik.WebControls.RadChart RadChart1;
protected System.Web.UI.WebControls.Button Button1;
private System.Collections.Hashtable chartElementsHash;
protected System.Web.UI.WebControls.Label lblIncorrectSettings;
string[] keyNames = { "Background", "Plot area", "Title", "Legend", "Series 1", "Series 2", "Item 1", "Item 2" };
private void BuildHashTable()
{
chartElementsHash = new System.Collections.Hashtable();
chartElementsHash.Add(keyNames[0], RadChart1.Background);
chartElementsHash.Add(keyNames[1], RadChart1.PlotArea);
chartElementsHash.Add(keyNames[2], RadChart1.Title1.Background);
chartElementsHash.Add(keyNames[3], RadChart1.Legend.Background);
chartElementsHash.Add(keyNames[4], RadChart1.GetChartSeries(0).Appearance);
chartElementsHash.Add(keyNames[5], RadChart1.GetChartSeries(1).Appearance);
chartElementsHash.Add(keyNames[6], RadChart1.GetChartSeries(0).Items[0].Appearance);
chartElementsHash.Add(keyNames[7], RadChart1.GetChartSeries(1).Items[0].Appearance);
}
private void Page_Load(object sender, System.EventArgs e)
{
BuildHashTable();
if (!Page.IsPostBack)
{
InitControls();
RadChart1.ChartSeriesCollection[0].Items[0].Appearance.CopyFrom(RadChart1.ChartSeriesCollection[0].Appearance);
RadChart1.ChartSeriesCollection[1].Items[0].Appearance.CopyFrom(RadChart1.ChartSeriesCollection[1].Appearance);
SetControlValues();
}
}
private void InitControls()
{
string[] valueNames;
valueNames = Enum.GetNames(typeof(KnownColor));
ddlBorderColor.Items.Clear();
foreach (string s in valueNames)
{
ddlBorderColor.Items.Add(s);
}
ddlChartElement.Items.Clear();
foreach (string s in keyNames)
{
ddlChartElement.Items.Add(s);
}
}
private void SetControlValues()
{
ChartRectShape appearance = GetCurrentAppearance(false);
if (appearance != null)
{
ddlBorderColor.SelectedIndex = ddlBorderColor.Items.IndexOf(ddlBorderColor.Items.FindByText(appearance.BorderColor.ToKnownColor().ToString()));
txtBoxBorderWidth.Text = appearance.BorderWidth.ToString();
txtBoxRoundSize.Text = appearance.Corners.RoundSize.ToString();
cbTopLeft.Checked = appearance.Corners.TopLeft == CornerType.Round;
cbTopRight.Checked = appearance.Corners.TopRight == CornerType.Round;
cbBottomLeft.Checked = appearance.Corners.BottomLeft == CornerType.Round;
cbBottomRight.Checked = appearance.Corners.BottomRight == CornerType.Round;
}
}
private CornerType GetCornerType(bool isRound)
{
if (isRound)
{
return CornerType.Round;
}
else
{
return CornerType.Rectangle;
}
}
private void SetAppearance(ChartRectShape appearance)
{
appearance.BorderColor = Color.FromName(ddlBorderColor.SelectedItem.Value);
try
{
appearance.BorderWidth = int.Parse(txtBoxBorderWidth.Text);
}
catch
{
txtBoxBorderWidth.Text = "Invalid width.";
}
try
{
appearance.Corners.RoundSize = int.Parse(txtBoxRoundSize.Text);
}
catch
{
txtBoxRoundSize.Text = "Invalid size.";
}
appearance.Corners.TopLeft = GetCornerType(cbTopLeft.Checked);
appearance.Corners.TopRight = GetCornerType(cbTopRight.Checked);
appearance.Corners.BottomLeft = GetCornerType(cbBottomLeft.Checked);
appearance.Corners.BottomRight = GetCornerType(cbBottomRight.Checked);
}
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
SetAppearance(GetCurrentAppearance(true));
lblIncorrectSettings.Visible = false;
}
catch
{
lblIncorrectSettings.Visible = true;
}
}
private ChartRectShape GetCurrentAppearance(bool changeItemAppearance)
{
if (changeItemAppearance)
{
if (ddlChartElement.SelectedIndex == 4)
{
SetAppearance((ChartRectShape) chartElementsHash[keyNames[6]]);
}
if (ddlChartElement.SelectedIndex == 5)
{
SetAppearance((ChartRectShape) chartElementsHash[keyNames[7]]);
}
}
return (ChartRectShape) chartElementsHash[ddlChartElement.SelectedItem.Value];
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ddlChartElement.SelectedIndexChanged += new System.EventHandler(this.ddlChartElement_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ddlChartElement_SelectedIndexChanged(object sender, System.EventArgs e)
{
SetControlValues();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -