📄 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.Labels
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public class DefaultCS: XhtmlPage
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
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.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.DropDownList ddlLabel;
protected System.Web.UI.WebControls.TextBox tbText;
protected System.Web.UI.WebControls.TextBox tbFont;
protected System.Web.UI.WebControls.DropDownList ddlTextColor;
protected System.Web.UI.WebControls.DropDownList ddlBorderColor;
protected System.Web.UI.WebControls.TextBox tbBorderWidth;
protected System.Web.UI.WebControls.CheckBox cbRoundCorners;
protected System.Web.UI.WebControls.DropDownList ddlFillStyle;
protected System.Web.UI.WebControls.TextBox tbRoundSize;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.DropDownList ddlBackColor;
protected System.Web.UI.WebControls.Label lblIncorrectSettings;
protected Telerik.WebControls.RadChart RadChart1;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
InitControls();
SetControlValues();
}
}
private void InitControls()
{
InitControl(ddlBorderColor, typeof(KnownColor));
InitControl(ddlFillStyle, typeof(FillStyle));
InitControl(ddlTextColor, typeof(KnownColor));
InitControl(ddlBackColor, typeof(KnownColor));
}
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 SetControlValues()
{
FontConverter fc = new FontConverter();
ColorConverter cc = new ColorConverter();
ChartBaseLabel label = GetCurrentLabel();
tbText.Text = label.Text;
tbFont.Text = fc.ConvertToString(label.TextFont);
SetControlValue(ddlTextColor, label.TextColor.ToKnownColor().ToString());
SetControlValue(ddlBackColor, label.Background.MainColor.ToKnownColor().ToString());
SetControlValue(ddlBorderColor, label.Background.BorderColor.ToKnownColor().ToString());
tbBorderWidth.Text = label.Background.BorderWidth.ToString();
if (label.Background.Corners.TopLeft == CornerType.Round)
{
cbRoundCorners.Checked = true;
}
else
{
cbRoundCorners.Checked = false;
}
tbRoundSize.Text = label.Background.Corners.RoundSize.ToString();
}
private void SetControlValue(DropDownList ddList, string val)
{
ListItem listItem;
listItem = ddList.SelectedItem;
if (listItem != null)
{
listItem.Selected = false;
}
listItem = ddList.Items.FindByValue(val);
if (listItem != null)
{
listItem.Selected = true;
}
}
#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.ddlLabel.SelectedIndexChanged += new System.EventHandler(this.ddlLabel_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ValidateInput()
{
if ((tbFont.Text == null) || (tbFont.Text == string.Empty))
{
tbFont.Text = "Arial; 12pt; style=bold";
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
ValidateInput();
ApplySettings(GetCurrentLabel());
lblIncorrectSettings.Visible = false;
}
catch
{
lblIncorrectSettings.Visible = true;
}
}
private void ApplySettings(ChartBaseLabel label)
{
FontConverter fc = new FontConverter();
ColorConverter cc = new ColorConverter();
label.Text = tbText.Text;
label.TextFont = (Font) fc.ConvertFromString(tbFont.Text);
label.TextColor = (Color) cc.ConvertFromString(ddlTextColor.SelectedItem.Value);
label.Background.MainColor = (Color) cc.ConvertFromString(ddlBackColor.SelectedItem.Value);
label.Background.BorderColor = (Color) cc.ConvertFromString(ddlBorderColor.SelectedItem.Value);
label.Background.BorderWidth = int.Parse(tbBorderWidth.Text);
label.Background.FillStyle = FillStyle.Solid;
if (cbRoundCorners.Checked)
{
label.Background.Corners.SetCornersType(CornerType.Round);
}
else
{
label.Background.Corners.SetCornersType(CornerType.Rectangle);
}
label.Background.Corners.RoundSize = int.Parse(tbRoundSize.Text);
ApplyFillStyle(label);
}
private void ApplyFillStyle(ChartBaseLabel label)
{
switch (ddlFillStyle.SelectedIndex)
{
case 0:
{
break;
}
case 1:
{
label.Background.FillStyle = FillStyle.Gradient;
label.Background.SecondColor = Color.White;
break;
}
case 2:
{
label.Background.FillStyle = FillStyle.Hatch;
label.Background.SecondColor = Color.White;
break;
}
case 3:
{
label.Background.FillStyle = FillStyle.Image;
label.Background.ImageMode = ImageMode.Tile;
label.Background.ImageUrl = @"texture.jpg";
break;
}
}
}
private ChartBaseLabel GetCurrentLabel()
{
switch (ddlLabel.SelectedIndex)
{
case (0):
{
return RadChart1.Title1;
}
case (1):
{
return RadChart1.XAxis.Label;
}
case (2):
{
return RadChart1.YAxis.Label;
}
case (3):
{
return RadChart1.ChartSeriesCollection[0].LabelAppearance;
}
}
return null;
}
private void ddlLabel_SelectedIndexChanged(object sender, System.EventArgs e)
{
SetControlValues();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -