📄 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.Gradients
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public class DefaultCS: XhtmlPage
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.DropDownList ddlMainColor;
protected System.Web.UI.WebControls.DropDownList ddlSecondColor;
protected System.Web.UI.WebControls.DropDownList ddlGradientFillStyle;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.TextBox txtBoxGradientFocus;
protected System.Web.UI.WebControls.CheckBox cbGammaCorrection;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
protected System.Web.UI.WebControls.Label Label5;
protected Telerik.WebControls.RadChart RadChart1;
protected System.Web.UI.WebControls.DropDownList ddlChartElement;
private System.Collections.Hashtable chartElementsHash;
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();
SetControlValues();
}
}
private void InitControls()
{
string[] valueNames;
// Init Colors
valueNames = Enum.GetNames(typeof(KnownColor));
ddlMainColor.Items.Clear();
ddlSecondColor.Items.Clear();
foreach (string s in valueNames)
{
ddlMainColor.Items.Add(s);
ddlSecondColor.Items.Add(s);
}
// Init gradient fill styles:
valueNames = Enum.GetNames(typeof(GradientFillStyle));
ddlGradientFillStyle.Items.Clear();
foreach (string s in valueNames)
{
ddlGradientFillStyle.Items.Add(s);
}
ddlChartElement.Items.Clear();
foreach (string s in keyNames)
{
ddlChartElement.Items.Add(s);
}
}
private void SetControlValues()
{
ChartRectShape appearance = GetCurrentAppearance();
if (appearance != null)
{
ddlMainColor.SelectedIndex = ddlMainColor.Items.IndexOf(ddlMainColor.Items.FindByText(appearance.MainColor.ToKnownColor().ToString()));
ddlSecondColor.SelectedIndex = ddlSecondColor.Items.IndexOf(ddlSecondColor.Items.FindByText(appearance.SecondColor.ToKnownColor().ToString()));
ddlGradientFillStyle.SelectedIndex = ddlGradientFillStyle.Items.IndexOf(ddlGradientFillStyle.Items.FindByText(appearance.GradientFillStyle.ToString()));
cbGammaCorrection.Checked = appearance.GammaCorrection;
txtBoxGradientFocus.Text = appearance.GradientFocus.ToString();
}
}
private ChartRectShape GetCurrentAppearance()
{
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 Button1_Click(object sender, System.EventArgs e)
{
ChartRectShape elementAppearance = GetCurrentAppearance();
if (elementAppearance != null)
{
elementAppearance.MainColor = Color.FromName(ddlMainColor.SelectedItem.Value);
elementAppearance.SecondColor = Color.FromName(ddlSecondColor.SelectedItem.Value);
elementAppearance.GradientFillStyle = (GradientFillStyle) Enum.Parse(typeof(GradientFillStyle), ddlGradientFillStyle.SelectedItem.Value, true);
try
{
elementAppearance.GradientFocus = float.Parse(txtBoxGradientFocus.Text);
}
catch
{
txtBoxGradientFocus.Text = "Value must be between 0 and 1";
}
elementAppearance.GammaCorrection = cbGammaCorrection.Checked;
elementAppearance.FillStyle = FillStyle.Gradient;
}
}
private void ddlChartElement_SelectedIndexChanged(object sender, System.EventArgs e)
{
SetControlValues();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -