CultureDemoForm.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:19k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Globalization;
- namespace CultureDemo
- {
- /// <summary>
- /// Summary description for Form1.
- /// </summary>
- public class CultureDemoForm : System.Windows.Forms.Form
- {
- private System.Windows.Forms.TreeView treeCultures;
- private System.Windows.Forms.Splitter splitter1;
- private System.Windows.Forms.Panel panel1;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.GroupBox groupSamples;
- private System.Windows.Forms.Label label6;
- private System.Windows.Forms.Label label7;
- private System.Windows.Forms.Label label8;
- private System.Windows.Forms.GroupBox groupRegionInformation;
- private System.Windows.Forms.Label label9;
- private System.Windows.Forms.Label label10;
- private System.Windows.Forms.TextBox textName;
- private System.Windows.Forms.TextBox textEnglishName;
- private System.Windows.Forms.TextBox textNativeName;
- private System.Windows.Forms.CheckBox checkIsNeutral;
- private System.Windows.Forms.TextBox textCalendar;
- private System.Windows.Forms.ListBox listCalendars;
- private System.Windows.Forms.TextBox textSampleNumber;
- private System.Windows.Forms.TextBox textSampleDate;
- private System.Windows.Forms.TextBox textSampleTime;
- private System.Windows.Forms.CheckBox checkIsMetric;
- private System.Windows.Forms.TextBox textCurrency;
- private System.Windows.Forms.TextBox textRegionName;
- private System.Windows.Forms.TextBox textCurrencyName;
- private System.Windows.Forms.TextBox textBox1;
- private System.Windows.Forms.TextBox textBox2;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- public CultureDemoForm()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- AddCulturesToTree();
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.treeCultures = new System.Windows.Forms.TreeView();
- this.splitter1 = new System.Windows.Forms.Splitter();
- this.panel1 = new System.Windows.Forms.Panel();
- this.groupRegionInformation = new System.Windows.Forms.GroupBox();
- this.label9 = new System.Windows.Forms.Label();
- this.groupSamples = new System.Windows.Forms.GroupBox();
- this.label8 = new System.Windows.Forms.Label();
- this.label7 = new System.Windows.Forms.Label();
- this.label6 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label1 = new System.Windows.Forms.Label();
- this.label10 = new System.Windows.Forms.Label();
- this.textName = new System.Windows.Forms.TextBox();
- this.textEnglishName = new System.Windows.Forms.TextBox();
- this.textNativeName = new System.Windows.Forms.TextBox();
- this.checkIsNeutral = new System.Windows.Forms.CheckBox();
- this.textCalendar = new System.Windows.Forms.TextBox();
- this.listCalendars = new System.Windows.Forms.ListBox();
- this.textSampleNumber = new System.Windows.Forms.TextBox();
- this.textSampleDate = new System.Windows.Forms.TextBox();
- this.textSampleTime = new System.Windows.Forms.TextBox();
- this.textRegionName = new System.Windows.Forms.TextBox();
- this.textCurrency = new System.Windows.Forms.TextBox();
- this.textCurrencyName = new System.Windows.Forms.TextBox();
- this.checkIsMetric = new System.Windows.Forms.CheckBox();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.panel1.SuspendLayout();
- this.groupRegionInformation.SuspendLayout();
- this.groupSamples.SuspendLayout();
- this.SuspendLayout();
- //
- // treeCultures
- //
- this.treeCultures.Dock = System.Windows.Forms.DockStyle.Left;
- this.treeCultures.ImageIndex = -1;
- this.treeCultures.Location = new System.Drawing.Point(0, 0);
- this.treeCultures.Name = "treeCultures";
- this.treeCultures.SelectedImageIndex = -1;
- this.treeCultures.Size = new System.Drawing.Size(168, 454);
- this.treeCultures.TabIndex = 0;
- this.treeCultures.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.OnSelectCulture);
- //
- // splitter1
- //
- this.splitter1.Location = new System.Drawing.Point(168, 0);
- this.splitter1.Name = "splitter1";
- this.splitter1.Size = new System.Drawing.Size(3, 454);
- this.splitter1.TabIndex = 1;
- this.splitter1.TabStop = false;
- //
- // panel1
- //
- this.panel1.Controls.Add(this.listCalendars);
- this.panel1.Controls.Add(this.textCalendar);
- this.panel1.Controls.Add(this.checkIsNeutral);
- this.panel1.Controls.Add(this.textNativeName);
- this.panel1.Controls.Add(this.textEnglishName);
- this.panel1.Controls.Add(this.textName);
- this.panel1.Controls.Add(this.groupRegionInformation);
- this.panel1.Controls.Add(this.groupSamples);
- this.panel1.Controls.Add(this.label5);
- this.panel1.Controls.Add(this.label4);
- this.panel1.Controls.Add(this.label3);
- this.panel1.Controls.Add(this.label2);
- this.panel1.Controls.Add(this.label1);
- this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
- this.panel1.Location = new System.Drawing.Point(168, 0);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(304, 454);
- this.panel1.TabIndex = 1;
- //
- // groupRegionInformation
- //
- this.groupRegionInformation.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.groupRegionInformation.Controls.Add(this.checkIsMetric);
- this.groupRegionInformation.Controls.Add(this.textCurrencyName);
- this.groupRegionInformation.Controls.Add(this.textCurrency);
- this.groupRegionInformation.Controls.Add(this.textRegionName);
- this.groupRegionInformation.Controls.Add(this.label10);
- this.groupRegionInformation.Controls.Add(this.label9);
- this.groupRegionInformation.Location = new System.Drawing.Point(19, 320);
- this.groupRegionInformation.Name = "groupRegionInformation";
- this.groupRegionInformation.Size = new System.Drawing.Size(272, 120);
- this.groupRegionInformation.TabIndex = 12;
- this.groupRegionInformation.TabStop = false;
- this.groupRegionInformation.Text = "Region Information";
- //
- // label9
- //
- this.label9.Location = new System.Drawing.Point(16, 16);
- this.label9.Name = "label9";
- this.label9.TabIndex = 0;
- this.label9.Text = "Region:";
- //
- // groupSamples
- //
- this.groupSamples.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.groupSamples.Controls.Add(this.textSampleTime);
- this.groupSamples.Controls.Add(this.textSampleDate);
- this.groupSamples.Controls.Add(this.textSampleNumber);
- this.groupSamples.Controls.Add(this.label8);
- this.groupSamples.Controls.Add(this.label7);
- this.groupSamples.Controls.Add(this.label6);
- this.groupSamples.Location = new System.Drawing.Point(19, 200);
- this.groupSamples.Name = "groupSamples";
- this.groupSamples.Size = new System.Drawing.Size(272, 112);
- this.groupSamples.TabIndex = 11;
- this.groupSamples.TabStop = false;
- this.groupSamples.Text = "Samples";
- //
- // label8
- //
- this.label8.Location = new System.Drawing.Point(16, 72);
- this.label8.Name = "label8";
- this.label8.TabIndex = 4;
- this.label8.Text = "Time:";
- //
- // label7
- //
- this.label7.Location = new System.Drawing.Point(16, 48);
- this.label7.Name = "label7";
- this.label7.TabIndex = 2;
- this.label7.Text = "Full Date:";
- //
- // label6
- //
- this.label6.Location = new System.Drawing.Point(16, 24);
- this.label6.Name = "label6";
- this.label6.TabIndex = 0;
- this.label6.Text = "Number:";
- //
- // label5
- //
- this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.label5.Location = new System.Drawing.Point(19, 152);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(112, 23);
- this.label5.TabIndex = 9;
- this.label5.Text = "Optional Calendars:";
- //
- // label4
- //
- this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.label4.Location = new System.Drawing.Point(19, 120);
- this.label4.Name = "label4";
- this.label4.TabIndex = 7;
- this.label4.Text = "Default Calendar:";
- //
- // label3
- //
- this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.label3.Location = new System.Drawing.Point(19, 88);
- this.label3.Name = "label3";
- this.label3.TabIndex = 5;
- this.label3.Text = "Native Name:";
- //
- // label2
- //
- this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.label2.Location = new System.Drawing.Point(19, 24);
- this.label2.Name = "label2";
- this.label2.TabIndex = 0;
- this.label2.Text = "Culture Name:";
- //
- // label1
- //
- this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.label1.Location = new System.Drawing.Point(19, 56);
- this.label1.Name = "label1";
- this.label1.TabIndex = 3;
- this.label1.Text = "English Name:";
- //
- // label10
- //
- this.label10.Location = new System.Drawing.Point(16, 48);
- this.label10.Name = "label10";
- this.label10.TabIndex = 2;
- this.label10.Text = "Currency:";
- //
- // textName
- //
- this.textName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.textName.Location = new System.Drawing.Point(139, 24);
- this.textName.Name = "textName";
- this.textName.Size = new System.Drawing.Size(48, 20);
- this.textName.TabIndex = 1;
- this.textName.Text = "";
- //
- // textEnglishName
- //
- this.textEnglishName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.textEnglishName.Location = new System.Drawing.Point(139, 56);
- this.textEnglishName.Name = "textEnglishName";
- this.textEnglishName.Size = new System.Drawing.Size(152, 20);
- this.textEnglishName.TabIndex = 4;
- this.textEnglishName.Text = "";
- //
- // textNativeName
- //
- this.textNativeName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.textNativeName.Location = new System.Drawing.Point(139, 88);
- this.textNativeName.Name = "textNativeName";
- this.textNativeName.Size = new System.Drawing.Size(152, 20);
- this.textNativeName.TabIndex = 6;
- this.textNativeName.Text = "";
- //
- // checkIsNeutral
- //
- this.checkIsNeutral.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.checkIsNeutral.Location = new System.Drawing.Point(211, 24);
- this.checkIsNeutral.Name = "checkIsNeutral";
- this.checkIsNeutral.Size = new System.Drawing.Size(80, 24);
- this.checkIsNeutral.TabIndex = 2;
- this.checkIsNeutral.Text = "Is Neutral";
- //
- // textCalendar
- //
- this.textCalendar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.textCalendar.Location = new System.Drawing.Point(139, 120);
- this.textCalendar.Name = "textCalendar";
- this.textCalendar.Size = new System.Drawing.Size(152, 20);
- this.textCalendar.TabIndex = 8;
- this.textCalendar.Text = "";
- //
- // listCalendars
- //
- this.listCalendars.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.listCalendars.Location = new System.Drawing.Point(139, 152);
- this.listCalendars.Name = "listCalendars";
- this.listCalendars.Size = new System.Drawing.Size(152, 43);
- this.listCalendars.TabIndex = 10;
- //
- // textSampleNumber
- //
- this.textSampleNumber.Location = new System.Drawing.Point(128, 16);
- this.textSampleNumber.Name = "textSampleNumber";
- this.textSampleNumber.Size = new System.Drawing.Size(120, 20);
- this.textSampleNumber.TabIndex = 1;
- this.textSampleNumber.Text = "";
- //
- // textSampleDate
- //
- this.textSampleDate.Location = new System.Drawing.Point(128, 48);
- this.textSampleDate.Name = "textSampleDate";
- this.textSampleDate.Size = new System.Drawing.Size(120, 20);
- this.textSampleDate.TabIndex = 3;
- this.textSampleDate.Text = "";
- //
- // textSampleTime
- //
- this.textSampleTime.Location = new System.Drawing.Point(128, 80);
- this.textSampleTime.Name = "textSampleTime";
- this.textSampleTime.Size = new System.Drawing.Size(120, 20);
- this.textSampleTime.TabIndex = 5;
- this.textSampleTime.Text = "";
- //
- // textRegionName
- //
- this.textRegionName.Location = new System.Drawing.Point(128, 16);
- this.textRegionName.Name = "textRegionName";
- this.textRegionName.Size = new System.Drawing.Size(120, 20);
- this.textRegionName.TabIndex = 1;
- this.textRegionName.Text = "";
- //
- // textCurrency
- //
- this.textCurrency.Location = new System.Drawing.Point(128, 48);
- this.textCurrency.Name = "textCurrency";
- this.textCurrency.Size = new System.Drawing.Size(48, 20);
- this.textCurrency.TabIndex = 3;
- this.textCurrency.Text = "";
- //
- // textCurrencyName
- //
- this.textCurrencyName.Location = new System.Drawing.Point(200, 48);
- this.textCurrencyName.Name = "textCurrencyName";
- this.textCurrencyName.Size = new System.Drawing.Size(48, 20);
- this.textCurrencyName.TabIndex = 4;
- this.textCurrencyName.Text = "";
- //
- // checkIsMetric
- //
- this.checkIsMetric.Location = new System.Drawing.Point(136, 80);
- this.checkIsMetric.Name = "checkIsMetric";
- this.checkIsMetric.TabIndex = 5;
- this.checkIsMetric.Text = "Is Metric";
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(0, 0);
- this.textBox1.Name = "textBox1";
- this.textBox1.TabIndex = 0;
- this.textBox1.Text = "";
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(0, 0);
- this.textBox2.Name = "textBox2";
- this.textBox2.TabIndex = 0;
- this.textBox2.Text = "";
- //
- // CultureDemoForm
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(472, 454);
- this.Controls.Add(this.panel1);
- this.Controls.Add(this.splitter1);
- this.Controls.Add(this.treeCultures);
- this.Name = "CultureDemoForm";
- this.Text = "Culture Demo";
- this.panel1.ResumeLayout(false);
- this.groupRegionInformation.ResumeLayout(false);
- this.groupSamples.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new CultureDemoForm());
- }
- // add all cultures to the tree view
- public void AddCulturesToTree()
- {
- CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
- TreeNode[] nodes = new TreeNode[cultures.Length];
- int i = 0;
- TreeNode parent = null;
- foreach (CultureInfo ci in cultures)
- {
- nodes[i] = new TreeNode();
- nodes[i].Text = ci.DisplayName;
- nodes[i].Tag = ci;
- if (ci.IsNeutralCulture)
- {
- parent = nodes[i];
- treeCultures.Nodes.Add(nodes[i]);
- }
- else if (ci.ThreeLetterISOLanguageName == CultureInfo.InvariantCulture.ThreeLetterISOLanguageName)
- {
- this.treeCultures.Nodes.Add(nodes[i]);
- }
- else
- {
- parent.Nodes.Add(nodes[i]);
- }
- i++;
- }
- }
- private void OnSelectCulture(object sender, System.Windows.Forms.TreeViewEventArgs e)
- {
- ClearTextFields();
- // get culture from tree
- CultureInfo ci = (CultureInfo)e.Node.Tag;
- textName.Text = ci.Name;
- textNativeName.Text = ci.NativeName;
- textEnglishName.Text = ci.EnglishName;
-
- checkIsNeutral.Checked = ci.IsNeutralCulture;
- // default calendar
- textCalendar.Text = ci.Calendar.ToString().Remove(0, 21);
- // fill optional calendars
- listCalendars.Items.Clear();
- foreach (Calendar optCal in ci.OptionalCalendars)
- {
- string calName = optCal.ToString().Remove(0, 21);
- // for GregorianCalendar add type information
- if (optCal is System.Globalization.GregorianCalendar)
- {
- GregorianCalendar gregCal = optCal as GregorianCalendar;
- calName += " " + gregCal.CalendarType.ToString();
- }
- listCalendars.Items.Add(calName);
- }
- // display number and date samples
- if (!ci.IsNeutralCulture)
- {
- groupSamples.Enabled = true;
- ShowSamples(ci);
- // invariant culture doesn't have a region
- if (ci.ThreeLetterISOLanguageName == "IVL")
- {
- groupRegionInformation.Enabled = false;
- }
- else
- {
- groupRegionInformation.Enabled = true;
- ShowRegionInformation(ci.LCID);
- }
- }
- else // neutral culture: no region, no number/date formatting
- {
- groupSamples.Enabled = false;
- groupRegionInformation.Enabled = false;
- }
- }
- private void ShowSamples(CultureInfo ci)
- {
- double number = 9876543.21;
- textSampleNumber.Text = number.ToString("N", ci);
- DateTime today = DateTime.Today;
- textSampleDate.Text = today.ToString("D", ci);
- DateTime now = DateTime.Now;
- textSampleTime.Text = now.ToString("T", ci);
- }
- private void ShowRegionInformation(int culture)
- {
- RegionInfo ri = new RegionInfo(culture);
- textRegionName.Text = ri.DisplayName;
- textCurrency.Text = ri.CurrencySymbol;
- textCurrencyName.Text = ri.ISOCurrencySymbol;
- checkIsMetric.Checked = ri.IsMetric;
- }
- #region Clear Fields
- private void ClearTextFields()
- {
- // samples
- textSampleNumber.Text = "";
- textSampleDate.Text = "";
- textSampleTime.Text = "";
- // region information
- textRegionName.Text = "";
- textCurrency.Text = "";
- textCurrencyName.Text = "";
- checkIsMetric.Checked = false;
- }
- #endregion
- }
- }