學習 動態產生元件、委派、共用一個事件
學習 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 |