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

📄 form2revisited.cs

📁 清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace Localisation
{
  public partial class Form2Revisited : Form
  {
    public Form2Revisited()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      this.DisplayThis(DateTime.Now);
    }

    private void menuItem1_Click(object sender, EventArgs e)
    {
      this.ParseThat("13/1/06 23.31.54");
    }

    private void menuItem2_Click(object sender, EventArgs e)
    {
      string s = this.ExtractDecimalPoints(12.34);
      label1.Text = s;
    }

    private void button2_Click(object sender, EventArgs e)
    {
      label1.Text = this.FirstDayOfWeekToStringCorrect();
    }

    private void DisplayThis(DateTime dt)
    {
      CultureInfo ci = CultureInfo.CurrentCulture;
      string timeSeparator = ci.DateTimeFormat.TimeSeparator;
      label1.Text = dt.Hour + timeSeparator + dt.Minute;
    }

    private void ParseThat(string someTime)
    {
      // someTime comes in as "13/1/06 23.31.54"
      CultureInfo ci = new CultureInfo("it-IT");
      DateTime dt = DateTime.Parse(someTime, ci);
      MessageBox.Show(dt.ToString());
    }

    private string ExtractDecimalPoints(double valueFromNetwork)
    {
      // valueFromNetwork comes in as 12.34 but on French becomes 12,34
      string temp = valueFromNetwork.ToString(new CultureInfo("en-GB"));
      int decimalPoint = temp.IndexOf('.');
      return temp.Substring(decimalPoint + 1);
    }

    private string FirstDayOfWeekToString()
    {
      DayOfWeek dow =
        CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;

      switch (dow)
      {
        case DayOfWeek.Monday:
          return "Monday";
        case DayOfWeek.Sunday:
          return "Sunday";
        default:
          return "Monday"; //arbitrary decision
      }
    }

    private string FirstDayOfWeekToStringCorrect()
    {
      DateTimeFormatInfo dtfi = CultureInfo.CurrentCulture.DateTimeFormat;
      DayOfWeek dow = dtfi.FirstDayOfWeek;
      return dtfi.DayNames[(int)dow];
    }

    private void button3_Click(object sender, EventArgs e)
    {
      //this.Hardcoded();
      this.FromResources();
    }

    private void Hardcoded()
    {
      label1.Text = "Day of week:";
      textBox1.Text = "Saturday";
    }
    private void FromResources()
    {
      label1.Text = Resource1.label1;
      textBox1.Text = Resource1.saturday;
    }
  }
}

⌨️ 快捷键说明

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