⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultcs.aspx.cs

📁 Telerik是很大的第三方软件制造商
💻 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.Legend
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class DefaultCS: XhtmlPage
	{
		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 Label10;
		protected System.Web.UI.WebControls.Label Label9;
		protected System.Web.UI.WebControls.DropDownList ddlVerAlignment;
		protected System.Web.UI.WebControls.TextBox txtBoxHorSpacing;
		protected System.Web.UI.WebControls.TextBox txtBoxVerSpacing;
		protected System.Web.UI.WebControls.Button btnApply;
		protected System.Web.UI.WebControls.DropDownList ddlPosition;
		protected System.Web.UI.WebControls.DropDownList ddlHorAlignment;
		protected System.Web.UI.WebControls.DropDownList ddlLocation;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label8;
		protected System.Web.UI.WebControls.DropDownList ddlItemMark;
		protected System.Web.UI.WebControls.TextBox txtBoxItemFont;
		protected System.Web.UI.WebControls.DropDownList ddlItemsColor;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label11;
		protected System.Web.UI.WebControls.Label Label12;
		protected System.Web.UI.WebControls.TextBox txtBoxWidthRatio;
		protected System.Web.UI.WebControls.TextBox txtBoxHeightRatio;
		protected System.Web.UI.WebControls.CheckBox cbAutoScale;
		protected System.Web.UI.WebControls.Label Label13;
		protected System.Web.UI.WebControls.Label Label14;
		protected System.Web.UI.WebControls.Label Label15;
		protected System.Web.UI.WebControls.Label Label17;
		protected System.Web.UI.WebControls.Label Label18;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.DropDownList ddlItemColor;
		protected System.Web.UI.WebControls.DropDownList ddlItemMark1;		
		protected System.Web.UI.WebControls.TextBox txtBoxHRef;
		protected System.Web.UI.WebControls.TextBox txtBoxToolTip;
		protected System.Web.UI.WebControls.TextBox txtBoxAttributes;
		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(ddlItemMark, typeof(ChartLegendItemMark));
			InitControl(ddlItemsColor, typeof(KnownColor));
			
			InitControl(ddlLocation, typeof(ChartLocation));
			InitControl(ddlPosition, typeof(ChartPosition));
			InitControl(ddlHorAlignment, typeof(ChartHAlignment));
			InitControl(ddlVerAlignment, typeof(ChartVAlignment));

			InitControl(ddlItemColor, typeof(KnownColor));
			InitControl(ddlItemMark1, typeof(ChartLegendItemMark));
		}

		private void SetControlValues()
		{
			FontConverter fc = new FontConverter();

			SetControlValue(ddlItemMark, RadChart1.Legend.ItemMark.ToString());            
			txtBoxItemFont.Text = fc.ConvertToString(RadChart1.Legend.ItemFont);
			SetControlValue(ddlItemsColor, RadChart1.Legend.ItemColor.ToKnownColor().ToString());
			SetControlValue(ddlLocation, RadChart1.Legend.Location.ToString());
			SetControlValue(ddlPosition, RadChart1.Legend.Position.ToString());
			SetControlValue(ddlHorAlignment, RadChart1.Legend.HAlignment.ToString());
			SetControlValue(ddlVerAlignment, RadChart1.Legend.VAlignment.ToString());
			txtBoxHorSpacing.Text = RadChart1.Legend.HSpacing.ToString();
			txtBoxVerSpacing.Text = RadChart1.Legend.VSpacing.ToString();
			cbAutoScale.Checked = RadChart1.Legend.Visible;
			txtBoxHeightRatio.Text = RadChart1.Legend.HeightRatio.ToString();
			txtBoxWidthRatio.Text = RadChart1.Legend.WidthRatio.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.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void ApplySettings()
		{
            
			FontConverter   fc = new FontConverter();
			ColorConverter  cc = new ColorConverter();

			RadChart1.Legend.ItemColor  = (Color) cc.ConvertFromString(ddlItemsColor.SelectedItem.Value);
			RadChart1.Legend.ItemFont   = (Font) fc.ConvertFromString(txtBoxItemFont.Text);
			RadChart1.Legend.ItemMark   = (ChartLegendItemMark) Enum.Parse(typeof(ChartLegendItemMark), ddlItemMark.SelectedItem.Value);
			RadChart1.Legend.Location   = (ChartLocation) Enum.Parse(typeof(ChartLocation), ddlLocation.SelectedItem.Value);
			RadChart1.Legend.Position   = (ChartPosition) Enum.Parse(typeof(ChartPosition), ddlPosition.SelectedItem.Value);
			RadChart1.Legend.HAlignment = (ChartHAlignment) Enum.Parse(typeof(ChartHAlignment), ddlHorAlignment.SelectedItem.Value);
			RadChart1.Legend.VAlignment = (ChartVAlignment) Enum.Parse(typeof(ChartVAlignment), ddlVerAlignment.SelectedItem.Value);
			RadChart1.Legend.HSpacing   = int.Parse(txtBoxHorSpacing.Text);
			RadChart1.Legend.VSpacing   = int.Parse(txtBoxVerSpacing.Text);            
			RadChart1.Legend.AutoSize   = cbAutoScale.Checked;
			RadChart1.Legend.WidthRatio = double.Parse(txtBoxWidthRatio.Text);
			RadChart1.Legend.HeightRatio = double.Parse(txtBoxHeightRatio.Text);

		}

		private void ValidateInput()
		{
			if ((txtBoxItemFont.Text == null) || (txtBoxItemFont.Text == string.Empty))
			{
				txtBoxItemFont.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 txtBoxWidthRatio_TextChanged(object sender, System.EventArgs e)
		{
        
		}

		protected override void OnPreRender(EventArgs e)
		{
			if ( (RadChart1.Legend.Location == ChartLocation.OutsidePlotArea) && (RadChart1.Legend.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.Legend.Location == ChartLocation.OutsidePlotArea) && (RadChart1.Legend.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.Legend.Location == ChartLocation.OutsidePlotArea) && (RadChart1.Legend.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.Legend.Location == ChartLocation.OutsidePlotArea) && (RadChart1.Legend.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 Button1_Click(object sender, System.EventArgs e)
		{
			ChartLegendItem legendItem = new ChartLegendItem();

			ColorConverter cc = new ColorConverter();

			legendItem.Appearance.MainColor = (Color) cc.ConvertFromString(ddlItemColor.SelectedItem.Value);
			legendItem.Appearance.FillStyle = FillStyle.Solid;			
			legendItem.ItemMark =  (ChartLegendItemMark) Enum.Parse(typeof(ChartLegendItemMark), ddlItemMark1.SelectedItem.Value);
			legendItem.Name = "Item " + RadChart1.Legend.Items.Count.ToString();
			legendItem.ImageMap.HRef = txtBoxHRef.Text;
			legendItem.ImageMap.ToolTip = txtBoxToolTip.Text;
			legendItem.ImageMap.Attributes = txtBoxAttributes.Text;

			RadChart1.Legend.Items.Add(legendItem);	
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			ChartLegend legend = RadChart1.Legend;

			if (legend.Items.Count > 0)
			{
				legend.Items.RemoveAt(legend.Items.Count - 1);
			}
		}
			
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -