學習 動態產生元件、委派、共用一個事件
學習 dataGridView
學習 轉換型別
哈囉
  private void timer1_Tick(object sender, EventArgs e)
  {
      // 宣告 DateTime 型別,接收 DateTime.Now
      DateTime DT_now = DateTime.Now;
      labelNowTime.Text = DT_now.Hour + ":" + DT_now.Minute + ":" + DT_now.Second;
  }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PictureViewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void showButton_Click(object sender, EventArgs e)
        {
            // Show the Open File dialog. If the user clicks OK, load the
            // picture that the user chose.
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Load(openFileDialog1.FileName);
            }
                
        }
        private void clearButton_Click(object sender, EventArgs e)
        {
            // Clear the picture.
            pictureBox1.Image = null;
        }
        private void backgroundButton_Click(object sender, EventArgs e)
        {
            // Show the color dialog box. If the user clicks OK, change the
            // PictureBox control's background to the color the user chose.
            if (colorDialog1.ShowDialog() == DialogResult.OK)
                pictureBox1.BackColor = colorDialog1.Color;
        }
        private void closeButton_Click(object sender, EventArgs e)
        {
            // Close the form.
            this.Close();
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            // If the user selects the Stretch check box, 
            // change the PictureBox's
            // SizeMode property to "Stretch". If the user clears 
            // the check box, change it to "Normal".
            if (checkBox1.Checked)
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            else
                pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
        }
    }
}
| 
格式 | 
說明 | 
Format | 
Input  | 
Output | 
補充 | 
| C | 貨幣 | {0:C} | 1234.567 | NT$1,234.57 | Currency :C預設到小數2位…C1取小數一位,C3取小數三位… | 
| D | 十進位 | {0:D} | 1234 | 1234 | Decimal: 只支援整數資料型別(integral types),D後面數字表示指定的位數 | 
| E | 科學指數 | {0:E} | 1234 | 1.234000E+003 | Scientific | 
| F | 固定 | {0:F} | 1234.4567 | 1234.46 | Fixed-point | 
| G | 一般 | {0:G} | 1234.567 | 1234.57 | General | 
| N | 數字 | {0:N} | 120000 | 120,000.00 | Number:每三位數用 "," 隔開 | 
| P | 百分比 | {0:P} | 0.25 | 25.00% | Percent:輸入數值*100 ; 預設取小數2位,P0可取小數 | 
| R | 來回 | {0:R} | 0.25 | 0.25 | Round-trip:只支援Double、Single | 
| X | 十六進位 | {0:X} | 123 | 7B | Hexadecimal:只支援整數資料型別(integral types) | 
| 
格式 | 
說明 | 
Format | 
Input | 
Output | 
補充 | 
| 0 | 零值預留位置 | {0:000.000} | 12.3 | 012.300 | Zero placeholder | 
| # | 數字預留位置 | {0:###.###} | 12.3 | 12.3 | Digit placeholder #,,:1234567890→1235 #,,,:1234567890→1 #,##0,,:1234567890→1,235 | 
| . | 小數點 | {0:0.0} | 12.3 | 12.3 | Decimal point | 
| , | 千位分隔符號 | {0:0,0} | 1200 | 1,200 | Thousand separator and number scaling | 
| % | 百分比預留位置 | {0:0%} | 0.25 | 25% | Percentage placeholder | 
| e | 科學標記法 | {0:0e+0} | 123 | 1e+2 | Scientific notation | 
| \ | 跳脫字元 | {0:00\n0} | 123 | 12 3 | Escape character | 
| 
格式 | 
說明 | 
Format | 
Output | 
補充 | 
| dd | 月份日期 | {0:dd} | 11 | |
| ddd | 星期幾的縮寫 | {0:ddd} | 星期日 | Sun | 
| dddd | 星期幾的完整名稱 | {0:dddd} | 星期日 | Sunday | 
| f, ff… | 秒數 | {0:fff} | 364 | |
| gg,… | 時期或時代 | {0:gg} | 西元 | |
| hh | 小時(12 小時制) | {0:hh} | 02 | |
| HH | 小時(24 小時制) | {0:HH} | 14 | |
| mm | 分鐘 | {0:mm} | 21 | |
| MM | 月份 | {0:MM} | 03 | |
| MMM | 月份的縮寫名稱 | {0:MMM} | 三月 | Mar | 
| MMMM | 月份的完整名稱 | {0:MMMM} | 三月 | March | 
| ss | 秒數 | {0:ss} | 49 | |
| tt | A.M./P.M | {0:tt} | 下午 | |
| yy | 兩個位數的數字來表示年份 | {0:yy} | 12 | |
| yyy | 三個位數的數字來表示年份 | {0:yyy} | 2012 | |
| yyyy | 四個位數的數字來表示年份 | {0:yyyy} | 2012 | |
| zz | 時差(小時) | {0:zz} | +08 | 系統時區與格林威治標準時間 (GMT) 時差 | 
| zzz | 時差(小時&分鐘) | {0:zzz} | +08:00 | 系統時區與格林威治標準時間 (GMT) 時差 (帶正負號) | 
| : | 時間分隔符號 | {0:hh:mm:ss} | 02:29:06 | |
| / | 日期分隔符號 | {0:yyyy/MM/dd} | 2012/03/11 | 
| 英文 | 中文 | 類似概念 | 舉例 | 
| class | 類別 | 類別:請視為→設計圖 或看成→自訂的型別 (下定義、分門別類) | ex:定義"人 "類別.. | 
| property | 屬性 | 名詞 語法似C語言的變數 | 人有: 性別,生日,身高,體重,... | 
| method | 方法 | 動詞 也有翻譯成:行為 語法似C語言的function | 人會: 跑,跳,吃,喝,... | 
| object | 物件 | 屬於該類別的實體物 | 張三,李四,志明,春嬌,... | 
namespace example
{
    class Student
    {
        // Property 屬性
        public int grade; // 幾年級
        public string name; // 姓名
        // Method 方法
        public string Say() // 說:自我介紹
        {
            return "我叫" + name + ",我是" + grade + "年級";
        }
        public string Talk(Student s) // 有輸入:Student
        {
            return grade + "年級的" + name + "對" + s.name + "說早安~";
        }
        public void Upgrade() // 升高一個年級
        {
            grade++;
        }
    }
}
namespace example
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Student s1 = new Student(); // 新增物件
            s1.grade = 1;               // 設定屬性
            s1.name = "張三";
            Student s2 = new Student();
            s2.grade = 2;
            s2.name = "李四";
            // 方法測試1
            MessageBox.Show(s1.Say());
            MessageBox.Show(s1.Talk(s2));
            // 方法測試2
            MessageBox.Show(s1.Say());
            s1.Upgrade();
            MessageBox.Show(s1.Say());
        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinFormEX1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int score;
            if (!int.TryParse(textBox1.Text, out score)) //把字串轉換為int,傳值給score
            {
                //若轉換失敗,會傳 0 給score
                textBox1.Text = "0"; // 把畫面也更新為0
            }
            if (score < 100 && score >= 0)//輸入的數值介於 0~100之間
            {
                MessageBox.Show("你要被打" + (100 - score) + "下屁股");
            }
            else if (score < 0 || score > 100)//輸入值 大於100 或 小於 0
            {
                MessageBox.Show("小小年紀就說謊,看我不打死你才怪");
            }
            else//只有100分會執行這個條件
            {
                MessageBox.Show("恭喜你,滿分不用被打屁股");
            }
        }
    }
}
this.AcceptButton = button1; // 按Enter預設執行的button指定為button1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HelloWorld // 依專案名稱
{
    class Program
    {
        static void Main(string[] args)
        {
            // 兩行解決
            Console.WriteLine("Hello World");
            Console.ReadKey();
        }
    }
}
| Brush name | Brush aliases | File name | 
|---|---|---|
| Bash/shell | bash, shell | shBrushBash.js | 
| C# | c-sharp, csharp | shBrushCSharp.js | 
| C++ | cpp, c | shBrushCpp.js | 
| CSS | css | shBrushCss.js | 
| Delpi | delphi, pas, pascal | shBrushDelphi.js | 
| Diff | diff, patch | shBrushDiff.js | 
| Groovy | groovy | shBrushGroovy.js | 
| JavaScript | js, jscript, javascript | shBrushJScript.js | 
| Java | java | shBrushJava.js | 
| Perl | perl, pl | shBrushPerl.js | 
| PHP | php | shBrushPhp.js | 
| Plain Text | plain, text | shBrushPlain.js | 
| Python | py, python | shBrushPython.js | 
| Ruby | rails, ror, ruby | shBrushRuby.js | 
| Scala | scala | shBrushScala.js | 
| SQL | sql | shBrushSql.js | 
| Visual Basic | vb, vbnet | shBrushVb.js | 
| XML | xml, xhtml, xslt, html, xhtml | shBrushXml.js |