📄 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.Title
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public class DefaultCS: XhtmlPage
{
protected Telerik.WebControls.RadChart RadChart1;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.DropDownList ddlVerAlignment;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.TextBox txtBoxHorSpacing;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.TextBox txtBoxVerSpacing;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Button btnApply;
protected System.Web.UI.WebControls.TextBox txtBoxText;
protected System.Web.UI.WebControls.TextBox txtBoxFont;
protected System.Web.UI.WebControls.DropDownList ddlTextDirection;
protected System.Web.UI.WebControls.DropDownList ddlPosition;
protected System.Web.UI.WebControls.DropDownList ddlHorAlignment;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList ddlLocation;
protected System.Web.UI.WebControls.Label lblIncorrectSettings;
protected System.Web.UI.WebControls.DropDownList ddlTextColor;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
InitControls();
SetControlValues();
}
}
protected override void OnPreRender(EventArgs e)
{
if ( (RadChart1.Title1.Location == ChartLocation.OutsidePlotArea) && (RadChart1.Title1.Position == ChartPosition.Left) )
{
RadChart1.Margins.Left = Unit.Percentage(20);
RadChart1.Margins.Top = Unit.Percentage(10);
RadChart1.Margins.Right = Unit.Percentage(10);
RadChart1.Margins.Bottom = Unit.Percentage(10);
}
else if ( (RadChart1.Title1.Location == ChartLocation.OutsidePlotArea) && (RadChart1.Title1.Position == ChartPosition.Top) )
{
RadChart1.Margins.Left = Unit.Percentage(10);
RadChart1.Margins.Top = Unit.Percentage(20);
RadChart1.Margins.Right = Unit.Percentage(10);
RadChart1.Margins.Bottom = Unit.Percentage(10);
}
else if ( (RadChart1.Title1.Location == ChartLocation.OutsidePlotArea) && (RadChart1.Title1.Position == ChartPosition.Bottom) )
{
RadChart1.Margins.Left = Unit.Percentage(10);
RadChart1.Margins.Top = Unit.Percentage(10);
RadChart1.Margins.Right = Unit.Percentage(10);
RadChart1.Margins.Bottom = Unit.Percentage(23);
}
else if ( (RadChart1.Title1.Location == ChartLocation.OutsidePlotArea) && (RadChart1.Title1.Position == ChartPosition.Right) )
{
RadChart1.Margins.Left = Unit.Percentage(10);
RadChart1.Margins.Top = Unit.Percentage(10);
RadChart1.Margins.Right = Unit.Percentage(20);
RadChart1.Margins.Bottom = Unit.Percentage(10);
}
}
private void InitControls()
{
InitControl(ddlTextColor, typeof(KnownColor));
InitControl(ddlTextDirection, typeof(ChartTextDirection));
InitControl(ddlLocation, typeof(ChartLocation));
InitControl(ddlPosition, typeof(ChartPosition));
InitControl(ddlHorAlignment, typeof(ChartHAlignment));
InitControl(ddlVerAlignment, typeof(ChartVAlignment));
}
private void SetControlValues()
{
FontConverter fc = new FontConverter();
txtBoxText.Text = RadChart1.Title1.Text;
txtBoxFont.Text = fc.ConvertToString(RadChart1.Title1.TextFont);
SetControlValue(ddlTextColor, RadChart1.Title1.TextColor.ToKnownColor().ToString());
SetControlValue(ddlTextDirection, RadChart1.Title1.TextDirection.ToString());
SetControlValue(ddlPosition, RadChart1.Title1.Position.ToString());
SetControlValue(ddlLocation, RadChart1.Title1.Location.ToString());
SetControlValue(ddlHorAlignment, RadChart1.Title1.HAlignment.ToString());
SetControlValue(ddlVerAlignment, RadChart1.Title1.VAlignment.ToString());
txtBoxHorSpacing.Text = RadChart1.Title1.HSpacing.ToString();
txtBoxVerSpacing.Text = RadChart1.Title1.VSpacing.ToString();
}
private void InitControl(DropDownList ddList, Type type)
{
string[] valueNames = Enum.GetNames(type);
ddList.Items.Clear();
foreach (string s in valueNames)
{
ddList.Items.Add(s);
}
}
private void SetControlValue(DropDownList ddList, string val)
{
ddList.SelectedIndex = ddList.Items.IndexOf(ddList.Items.FindByValue(val));
}
#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.ddlPosition.SelectedIndexChanged += new System.EventHandler(this.ddlPosition_SelectedIndexChanged);
this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ValidateInput()
{
if ((txtBoxFont.Text == null) || (txtBoxFont.Text == string.Empty))
{
txtBoxFont.Text = "Arial; 12pt; style=bold";
}
}
private void btnApply_Click(object sender, System.EventArgs e)
{
try
{
ValidateInput();
ApplySettings();
lblIncorrectSettings.Visible = false;
}
catch
{
lblIncorrectSettings.Visible = true;
}
}
private void ApplySettings()
{
FontConverter fc = new FontConverter();
ColorConverter cc = new ColorConverter();
RadChart1.Title1.Text = txtBoxText.Text;
RadChart1.Title1.TextFont = (Font) fc.ConvertFromString(txtBoxFont.Text);
RadChart1.Title1.TextColor = (Color) cc.ConvertFromString(ddlTextColor.SelectedItem.Value);
RadChart1.Title1.TextDirection = (ChartTextDirection) Enum.Parse(typeof(ChartTextDirection), ddlTextDirection.SelectedItem.Value);
RadChart1.Title1.Position = (ChartPosition) Enum.Parse(typeof(ChartPosition), ddlPosition.SelectedItem.Value);
RadChart1.Title1.Location = (ChartLocation) Enum.Parse(typeof(ChartLocation), ddlLocation.SelectedItem.Value);
RadChart1.Title1.HAlignment = (ChartHAlignment) Enum.Parse(typeof(ChartHAlignment), ddlHorAlignment.SelectedItem.Value);
RadChart1.Title1.VAlignment = (ChartVAlignment) Enum.Parse(typeof(ChartVAlignment), ddlVerAlignment.SelectedItem.Value);
RadChart1.Title1.HSpacing = int.Parse(txtBoxHorSpacing.Text);
RadChart1.Title1.VSpacing = int.Parse(txtBoxVerSpacing.Text);
}
private void ddlPosition_SelectedIndexChanged(object sender, System.EventArgs e)
{
if ( (RadChart1.Title1.Location == ChartLocation.OutsidePlotArea) && (ddlPosition.SelectedItem.Value.Equals("Left")))
{
SetControlValue(ddlTextDirection, "Left");
}
else if ( (RadChart1.Title1.Location == ChartLocation.OutsidePlotArea) && (ddlPosition.SelectedItem.Value.Equals("Right")))
{
SetControlValue(ddlTextDirection, "Right");
}
else
{
SetControlValue(ddlTextDirection, "Normal");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -