---
# System prepended metadata

title: 112物件導向實習

---

# 112物件導向實習
## 2024/2/21
### 你的名字
```
// See https://aka.ms/new-console-template for more information
Console.Write("請輸入你的名字");
string name = Console.ReadLine();
Console.WriteLine($"Good Day！{name}");
```
![image](https://hackmd.io/_uploads/HJAjG1X3p.png)

### 提款G
```
Console.Write("請輸入名稱：");
string? n = Console.ReadLine();
Console.Write("請輸入提款金額：");
int m = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Hi {n}, 提款金額：{m:C0}");


![image](https://hackmd.io/_uploads/HJi0xqr6T.png)




```
### 課堂作業
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace s1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "確定沒問題";
        }

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

        private void button3_Click(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            label1.Text = "hello";
        }
    }
}
```
![image](https://hackmd.io/_uploads/HJkFvxbkC.png)
![image](https://hackmd.io/_uploads/B1Q9vxZJA.png)
![image](https://hackmd.io/_uploads/HkJhwlZkR.png)


![image](https://hackmd.io/_uploads/BkKxNogTT.png)
## 2024/3/6
### 資料大小
```
using System.Net.Sockets;
using static System.Console;
WriteLine("資訊一甲17號翁叡毅");
WriteLine("");
int number1 = 1_23_456;
long number2 = 456_789_123L;

long max = Int64.MaxValue;
long min = Int64.MinValue;
int number3 = 0b1011_10;
int number4 = 0b_111_110_10;
int number5 = 0x_FB12;

WriteLine($"Number:{number1:N0}, {number2:n0}");

WriteLine($"二進位變十進位: {number3:D5}, {number4:D4}, { number5: D6}");

WriteLine($".NET Framework型別()number1): {number1.GetType()}");

 WriteLine($".NET Framework型別(number2): {number2.GetType()}");
```
![image](https://hackmd.io/_uploads/rkTK7tRaa.png)

### 練習二
```
using static System.Console;

WriteLine("資訊一甲17號翁叡毅");
WriteLine(" ");
float num1 = 1.2233445566778899F;
double num2 = 1.2233445566778899;
decimal num3 = 1.2233445566778899M;
double x1 = 0.1, x2 = 0.2;
decimal y1 = 0.1M, y2 = 0.2M;
WriteLine($"float: {num1}");
WriteLine($"double: {num2}");
WriteLine($"decimal: {num3}");
WriteLine($"float: {num1:f4}");
WriteLine($"double佔< { sizeof(double)} >位元組");
WriteLine($"decimal佔< {sizeof(decimal)} >位元組");

```
![image](https://hackmd.io/_uploads/Hy1X2fZ1R.png)

### 練習三
```
using static System.Console;

WriteLine("資訊一甲17號翁叡毅");
WriteLine(" ");
const float sq = 3.0579F;
Write("請輸入坪數");
float a = Convert.ToSingle(ReadLine());
WriteLine($"{a}坪 = {sq*a}平方公尺");

const float p = 3.14159F;
const float c = p * 25.0F;
WriteLine($"圓面積 ->{c}");
```
![image](https://hackmd.io/_uploads/ryMvhMbyC.png)

### 練習四
```
using static System.Console;

WriteLine("資訊一甲17號翁叡毅");
WriteLine(" ");
Write("請輸入生日");
string bir = ReadLine();
DateTime special = Convert.ToDateTime(bir); 
DateTime Atonce = DateTime.Now;
string thisday = Convert.ToString(Atonce);
WriteLine($"今天是{thisday} /n 你的生日 {special}");

```
### 作業
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                int loan, year, money, month;
                double rate, payrate, mrate;
                loan = int.Parse(textBox1.Text);
                rate = int.Parse(textBox4.Text)/100.0;
                year = int.Parse(textBox3.Text);
                mrate = rate / 12;
                month = year * 12;
                payrate = ((Math.Pow((1 + rate / 12), year * 12) * rate / 12)) / (Math.Pow((1 + rate / 12), year * 12) - 1);
                money = (int)(loan*payrate +0.5);
                label6.Text = money.ToString();
            }
            catch
            {
                label6.Text = "Error";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = " ";
            label6.Text = " ";
            textBox3.Text = " ";
            textBox4.Text = " ";
        }
    }
}
```
## 20240313
### 練習1:
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.MaxLength = 3;
            textBox2.ReadOnly = true;
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                double C = Convert.ToDouble(textBox1.Text);
                double F =  C * 9 / 5 + 32;
                textBox2.Text = F.ToString();
                
            }
            catch 
            {
                textBox2.Text = "Please enter the value";
                textBox2.Clear();

            }
        }
    }
}

```
![image](https://hackmd.io/_uploads/rybn_lbk0.png)
### 練習2
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string n = Microsoft.VisualBasic.Interaction.InputBox("請輸入姓名", "輸入");
            DialogResult dr = MessageBox.Show(n+"歡迎你","歡迎",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
            Text = n;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int i = Convert.ToInt32(textBox2.Text);
                label4.Text = $"提款金額 :{i:N} 元";

            }
            catch
            {
                MessageBox.Show("請輸入整數","注意",
                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}


```

![image](https://hackmd.io/_uploads/BJacuxWJA.png)
### 課堂作業
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string n = Microsoft.VisualBasic.Interaction.InputBox("請輸入姓名", "輸入");
            DialogResult dr = MessageBox.Show(n+"歡迎你","歡迎",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
            Text = n;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            float[] score = new float[] {
                Convert.ToSingle(textBox1.Text),
                Convert.ToSingle(textBox2.Text),
                Convert.ToSingle(textBox3.Text),
                Convert.ToSingle(textBox4.Text),
                Convert.ToSingle(textBox5.Text) };

            float sum = 0.0F;
            int len = score.Length;
            float max = 97;
            string top = string.Empty;

            for (int i = 0; i < score.Length; i++)
            {
                sum += score[i];
                if (score[i] > max)
                    max = score[i];
            }
            float avg = sum / (float)len;
            label6.Text = "總分= "+sum.ToString();
            label7.Text = "平均= "+avg.ToString();
            label8.Text = "最高= "+max.ToString(); 
        }
    }
 }

```
![image](https://hackmd.io/_uploads/rkXoKlZy0.png)
## 20240320
### 練習:
```
using static System.Console;

int sum = 0, cnt = 0;

for (; ; )
{
    Write("請輸入交往天數做加總:");
    int num = Convert.ToInt32(ReadLine());
    cnt++;
    sum += num;

    Write("還要複合嗎?(y繼續,n離開)");
    string endkey = ReadLine();

    if (endkey == "y" || endkey == "Y")
        continue;
    else if (endkey == "n" || endkey == "N")
        break;
}

WriteLine($"輸入{cnt}個數值，合計:{sum}");

ReadKey();
```
![image](https://hackmd.io/_uploads/SyFQhlOAT.png)

### 課堂作業
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string idChar = "abcdefghijklmopqrstuvwxyz";
        string[] idCity = {"台北市","台中市","基隆市","台南市","高雄市","新北市","宜蘭縣","桃園縣",
             "新竹縣","苗栗國","台中市","南投縣","彰化縣","雲林縣","嘉義縣","台南市","高雄市",
             "屏東縣","花蓮國","台東縣","澎湖縣","陽明山","金門縣","連江縣","嘉義市","新竹市"};
        string msg = "";
        string id, gender;

        Random r = new Random();

        private void button2_Click(object sender, EventArgs e)
        {
            int sum = 0,idPos = 0;
            idPos = r.Next(26);
            id = idChar.Substring(idPos,1).ToUpper();
            sum = (idPos + 10) / 10 + (idPos % 10) * 9;

            idPos = r.Next(2) + 1;
            id += idPos.ToString();
            sum += idPos * 8;

            for(int i = 2; i < 9; i++)
            {
                idPos = r.Next(10);
                id += idPos.ToString();
                sum += idPos * (9-i);
            }
            if (sum % 10 == 0)
                idPos = 0;
            else
                idPos = 10-(sum%10);
            id += idPos.ToString();
            sum += idPos;
            textBox1.Text = id;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length == 10)
            {
                int sum = 0, idPos = 0;
                id = textBox1.Text;
                idPos = idChar.IndexOf(id.Substring(0, 1).ToLower());
                sum = ((idPos + 10) / 10 + (idPos % 10) * 9)%10;
                gender = id.Substring(1, 1);
                for (int i = 1; i < 9; i++)
                    sum += Convert.ToInt32(id.Substring(i, 1)) * (9 - i);
                //sum += Convert.ToInt32(id.Substring(1, 1));
                if ((10-(sum % 10))%10 == Convert.ToInt32(id.Substring(9,1)))
                    msg = sum.ToString() + ",正確," + idCity[idPos];
                else
                    msg = sum.ToString() + "錯誤";
                if (gender == "1")
                    msg += " 男";
                else
                    msg += " 女";
            }
            else
                msg = "錯誤";
            label3.Text = msg;
        }

    }
}

```
![image](https://hackmd.io/_uploads/SybHKg-kC.png)
 ## 20240327
 ### 練習1
```
// See https://aka.ms/new-console-template for more information
string[] name = { "Molly", "Eric", "Johseph", "Peter", "Iron", "Priyanka" };
int[] age = { 24, 26, 24, 26, 28, 25 };
int index = Array.IndexOf(age, 24);
Console.WriteLine("---年齡符合24歲---\n");
while (index >= 0)
{
    Console.WriteLine($"{name[index],-8}");
    index = Array.IndexOf(age, 24, index + 1);

}
Array.Sort(age);
var key = Array.BinarySearch(age, 25);
switch (key)
{
    case >= 0:
        Console.WriteLine($"\n找到年齡25!位置={key}");
        break;
    default:
        Console.WriteLine($"\n未找到年齡25!位置={key}");
        break;

}

```
![image](https://hackmd.io/_uploads/BJlwrZ-y0.png)

### 練習2
```
Console.WriteLine("資訊一甲 17翁叡毅");
Console.WriteLine(" ");
int outer, inner;
int[] sum = new int[3];
string[] name = { "Marry", "Tori", "John" };
foreach (string item in name)
    Console.Write("{0,7}", item);
Console.WriteLine();
int[,] score = { { 75, 65, 96 }, { 55, 67, 39 }, { 45, 92, 85 }, { 71, 69, 81 } };
int row = score.GetLength(0);
int column = score.GetLength(1);

for (outer = 0; outer < row; outer++)
{
    for (inner = 0; inner < column; inner++)
        Console.Write($"{score[outer, inner],7}");
    Console.WriteLine();
    sum[0] += score[outer, 0];
    sum[1] += score[outer, 1];
    sum[2] += score[outer, 2];
}
Console.WriteLine("-----------------------");
Console.WriteLine($"sum:{sum[0]} {sum[1],5}{sum[2],6}");
```
![image](https://hackmd.io/_uploads/Byv2c-bk0.png)

### 練習3
```
Console.WriteLine("資訊一甲17 翁叡毅");
Console.WriteLine(" ");
int[,,] num3D = new int[2, 2, 3]
{ { { 11,13,15},{ 22,24,26} },{ { 33,38,41},{ 44,48,52} } };
Console.Write($"元素:{num3D[1, 1, 1]}," + $"位於第2個表格,位於第2列 第2欄\n");
int table = num3D.GetLength(0);
int row = num3D.GetLength(1);
int column = num3D.GetLength(2);
Console.Write($"表格{table} 個,二維表格{row}*{column}\n");
for (int i = 0; i < table; i++)
{
    Console.WriteLine($"----表格{i + 1}----");
    for (int j = 0; j < row; j++)
    {
        for (int k = 0; k < column; k++)
            Console.Write($"{num3D[i, j, k],3} |");
        Console.WriteLine();
    }
    Console.WriteLine();
}

```
![image](https://hackmd.io/_uploads/HkHXiZZyR.png)
### 作業1
```
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int total;
            string msg;
            total = checkBox1.Checked == true ? 1 : 5;
            msg = checkBox1.Checked == true ? "棉花" : "木頭";
            msg += "黑奴\n黑人伙食:";
            msg += checkBox2.Checked ? "炸雞" : checkBox2.Checked ? "玉米糊" : "不給他們東西吃;";
            if (checkBox1.Checked == true)
            {
                msg += "\n使用鞭子";

            }
            if (checkBox1.Checked == true)
            {
                total += 30;
                msg += "\n使用狐鼠步槍";

            }
            msg += $"\n總價:{total}元";
            MessageBox.Show(msg, "購物清單", MessageBoxButtons.OK, MessageBoxIcon.None);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}

```
![image](https://hackmd.io/_uploads/H1tvSf-1A.png)

### 作業2
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(ClstBooks.CheckedItems.Count +ClstBorrow.CheckedItems.Count>2) 
            {
                MessageBox.Show("最多兩本", "注意");
                for (int i = 0; i < ClstBooks.Items.Count; i++)
                    ClstBooks.SetItemChecked(i, false);
            }
            else
            {
                for (int i = ClstBooks.Items.Count - 1; i >= 0; i--)
                {
                    if(ClstBooks.GetItemChecked(i)==true)
                    {
                        if (ClstBooks.GetItemChecked(i) == true) ClstBorrow.Items.Add(ClstBooks.Items[i]);
                        if (ClstBooks.GetItemChecked(i) == true) ClstBooks.Items.RemoveAt(i);

                    }
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] books = new string[] { "三國演義", "水滸傳", "西遊記", "紅樓夢", "聊齋志異", "鏡花緣" };
            ClstBooks.Items.AddRange(books);
            ClstBooks.CheckOnClick = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach(int i in ClstBorrow.CheckedIndices)
                if (ClstBorrow.GetItemChecked(i) == true) ClstBooks.Items.Add(ClstBorrow.Items[i]);
            for (int i = ClstBorrow.Items.Count - 1; i >= 0; i--)
            {
                if(ClstBorrow.GetItemChecked(i)==true) 
                    ClstBorrow.Items.RemoveAt(i);
            }
        }
            
    }
}
```

## 20240410 
### 練習一

```
private void Form1_Load(object sender, EventArgs e)
{
    // 設定圖片顯示模式為拉伸
    PicShow.SizeMode = PictureBoxSizeMode.StretchImage;

    // 設定初始圖片高度與寬度
    PicShow.Height = 90;
    PicShow.Width = 90;

    // 載入初始圖片
    PicShow.Image = Image.FromFile($"C:\\Users\\popst\\Pictures\\miyu_art\\pic1.png");

    // 設定滑桿最大最小值與初始值
    TkbPic.Maximum = 3;
    TkbPic.Minimum = 1;

    // 設定垂直滾動條的最大最小值與初始值
    VsbHeight.Maximum = 180;
    VsbHeight.Minimum = 1;
    VsbHeight.LargeChange = 1;
    VsbHeight.Value = PicShow.Height;

    // 設定水平滾動條的最大最小值與初始值
    HsbWidth.Maximum = 180;
    HsbWidth.Minimum = 1;
    HsbWidth.LargeChange = 1;
    HsbWidth.Value = PicShow.Width;

    // 設定工具提示內容
    Ttip.SetToolTip(VsbHeight, $"{VsbHeight.Value}");
    Ttip.SetToolTip(HsbWidth, $"{HsbWidth.Value}");
    Ttip.SetToolTip(TkbPic, "pic1");
}

// 垂直滾動條滾動事件
private void VsbHeight_Scroll(object sender, ScrollEventArgs e)
{
    // 調整圖片高度並更新工具提示內容
    PicShow.Height = VsbHeight.Value;
    Ttip.SetToolTip(VsbHeight, $"{VsbHeight.Value}");
}

// 水平滾動條滾動事件
private void HsbWidth_Scroll(object sender, ScrollEventArgs e)
{
    // 調整圖片寬度並更新工具提示內容
    PicShow.Width = HsbWidth.Value;
    Ttip.SetToolTip(HsbWidth, $"{HsbWidth.Value}");
}

// 圖片切換滑桿滾動事件
private void TkbPic_Scroll(object sender, EventArgs e)
{
        // 切換圖片並更新工具提示內容
        PicShow.Image = Image.FromFile($"C:\\Users\\popst\\Pictures\\miyu_art\\pic{TkbPic.Value}.png");
        Ttip.SetToolTip(TkbPic, $"pic{TkbPic.Value}");
    }

    private void PicShow_Click(object sender, EventArgs e)
    {

        }
    }
}
```
圖片資料夾一直找不到所以執行畫面跑不出來
### 練習二
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _0410
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            DtpAlarm.CustomFormat = "yyyy-MM-dd HH:mm";
            DtpAlarm.Format = DateTimePickerFormat.Custom;
            DtpAlarm.MinDate = DateTime.Now.AddMinutes(1);
            DtpAlarm.MaxDate = DateTime.Now.AddDays(7);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timerl.Interval = 1000;
            timerl.Enabled = true;
            DtpAlarm.Enabled = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now >= DtpAlarm.Value)
            {
                timerl.Enabled = false;
                System.Media.SystemSounds.Beep.Play(); // 發出系統Beep聲
                MessageBox.Show(textBox1. Text,"提示");
            }
        }
    }
}

```
![1714488509856](https://hackmd.io/_uploads/HJ6A4t0W0.png)



### 作業1
```

namespace WinFormsApp2
{
    public partial class Form1 : Form
    {
        int n = 0;
        string[] tea = new string[] { "丁丁", "拉拉", "迪西", "小波", "努努" };
        int[] score = new int[5];
        int sum = 0;
        int number;

        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

            label1.Text = tea[n] + "老師給分";
            label2.Text = "";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            if (Int32.TryParse(textBox1.Text, out number))
            {
                if (number <= 100 && number >= 0)
                {

                    listBox1.Items.Add ($"{tea[n]}:{number}");
                    if (n != 4)
                    {
                         n++;
                        label1.Text = $"{score[n]} score";
                        label1.Text = $"{tea[n]}老師分";

                    }
                    else
                    {
                        button1.Enabled = false;

                    }
                    sum += number;
                     label2.Text = $"平均: {(double)sum / listBox1.Items.Count:0.##}";

                    textBox1.Text = "";

                }

                
                    
                
            }

        }
    }
}

```
![image](https://hackmd.io/_uploads/B1VbZ5QxR.png)

## 20240417

### 練習一
```
{
    partial class Form1
    {
        /// <summary>
        /// 設計工具所需的變數。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清除任何使用中的資源。
        /// </summary>
        /// <param name="disposing">如果應該處置受控資源則為 true，否則為 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form 設計工具產生的程式碼

        /// <summary>
        /// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器修改
        /// 這個方法的內容。
        /// </summary>
        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.listCry = new System.Windows.Forms.ListBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.radAny = new System.Windows.Forms.RadioButton();
            this.radGirl = new System.Windows.Forms.RadioButton();
            this.radBoy = new System.Windows.Forms.RadioButton();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.txtNum = new System.Windows.Forms.TextBox();
            this.btnGo = new System.Windows.Forms.Button();
            this.btnSave = new System.Windows.Forms.Button();
            this.txtBox = new System.Windows.Forms.Label();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.listCry);
            this.groupBox1.Location = new System.Drawing.Point(110, 51);
            this.groupBox1.Margin = new System.Windows.Forms.Padding(5);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Padding = new System.Windows.Forms.Padding(5);
            this.groupBox1.Size = new System.Drawing.Size(195, 182);
            this.groupBox1.TabIndex = 2;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "縣市";
            // 
            // listCry
            // 
            this.listCry.FormattingEnabled = true;
            this.listCry.ItemHeight = 19;
            this.listCry.Location = new System.Drawing.Point(9, 32);
            this.listCry.Name = "listCry";
            this.listCry.Size = new System.Drawing.Size(178, 137);
            this.listCry.TabIndex = 0;
            this.listCry.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
            // 
            // groupBox2
            // 
            this.groupBox2.BackColor = System.Drawing.SystemColors.ButtonHighlight;
            this.groupBox2.Controls.Add(this.radAny);
            this.groupBox2.Controls.Add(this.radGirl);
            this.groupBox2.Controls.Add(this.radBoy);
            this.groupBox2.Location = new System.Drawing.Point(367, 49);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(254, 73);
            this.groupBox2.TabIndex = 3;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "性別";
            // 
            // radAny
            // 
            this.radAny.AutoSize = true;
            this.radAny.Location = new System.Drawing.Point(150, 41);
            this.radAny.Name = "radAny";
            this.radAny.Size = new System.Drawing.Size(65, 23);
            this.radAny.TabIndex = 2;
            this.radAny.TabStop = true;
            this.radAny.Text = "任意";
            this.radAny.UseVisualStyleBackColor = true;
            this.radAny.CheckedChanged += new System.EventHandler(this.radAny_CheckedChanged);
            // 
            // radGirl
            // 
            this.radGirl.AutoSize = true;
            this.radGirl.Location = new System.Drawing.Point(78, 41);
            this.radGirl.Name = "radGirl";
            this.radGirl.Size = new System.Drawing.Size(65, 23);
            this.radGirl.TabIndex = 1;
            this.radGirl.TabStop = true;
            this.radGirl.Text = "女生";
            this.radGirl.UseVisualStyleBackColor = true;
            this.radGirl.CheckedChanged += new System.EventHandler(this.radGirl_CheckedChanged);
            // 
            // radBoy
            // 
            this.radBoy.AutoSize = true;
            this.radBoy.Location = new System.Drawing.Point(7, 41);
            this.radBoy.Name = "radBoy";
            this.radBoy.Size = new System.Drawing.Size(65, 23);
            this.radBoy.TabIndex = 0;
            this.radBoy.TabStop = true;
            this.radBoy.Text = "男生";
            this.radBoy.UseVisualStyleBackColor = true;
            this.radBoy.CheckedChanged += new System.EventHandler(this.radBoy_CheckedChanged);
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.txtNum);
            this.groupBox3.Location = new System.Drawing.Point(374, 146);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(247, 87);
            this.groupBox3.TabIndex = 4;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "人數";
            // 
            // txtNum
            // 
            this.txtNum.Location = new System.Drawing.Point(7, 44);
            this.txtNum.Name = "txtNum";
            this.txtNum.Size = new System.Drawing.Size(234, 30);
            this.txtNum.TabIndex = 0;
            this.txtNum.TextChanged += new System.EventHandler(this.txtNum_TextChanged);
            // 
            // btnGo
            // 
            this.btnGo.Location = new System.Drawing.Point(119, 542);
            this.btnGo.Name = "btnGo";
            this.btnGo.Size = new System.Drawing.Size(95, 49);
            this.btnGo.TabIndex = 6;
            this.btnGo.Text = "Go";
            this.btnGo.UseVisualStyleBackColor = true;
            this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
            // 
            // btnSave
            // 
            this.btnSave.Location = new System.Drawing.Point(350, 542);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(102, 49);
            this.btnSave.TabIndex = 7;
            this.btnSave.Text = "Save";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // txtBox
            // 
            this.txtBox.Location = new System.Drawing.Point(115, 276);
            this.txtBox.Name = "txtBox";
            this.txtBox.Size = new System.Drawing.Size(506, 229);
            this.txtBox.TabIndex = 8;
            this.txtBox.Text = "label1";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 19F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(766, 635);
            this.Controls.Add(this.txtBox);
            this.Controls.Add(this.btnSave);
            this.Controls.Add(this.btnGo);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Font = new System.Drawing.Font("新細明體", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136)));
            this.Margin = new System.Windows.Forms.Padding(5);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.RadioButton radGirl;
        private System.Windows.Forms.RadioButton radBoy;
        private System.Windows.Forms.ListBox listCry;
        private System.Windows.Forms.RadioButton radAny;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.TextBox txtNum;
        private System.Windows.Forms.Button btnGo;
        private System.Windows.Forms.Button btnSave;
        private System.Windows.Forms.Label txtBox;
    }
}
```
![upload_8c15ce2a3035f4f954021dcc9821af3a](https://hackmd.io/_uploads/S11TGcWX0.png)
### 練習2
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _0417
{
    public partial class Form1 : Form
    {
        public Form1()
        {InitializeComponent();}

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel1.Text = "Visual Studio web";
            System.Diagnostics.Process.Start("https://visualstudio.microsoft.com/zh-hant/");
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("C:\\Users\\user\\Downloads\\20240306w\\20240306w\\bin\\Debug\\20240306w.exe");
        }
    }
```
![1715746233824](https://hackmd.io/_uploads/rybWLh-7C.png)






