2017年5月20日 星期六

C# 自動滑鼠ATM_Lite ver0.97的程式碼

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;
using System.Threading;
using System.Runtime.InteropServices;
using System.Configuration;
using System.IO;

namespace 自動滑鼠ATM_Lite
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //需要宣告的變數,集中在這裡管理,第一部分是固定設定的變數
        Byte ED;//用來判斷現在正在編輯的檔案是哪一個,是整個程式運作的核心變數
        bool btop, bhide, bshow, bcome, bstop, bnext;//看是否保持在最上層,啟動後是否隱藏,停止後是否出現,是否回到原位,是否停止其他動作,是否接續下個動作

        //第二部分是陣列
        string[] name = new string[12];//儲存動作名稱
        short[] tt = new short[12];//儲存總次數 tatol times
        short[] ct = new short[12];//儲存目標循環次數 cycle times
        int[] iv = new int[12];//儲存間隔時間interval
        Byte[] hk = new Byte[12];//儲存啟動停止熱鍵Hot Key
        Byte[] na = new Byte[12];//儲存下一個動作的設定Next Action

        //第三部分為暫存性變數
        bool[] doing = new bool[12];//儲存動作是否正在進行當中
        short[] step = new short[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };//儲存已執行步驟數
        short[] ce = new short[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };//儲存已執行循環次數
        short[] x = new short[12];
        short[] y = new short[12];
        Byte[] z = new Byte[12];
        Byte times = 0;//儲存暫時的次數
        short slc, slr;//儲存datagridview中所選擇的行與列select column, select row
        short xcome, ycome;
        bool ldown, rdown, mdown;//看滑鼠按鍵是否處於按下狀態,為避免程式錯誤而設
        string xe, ye, ze, ae, we, st;//編輯時的暫存資料區
        bool cut; short cuti;//剪下按鈕的標記
        bool ctrl, alt, shift, edhk;
        Double opacity;//設定透明度

        GlobalKeyboardHook gHook;//全域鍵盤監控
        int kv;//儲存keyValue值
        //
        //
        //呼叫API
        [DllImport("User32")] public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr ExtraInfo);
        [DllImport("User32")] public extern static void SetCursorPos(int x, int y);
        [DllImport("User32")] public extern static bool GetCursorPos(out Point p);
        [DllImport("User32")] public extern static int ShowCursor(bool bShow);
        [DllImport("User32")] public static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
        [DllImport("User32")] public static extern bool SetForegroundWindow(IntPtr hWnd);
        //宣告滑鼠動作
        public enum MouseEventTFlags
        {
            MOVE = 0x00000001,
            LEFTDOWN = 0x00000002,
            LEFTUP = 0x00000004,
            RIGHTDOWN = 0x00000008,
            RIGHTUP = 0x00000010,
            MIDDLEDOWN = 0x00000020,
            MIDDLEUP = 0x00000040,
        }
        //
//必備的Load事件
        private void Form1_Load(object sender, EventArgs e)
        {
            //載入時要將設定檔中的資料數字讀進記憶體裡
            ED = Properties.Settings.Default.ED; btop = Properties.Settings.Default.btop;
            bhide = Properties.Settings.Default.bhide; bshow = Properties.Settings.Default.bshow; opacity = Properties.Settings.Default.opacity;
            bcome = Properties.Settings.Default.bcome; bstop = Properties.Settings.Default.bstop; bnext = Properties.Settings.Default.bnext;
            name[0] = Properties.Settings.Default.name0; name[1] = Properties.Settings.Default.name1; name[2] = Properties.Settings.Default.name2; name[3] = Properties.Settings.Default.name3;
            name[4] = Properties.Settings.Default.name4; name[5] = Properties.Settings.Default.name5; name[6] = Properties.Settings.Default.name6; name[7] = Properties.Settings.Default.name7;
            name[8] = Properties.Settings.Default.name8; name[9] = Properties.Settings.Default.name9; name[10] = Properties.Settings.Default.name10; name[11] = Properties.Settings.Default.name11;
            tt[0] = Properties.Settings.Default.tt0; tt[1] = Properties.Settings.Default.tt1; tt[2] = Properties.Settings.Default.tt2; tt[3] = Properties.Settings.Default.tt3;
            tt[4] = Properties.Settings.Default.tt4; tt[5] = Properties.Settings.Default.tt5; tt[6] = Properties.Settings.Default.tt6; tt[7] = Properties.Settings.Default.tt7;
            tt[8] = Properties.Settings.Default.tt8; tt[9] = Properties.Settings.Default.tt9; tt[10] = Properties.Settings.Default.tt10; tt[11] = Properties.Settings.Default.tt11;
            ct[0] = Properties.Settings.Default.ct0; ct[1] = Properties.Settings.Default.ct1; ct[2] = Properties.Settings.Default.ct2; ct[3] = Properties.Settings.Default.ct3;
            ct[4] = Properties.Settings.Default.ct4; ct[5] = Properties.Settings.Default.ct5; ct[6] = Properties.Settings.Default.ct6; ct[7] = Properties.Settings.Default.ct7;
            ct[8] = Properties.Settings.Default.ct8; ct[9] = Properties.Settings.Default.ct9; ct[10] = Properties.Settings.Default.ct10; ct[11] = Properties.Settings.Default.ct11;
            iv[0] = Properties.Settings.Default.iv0; iv[1] = Properties.Settings.Default.iv1; iv[2] = Properties.Settings.Default.iv2; iv[3] = Properties.Settings.Default.iv3;
            iv[4] = Properties.Settings.Default.iv4; iv[5] = Properties.Settings.Default.iv5; iv[6] = Properties.Settings.Default.iv6; iv[7] = Properties.Settings.Default.iv7;
            iv[8] = Properties.Settings.Default.iv8; iv[9] = Properties.Settings.Default.iv9; iv[10] = Properties.Settings.Default.iv10; iv[11] = Properties.Settings.Default.iv11;
            hk[0] = Properties.Settings.Default.hk0; hk[1] = Properties.Settings.Default.hk1; hk[2] = Properties.Settings.Default.hk2; hk[3] = Properties.Settings.Default.hk3;
            hk[4] = Properties.Settings.Default.hk4; hk[5] = Properties.Settings.Default.hk5; hk[6] = Properties.Settings.Default.hk6; hk[7] = Properties.Settings.Default.hk7;
            hk[8] = Properties.Settings.Default.hk8; hk[9] = Properties.Settings.Default.hk9; hk[10] = Properties.Settings.Default.hk10; hk[11] = Properties.Settings.Default.hk11;
            na[0] = Properties.Settings.Default.na0; na[1] = Properties.Settings.Default.na1; na[2] = Properties.Settings.Default.na2; na[3] = Properties.Settings.Default.na3;
            na[4] = Properties.Settings.Default.na4; na[5] = Properties.Settings.Default.na5; na[6] = Properties.Settings.Default.na6; na[7] = Properties.Settings.Default.na7;
            na[8] = Properties.Settings.Default.na8; na[9] = Properties.Settings.Default.na9; na[10] = Properties.Settings.Default.na10; na[11] = Properties.Settings.Default.na11;

            //將設定的內容顯示在各控制項上
            comboBoxDataName.Items.Add(name[0]); comboBoxDataName.Items.Add(name[1]); comboBoxDataName.Items.Add(name[2]); comboBoxDataName.Items.Add(name[3]);
            comboBoxDataName.Items.Add(name[4]); comboBoxDataName.Items.Add(name[5]); comboBoxDataName.Items.Add(name[6]); comboBoxDataName.Items.Add(name[7]);
            comboBoxDataName.Items.Add(name[8]); comboBoxDataName.Items.Add(name[9]); comboBoxDataName.Items.Add(name[10]); comboBoxDataName.Items.Add(name[11]);
            comboBoxNext.Items.Add(name[0]); comboBoxNext.Items.Add(name[1]); comboBoxNext.Items.Add(name[2]); comboBoxNext.Items.Add(name[3]);
            comboBoxNext.Items.Add(name[4]); comboBoxNext.Items.Add(name[5]); comboBoxNext.Items.Add(name[6]); comboBoxNext.Items.Add(name[7]);
            comboBoxNext.Items.Add(name[8]); comboBoxNext.Items.Add(name[9]); comboBoxNext.Items.Add(name[10]); comboBoxNext.Items.Add(name[11]);
            comboBoxNext.Items.Add("無");

            if (btop == true) { this.TopMost = true; checkBox1.Checked = true; }
            if (bhide == true) { checkBox2.Checked = true; }
            if (bshow == true) { checkBox3.Checked = true; }
            if (bcome == true) { checkBox4.Checked = true; }
            if (bstop == true) { checkBox5.Checked = true; }
            if (bnext == true) { checkBox6.Checked = true; }
            trackBar1.Value = Convert.ToInt32(opacity * 100); this.Opacity = opacity;

            comboBoxDataName.SelectedIndex = ED;//由於這一句會觸發SelectedIndexChanged事件,所以有些本應寫在load事件中的程式碼,因與change事件重複,故直接使用change事件中的程式碼即可
            setdgv();

            gHook = new GlobalKeyboardHook();
            gHook.KeyDown += new KeyEventHandler(gHook_KeyDown);
            gHook.KeyUp += new KeyEventHandler(gHook_KeyUp);
            foreach (Keys key in Enum.GetValues(typeof(Keys)))
            gHook.HookedKeys.Add(key);
            gHook.hook();

            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            for (int i = 0; i <= 11; i++)
            {
                for (int j =0; j <= 5; j++)
                {
                    ((System.Windows.Forms.DataGridViewTextBoxColumn)dgv[i].Columns[j]).MaxInputLength = 12;
                }
            }
        }
        //
        //
        //鍵盤事件
        public void gHook_KeyDown(object sender, KeyEventArgs e)
        {
            kv = (int)e.KeyValue;
            switch (kv)
            {
                case 112: for (Byte i = 0; i < 12; i++) { if (hk[i] == 0 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 0 && doing[i] == true) { stop(i); } } break;
                case 113: for (Byte i = 0; i < 12; i++) { if (hk[i] == 1 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 1 && doing[i] == true) { stop(i); } } break;
                case 114: for (Byte i = 0; i < 12; i++) { if (hk[i] == 2 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 2 && doing[i] == true) { stop(i); } } break;
                case 115: for (Byte i = 0; i < 12; i++) { if (hk[i] == 3 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 3 && doing[i] == true) { stop(i); } } break;
                case 116: for (Byte i = 0; i < 12; i++) { if (hk[i] == 4 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 4 && doing[i] == true) { stop(i); } } break;
                case 117: for (Byte i = 0; i < 12; i++) { if (hk[i] == 5 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 5 && doing[i] == true) { stop(i); } } break;
                case 118: for (Byte i = 0; i < 12; i++) { if (hk[i] == 6 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 6 && doing[i] == true) { stop(i); } } break;
                case 119: for (Byte i = 0; i < 12; i++) { if (hk[i] == 7 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 7 && doing[i] == true) { stop(i); } } break;
                case 120: for (Byte i = 0; i < 12; i++) { if (hk[i] == 8 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 8 && doing[i] == true) { stop(i); } } break;
                case 121: for (Byte i = 0; i < 12; i++) { if (hk[i] == 9 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 9 && doing[i] == true) { stop(i); } } break;
                case 122: for (Byte i = 0; i < 12; i++) { if (hk[i] == 10 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 10 && doing[i] == true) { stop(i); } } break;
                case 123: for (Byte i = 0; i < 12; i++) { if (hk[i] == 11 && doing[i] == false && tt[i] > 0) { start(i); } else if (hk[i] == 11 && doing[i] == true) { stop(i); } } break;
                case 27: stopAll(); break;//按下ESC就執行全部停止
                case 160: shift = true; break;
                case 161: shift = true; break;
                case 162: ctrl = true; break;
                case 163: ctrl = true; break;
                case 164: alt = true; break;
                case 165: alt = true; break;
            }
        }
        public void gHook_KeyUp(object sender, KeyEventArgs e)
        {
            kv = (int)e.KeyValue;
            switch (kv)
            {
                case 160: shift = false; break;
                case 161: shift = false; break;
                case 162: ctrl = false; break;
                case 163: ctrl = false; break;
                case 164: alt = false; break;
                case 165: alt = false; break;
            }
        }
        //
        //常駐事件
        public void timerPosition_Tick(object sender, EventArgs e)
        {
            labelXP.Text = Cursor.Position.X.ToString();
            labelYP.Text = Cursor.Position.Y.ToString();
        }//用timer不斷更新座標並顯示
        public void labelRecord_MouseDown(object sender, MouseEventArgs e)
        {
            if (doing[0] == false && doing[1] == false && doing[2] == false && doing[3] == false && doing[4] == false && doing[5] == false &&
                doing[6] == false && doing[7] == false && doing[8] == false && doing[9] == false && doing[10] == false && doing[11] == false)
            {
                labelRecord.BackColor = System.Drawing.Color.Tomato; labelRecord.Text = "Recording...";//改變Record標籤的顏色和文字};
            }
        }
        public void labelRecord_MouseUp(object sender, MouseEventArgs e)
        {
            tt[ED] += 1; labeltt.Text = tt[ED].ToString();
            labelRecord.BackColor = System.Drawing.Color.Pink; labelRecord.Text = "Record";//把標籤上的顏色和文字改回來

            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            dgv[ED].Rows.Add(labeltt.Text, labelXP.Text, labelYP.Text, "0", "左鍵點一下", "");
        }

        //
//上方的主要設定
        private void comboBoxDataName_SelectedIndexChanged(object sender, EventArgs e)
        {
            slc = 0; slr = 0;
            ED = Convert.ToByte(comboBoxDataName.SelectedIndex);//選擇多少ED就是多少,然後其他變數跟控制項的顯示再跟著ED走
            labeltt.Text = tt[ED].ToString();
            double ivl; ivl = Convert.ToDouble(iv[ED]); ivl *= 0.001; textBoxInterval.Text = ivl.ToString();
            textBoxCycle.Text = ct[ED].ToString();
            comboBoxHK.SelectedIndex = hk[ED]; comboBoxNext.SelectedIndex = na[ED];
           
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            for (int i = 0; i <= 11; i++) { dgv[i].Visible = false; }
            dgv[ED].Visible = true;
        }
        private void comboBoxDataName_TextChanged(object sender, EventArgs e)
        {
            times = 0; timerNameUpdate.Enabled = true;
        }
        private void timerNameUpdate_Tick(object sender, EventArgs e)
        {
            times++;
            if (times == 3)
            {
                name[ED] = comboBoxDataName.Text;
                comboBoxDataName.Items.Clear(); comboBoxNext.Items.Clear();
                for (Byte i = 0; i <= 11; i++) { comboBoxDataName.Items.Add(name[i]); comboBoxNext.Items.Add(name[i]); }
                comboBoxNext.Items.Add("無");
                comboBoxNext.SelectedIndex = na[ED];
                comboBoxDataName.SelectedIndex = ED;
                times = 0; timerNameUpdate.Enabled = false; comboBoxDataName.Focus();
            }
        }
        private void textBoxInterval_TextChanged(object sender, EventArgs e)
        {
            try
            {
                Double second;
                second = Convert.ToDouble(textBoxInterval.Text);
                second *= 1000;
                if (second >= 60000) { iv[ED] = 60000; textBoxInterval.Text = "60"; }
                else if (second <= 1) { iv[ED] = 1; textBoxInterval.Text = "0.001"; }
                else { iv[ED] = Convert.ToInt32(second); }
            }
            catch
            {
                textBoxInterval.Text = "";
            }
        }
        private void textBoxCycle_TextChanged(object sender, EventArgs e)
        {
            try
            {
                ct[ED] = Convert.ToInt16(textBoxCycle.Text);
            }
            catch
            {
                textBoxCycle.Text = "";
            }
        }
        //
        //右方的設定區
        private void comboBoxHK_SelectedIndexChanged(object sender, EventArgs e)
        {
            hk[ED] = Convert.ToByte(comboBoxHK.SelectedIndex);
        }//選擇的索引值就是對應熱鍵的編號
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true) { this.TopMost = true; btop = true; } else { this.TopMost = false; btop = false; }
        }//設定是否要保持在最上層,按下後立刻生效
        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked == true) { bhide = true; } else { bhide = false; }
            if (checkBox2.Checked == false) { checkBox3.Checked = false; }
        }//開始後隱藏的選項,若沒勾選,則停止後復原的選項也會無效
        public void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked == true) { bshow = true; } else { bshow = false; }
            if (checkBox3.Checked == true) { checkBox2.Checked = true; }
        }//如果結束後恢復視窗的選項打勾,則啟動後隱藏的選項也要跟著勾
        public void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked == true) { bcome = true; } else { bcome = false; }
        }//看停止後滑鼠是否要回到原位
        public void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox5.Checked == true) { bstop = true; } else { bstop = false; }
        }//看開始後是否停止其他動作
        public void checkBox6_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox6.Checked == true) { bnext = true; } else { bnext = false; }
        }//看結束後是否接續下一個動作
        private void comboBoxNext_SelectedIndexChanged(object sender, EventArgs e)
        {
            na[ED] = Convert.ToByte(comboBoxNext.SelectedIndex);
            if (na[ED] == ED) { na[ED] = 12; comboBoxNext.SelectedIndex = 12; }
        }//選擇的索引值就會對應該動作的編號,並將變數存入na陣列中,預設值為12無動作
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            opacity = trackBar1.Value * 0.01;
            this.Opacity = opacity;
        }//透明度設定
         //
//編輯dataGridView相關的程式碼,中間左邊和右邊
        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            slc = Convert.ToInt16(dgv[ED].CurrentCellAddress.X); slr = Convert.ToInt16(dgv[ED].CurrentCellAddress.Y);
        }
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            try
            {
                st = dgv[ED].CurrentCell.Value.ToString();
            }
            catch
            {
                if (slr >= 0 && slr < tt[ED]) { dgv[ED].Rows[slr].Cells[slc].Value = ""; }
            }
        }
        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            kv = (int)e.KeyValue;
            switch (kv)
            {
                case 38: if (ctrl == true) { up(); } break;
                case 40: if (ctrl == true) { down(); } break;
                case 46: if (ctrl == true) { delete(); } break;
                case 67: if (ctrl == true) { copy(); } break;
                case 86: if (ctrl == true) { paste(); } break;
                case 88: if (ctrl == true) { dcut(); } break;
                case 48: if (edhk == true) { MouseAction(0); } break;
                case 49: if (edhk == true) { MouseAction(1); } break;
                case 50: if (edhk == true) { MouseAction(2); } break;
                case 51: if (edhk == true) { MouseAction(3); } break;
                case 52: if (edhk == true) { MouseAction(4); } break;
                case 53: if (edhk == true) { MouseAction(5); } break;
                case 54: if (edhk == true) { MouseAction(6); } break;
                case 55: if (edhk == true) { MouseAction(7); } break;
                case 56: if (edhk == true) { MouseAction(8); } break;
                case 57: if (edhk == true) { MouseAction(9); } break;
                case 96: if (edhk == true) { MouseAction(0); } break;
                case 97: if (edhk == true) { MouseAction(1); } break;
                case 98: if (edhk == true) { MouseAction(2); } break;
                case 99: if (edhk == true) { MouseAction(3); } break;
                case 100: if (edhk == true) { MouseAction(4); } break;
                case 101: if (edhk == true) { MouseAction(5); } break;
                case 102: if (edhk == true) { MouseAction(6); } break;
                case 103: if (edhk == true) { MouseAction(7); } break;
                case 104: if (edhk == true) { MouseAction(8); } break;
                case 105: if (edhk == true) { MouseAction(9); } break;
            }
        }
        //左邊按鈕的程式碼
        private void buttonNew_Click(object sender, EventArgs e) { addNew(); }
        private void buttonDel_Click(object sender, EventArgs e) { delete(); }
        private void buttonup_Click(object sender, EventArgs e) { up(); }
        private void buttondown_Click(object sender, EventArgs e) { down(); }
        private void buttoncopy_Click(object sender, EventArgs e) { copy(); }
        private void buttoncut_Click(object sender, EventArgs e) { dcut(); }
        private void buttonpaste_Click(object sender, EventArgs e) { paste(); }
        private void buttonClear_MouseDown(object sender, MouseEventArgs e)
        {
            timerClear.Enabled = true; times = 0;
            labelMsg.ForeColor = System.Drawing.Color.Red; labelMsg.Text = "按住三秒不放,即可清除此動作中的所有步驟,已經過0秒. 注意!!清除後無法恢復.";
        }//清除按鍵,需按住不放三秒,所以按下後啟動timer計時
        private void buttonClear_MouseUp(object sender, MouseEventArgs e)
        {
            timerClear.Enabled = false;
            labelMsg.ForeColor = System.Drawing.Color.Blue;
            if (times < 3) { labelMsg.Text = "清除按鈕:按住三秒不放,即可清除所有步驟; 按住十秒不放,清除所有步驟及動作(初始化)"; }
            if (times >= 3 && times < 10) { labelMsg.Text = "已清除所有步驟"; }
            if (times == 10) { labelMsg.Text = "按住Record不放,將滑鼠拉到需要的地方再放開,即可記錄座標"; }
            times = 0;
        }//放開後就取消timer
        private void timerClear_Tick(object sender, EventArgs e)
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            times++;
            switch (times)
            {
                case 1: labelMsg.Text = "按住三秒不放,即可清除此動作中的所有步驟,已經過1秒. 注意!!清除後無法恢復."; break;
                case 2: labelMsg.Text = "按住三秒不放,即可清除此動作中的所有步驟,已經過2秒. 注意!!清除後無法恢復."; break;
                case 3:
                    labelMsg.Text = "已經除所有步驟. 按住十秒不放,清除所有步驟及動作,程式初始化. ~~已經過3秒~~ 注意!!清除後無法恢復.";
                    tt[ED] = 0; labeltt.Text = tt[ED].ToString(); ct[ED] = 1; iv[ED] = 1000; textBoxCycle.Text = "1"; checkBox1.Checked = true; textBoxInterval.Text = "1";
                    dgv[ED].Rows.Clear();
                    break;
                case 4: labelMsg.Text = "已經除所有步驟. 按住十秒不放,清除所有步驟及動作,程式初始化. ~~已經過4秒~~ 注意!!清除後無法恢復."; break;
                case 5: labelMsg.Text = "已經除所有步驟. 按住十秒不放,清除所有步驟及動作,程式初始化. ~~已經過5秒~~ 注意!!清除後無法恢復."; break;
                case 6: labelMsg.Text = "已經除所有步驟. 按住十秒不放,清除所有步驟及動作,程式初始化. ~~已經過6秒~~ 注意!!清除後無法恢復."; break;
                case 7: labelMsg.Text = "已經除所有步驟. 按住十秒不放,清除所有步驟及動作,程式初始化. ~~已經過7秒~~ 注意!!清除後無法恢復."; break;
                case 8: labelMsg.Text = "已經除所有步驟. 按住十秒不放,清除所有步驟及動作,程式初始化. ~~已經過8秒~~ 注意!!清除後無法恢復."; break;
                case 9: labelMsg.Text = "已經除所有步驟. 按住十秒不放,清除所有步驟及動作,程式初始化. ~~已經過9秒~~ 注意!!清除後無法恢復."; break;
                case 10:
                    for (int i = 0; i <= 11; i++) { tt[i] = 0; ct[i] = 1; iv[i] = 1000; dgv[i].Rows.Clear(); }
                    labelMsg.Text = "已恢復成原始設定";
                    timerClear.Enabled = false;
                    break;
            }
        }
        private void addNew()
        {
            tt[ED] += 1; labeltt.Text = tt[ED].ToString();
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            dgv[ED].Rows.Add(labeltt.Text, "0", "0", "0", "左鍵點一下", "");
        }
        private void delete()
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            if (tt[ED] > 0)
            {
                for (int i = slr; i < tt[ED] - 1; i++)
                {
                    for (int j = 1; j <= 5; j++)
                    {
                        dgv[ED].Rows[i].Cells[j].Value = dgv[ED].Rows[i + 1].Cells[j].Value;//從選取那一格起,所有資料往前移一列
                    }
                }
                dgv[ED].Rows.RemoveAt(tt[ED] - 1);//刪除最後一列
                tt[ED] -= 1; labeltt.Text = tt[ED].ToString();//總步驟數-1
            }
        }
        private void up()
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            if (tt[ED] > 0 && slr > 0)
            {
                xe = dgv[ED].Rows[slr - 1].Cells[1].Value.ToString(); dgv[ED].Rows[slr - 1].Cells[1].Value = dgv[ED].Rows[slr].Cells[1].Value; dgv[ED].Rows[slr].Cells[1].Value = xe;
                ye = dgv[ED].Rows[slr - 1].Cells[2].Value.ToString(); dgv[ED].Rows[slr - 1].Cells[2].Value = dgv[ED].Rows[slr].Cells[2].Value; dgv[ED].Rows[slr].Cells[2].Value = ye;
                ze = dgv[ED].Rows[slr - 1].Cells[3].Value.ToString(); dgv[ED].Rows[slr - 1].Cells[3].Value = dgv[ED].Rows[slr].Cells[3].Value; dgv[ED].Rows[slr].Cells[3].Value = ze;
                ae = dgv[ED].Rows[slr - 1].Cells[4].Value.ToString(); dgv[ED].Rows[slr - 1].Cells[4].Value = dgv[ED].Rows[slr].Cells[4].Value; dgv[ED].Rows[slr].Cells[4].Value = ae;
                we = dgv[ED].Rows[slr - 1].Cells[5].Value.ToString(); dgv[ED].Rows[slr - 1].Cells[5].Value = dgv[ED].Rows[slr].Cells[5].Value; dgv[ED].Rows[slr].Cells[5].Value = we;
                slr -= 1;
            }
        }
        private void down()
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            if (tt[ED] > 0 && slr < tt[ED] - 1)
            {
                xe = dgv[ED].Rows[slr + 1].Cells[1].Value.ToString(); dgv[ED].Rows[slr + 1].Cells[1].Value = dgv[ED].Rows[slr].Cells[1].Value; dgv[ED].Rows[slr].Cells[1].Value = xe;
                ye = dgv[ED].Rows[slr + 1].Cells[2].Value.ToString(); dgv[ED].Rows[slr + 1].Cells[2].Value = dgv[ED].Rows[slr].Cells[2].Value; dgv[ED].Rows[slr].Cells[2].Value = ye;
                ze = dgv[ED].Rows[slr + 1].Cells[3].Value.ToString(); dgv[ED].Rows[slr + 1].Cells[3].Value = dgv[ED].Rows[slr].Cells[3].Value; dgv[ED].Rows[slr].Cells[3].Value = ze;
                ae = dgv[ED].Rows[slr + 1].Cells[4].Value.ToString(); dgv[ED].Rows[slr + 1].Cells[4].Value = dgv[ED].Rows[slr].Cells[4].Value; dgv[ED].Rows[slr].Cells[4].Value = ae;
                we = dgv[ED].Rows[slr + 1].Cells[5].Value.ToString(); dgv[ED].Rows[slr + 1].Cells[5].Value = dgv[ED].Rows[slr].Cells[5].Value; dgv[ED].Rows[slr].Cells[5].Value = we;
                slr += 1;
            }
        }
        private void copy()
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            if (tt[ED] > 0)
            {
                xe = dgv[ED].Rows[slr].Cells[1].Value.ToString();
                ye = dgv[ED].Rows[slr].Cells[2].Value.ToString();
                ze = dgv[ED].Rows[slr].Cells[3].Value.ToString();
                ae = dgv[ED].Rows[slr].Cells[4].Value.ToString();
                we = dgv[ED].Rows[slr].Cells[5].Value.ToString();
            }
        }
        private void dcut() { if (tt[ED] > 0) { cut = true; cuti = slr; } copy(); }
        private void paste()
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            if (cut == true)
            {
                cut = false;
                for (int i = cuti; i < tt[ED] - 1; i++) { for (int j = 1; j <= 5; j++) { dgv[ED].Rows[i].Cells[j].Value = dgv[ED].Rows[i + 1].Cells[j].Value; } }
                dgv[ED].Rows.RemoveAt(tt[ED] - 1);
                tt[ED] -= 1;
            }
            tt[ED] += 1; labeltt.Text = tt[ED].ToString();
            dgv[ED].Rows.Add(tt[ED].ToString(), "", "", "", "", "");
            for (int i = tt[ED] - 1; i > slr; i--) { for (int j = 1; j <= 5; j++) { dgv[ED].Rows[i].Cells[j].Value = dgv[ED].Rows[i - 1].Cells[j].Value; } }
            dgv[ED].Rows[slr + 1].Cells[1].Value = xe;
            dgv[ED].Rows[slr + 1].Cells[2].Value = ye;
            dgv[ED].Rows[slr + 1].Cells[3].Value = ze;
            dgv[ED].Rows[slr + 1].Cells[4].Value = ae;
            dgv[ED].Rows[slr + 1].Cells[5].Value = we;
        }

        //右方改變滑鼠動作的程式碼
        private void checkBoxHK_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxHK.Checked == true) { edhk = true; } else { edhk = false; }
        }//是否開啟熱鍵編輯
        private void btl1_MouseDown(object sender, MouseEventArgs e)
        {
            MouseAction(1);
            labelMsg.ForeColor = System.Drawing.Color.Red; labelMsg.Text = "按住三秒不放,即可改變所有動作為'左鍵點一下'";
            timerLeft.Enabled = true;
        }
        private void btl1_MouseUp(object sender, MouseEventArgs e)
        {
            timerLeft.Enabled = false;
            if (times < 3) { labelMsg.Text = "按住Record不放,將滑鼠拉到需要的地方再放開,即可記錄座標"; }
            times = 0;
            labelMsg.ForeColor = System.Drawing.Color.Blue;
        }
        private void btl2_Click(object sender, EventArgs e) { MouseAction(2); }
        private void btl3_Click(object sender, EventArgs e) { MouseAction(3); }
        private void btl4_Click(object sender, EventArgs e) { MouseAction(4); }
        private void btr1_MouseDown(object sender, MouseEventArgs e)
        {
            MouseAction(5);
            labelMsg.ForeColor = System.Drawing.Color.Red; labelMsg.Text = "按住三秒不放,即可改變所有動作為'右鍵點一下'";
            timerRight.Enabled = true;
        }
        private void btr1_MouseUp(object sender, MouseEventArgs e)
        {
            timerRight.Enabled = false;
            if (times < 3) { labelMsg.Text = "按住Record不放,將滑鼠拉到需要的地方再放開,即可記錄座標"; }
            times = 0;
            labelMsg.ForeColor = System.Drawing.Color.Blue;
        }
        private void btr2_Click(object sender, EventArgs e) { MouseAction(6); }
        private void btr3_Click(object sender, EventArgs e) { MouseAction(7); }
        private void btr4_Click(object sender, EventArgs e) { MouseAction(8); }
        private void btm1_Click(object sender, EventArgs e) { MouseAction(9); }
        private void btm2_Click(object sender, EventArgs e) { MouseAction(10); }
        private void btm3_Click(object sender, EventArgs e) { MouseAction(11); }
        private void btm4_Click(object sender, EventArgs e) { MouseAction(12); }
        private void btmove_Click(object sender, EventArgs e) { MouseAction(0); }
        private void btnone_Click(object sender, EventArgs e) { MouseAction(100); }
        private void timerLeft_Tick(object sender, EventArgs e)
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            times += 1;
            switch (times)
            {
                case 1: labelMsg.Text = "點住三秒不放,即可將所有動作改成'左鍵點一下'.  已經過1秒."; break;
                case 2: labelMsg.Text = "點住三秒不放,即可將所有動作改成'左鍵點一下'.  已經過2秒."; break;
                case 3: for (Int32 i = 0; i < tt[0]; i++) { dgv[ED].Rows[i].Cells[3].Value = "0"; dgv[ED].Rows[i].Cells[4].Value = "左鍵點一下"; }
                    labelMsg.ForeColor = System.Drawing.Color.Blue; labelMsg.Text = "已完成變更";
                    timerLeft.Enabled = false;
                    break;
            }
        }
        private void timerRight_Tick(object sender, EventArgs e)
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            times += 1;
            switch (times)
            {
                case 1: labelMsg.Text = "點住三秒不放,即可將所有動作改成'左鍵點一下'.  已經過1秒."; break;
                case 2: labelMsg.Text = "點住三秒不放,即可將所有動作改成'左鍵點一下'.  已經過2秒."; break;
                case 3:
                    for (Int32 i = 0; i < tt[0]; i++) { dgv[ED].Rows[i].Cells[3].Value = "5"; dgv[ED].Rows[i].Cells[4].Value = "右鍵點一下"; }
                    labelMsg.ForeColor = System.Drawing.Color.Blue; labelMsg.Text = "已完成變更";
                    timerRight.Enabled = false;
                    break;
            }
        }
        private void MouseAction(Byte ma)
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            if (slr >= 0 && tt[ED] > 0)
            {
                switch (ma)
                {
                    case 0: dgv[ED].Rows[slr].Cells[3].Value = "1"; dgv[ED].Rows[slr].Cells[4].Value = "移動"; break;
                    case 1: dgv[ED].Rows[slr].Cells[3].Value = "0"; dgv[ED].Rows[slr].Cells[4].Value = "左鍵點一下"; break;
                    case 2: dgv[ED].Rows[slr].Cells[3].Value = "2"; dgv[ED].Rows[slr].Cells[4].Value = "左鍵點二下"; break;
                    case 3: dgv[ED].Rows[slr].Cells[3].Value = "3"; dgv[ED].Rows[slr].Cells[4].Value = "按住左鍵"; break;
                    case 4: dgv[ED].Rows[slr].Cells[3].Value = "4"; dgv[ED].Rows[slr].Cells[4].Value = "放開左鍵"; break;
                    case 5: dgv[ED].Rows[slr].Cells[3].Value = "5"; dgv[ED].Rows[slr].Cells[4].Value = "右鍵點一下"; break;
                    case 6: dgv[ED].Rows[slr].Cells[3].Value = "6"; dgv[ED].Rows[slr].Cells[4].Value = "右鍵點二下"; break;
                    case 7: dgv[ED].Rows[slr].Cells[3].Value = "7"; dgv[ED].Rows[slr].Cells[4].Value = "按住右鍵"; break;
                    case 8: dgv[ED].Rows[slr].Cells[3].Value = "8"; dgv[ED].Rows[slr].Cells[4].Value = "放開右鍵"; break;
                    case 9: dgv[ED].Rows[slr].Cells[3].Value = "9"; dgv[ED].Rows[slr].Cells[4].Value = "中鍵點一下"; break;
                    case 10: dgv[ED].Rows[slr].Cells[3].Value = "10"; dgv[ED].Rows[slr].Cells[4].Value = "中鍵點二下"; break;
                    case 11: dgv[ED].Rows[slr].Cells[3].Value = "11"; dgv[ED].Rows[slr].Cells[4].Value = "按住中鍵"; break;
                    case 12: dgv[ED].Rows[slr].Cells[3].Value = "12"; dgv[ED].Rows[slr].Cells[4].Value = "放開中鍵"; break;
                    case 100: dgv[ED].Rows[slr].Cells[3].Value = "100"; dgv[ED].Rows[slr].Cells[4].Value = "無動作"; break;
                }
            }
        }
        //右下角兩個按鈕和小圖示的程式碼
        private void btStopAll_Click(object sender, EventArgs e) { stopAll(); }
        private void buttonhelp_Click(object sender, EventArgs e)
        {
            Form2 fm2 = new Form2(); fm2.Show();
            saveSattings(); savecsv1(); savecsv2(); savecsv3(); savecsv4(); savecsv5(); savecsv6(); savecsv7(); savecsv8(); savecsv9(); savecsv10(); savecsv11(); savecsv12();
        }
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { this.Show(); }



//開始動作的副程式,這裡的邏輯順序是:先啟動start副程式-->再啟動timer-->後啟動ATM,由ATM來負責模擬滑鼠動作
        public void start(Byte st)
        {
            if (bstop == true) { stopAll(); }//如果有選取開始後停止其他動作,就先停止所有動作
            if (bhide == true) { this.Hide(); }//如果選取隱藏視窗,就隱藏視窗
            xcome = Convert.ToInt16(Cursor.Position.X); ycome = Convert.ToInt16(Cursor.Position.Y);//記錄當下座標
            System.Windows.Forms.Timer[] timer = new System.Windows.Forms.Timer[] { timer1, timer2, timer3, timer4, timer5, timer6, timer7, timer8, timer9, timer10, timer11, timer12 };
            timer[st].Interval = iv[st];
            timer[st].Enabled = true;
            doing[st] = true;
        }
        //執行工作的timer群
        private void timer1_Tick(object sender, EventArgs e) { ATM(0); }
        private void timer2_Tick(object sender, EventArgs e) { ATM(1); }
        private void timer3_Tick(object sender, EventArgs e) { ATM(2); }
        private void timer4_Tick(object sender, EventArgs e) { ATM(3); }
        private void timer5_Tick(object sender, EventArgs e) { ATM(4); }
        private void timer6_Tick(object sender, EventArgs e) { ATM(5); }
        private void timer7_Tick(object sender, EventArgs e) { ATM(6); }
        private void timer8_Tick(object sender, EventArgs e) { ATM(7); }
        private void timer9_Tick(object sender, EventArgs e) { ATM(8); }
        private void timer10_Tick(object sender, EventArgs e) { ATM(9); }
        private void timer11_Tick(object sender, EventArgs e) { ATM(10); }
        private void timer12_Tick(object sender, EventArgs e) { ATM(11); }



//執行主要工作,最重要的ATM程式
        public void ATM(Byte atm)
        {
            DataGridView[] dgv = new DataGridView[] { dataGridView1, dataGridView2, dataGridView3, dataGridView4, dataGridView5, dataGridView6, dataGridView7, dataGridView8, dataGridView9, dataGridView10, dataGridView11, dataGridView12 };
            System.Windows.Forms.Timer[] timer = new System.Windows.Forms.Timer[] { timer1, timer2, timer3, timer4, timer5, timer6, timer7, timer8, timer9, timer10, timer11, timer12 };
            try
            {
                x[atm] = Convert.ToInt16(dgv[atm].Rows[step[atm]].Cells[1].Value);
                y[atm] = Convert.ToInt16(dgv[atm].Rows[step[atm]].Cells[2].Value);
                z[atm] = Convert.ToByte(dgv[atm].Rows[step[atm]].Cells[3].Value);
            }
            catch
            {
                x[atm] = 0; y[atm] = 0; z[atm] = 100;
            }
            SetCursorPos(x[atm], y[atm]);
            switch (z[atm])
            {
                case 0://如果z是0的話,那動作就是click一次
                    if (ldown == true) { mouse_event((int)(MouseEventTFlags.LEFTUP), 0, 0, 0, IntPtr.Zero); }//如果處於按住狀態就要先放開
                    mouse_event((int)(MouseEventTFlags.LEFTDOWN), 0, 0, 0, IntPtr.Zero);//在座標的地方按下
                    mouse_event((int)(MouseEventTFlags.LEFTUP), 0, 0, 0, IntPtr.Zero);//按下後要放開,才能完成一次click的動作
                    break;

                case 1://如果z是1的話,就是移動
                    mouse_event((int)(MouseEventTFlags.MOVE), 0, 0, 0, IntPtr.Zero);
                    break;

                case 2://如果z是2的話,就是左鍵點兩下
                    if (ldown == true) { mouse_event((int)(MouseEventTFlags.LEFTUP), 0, 0, 0, IntPtr.Zero); }
                    mouse_event((int)(MouseEventTFlags.LEFTDOWN), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventTFlags.LEFTUP), 0, 0, 0, IntPtr.Zero);
                    Thread.Sleep(50);
                    mouse_event((int)(MouseEventTFlags.LEFTDOWN), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventTFlags.LEFTUP), 0, 0, 0, IntPtr.Zero);
                    break;

                case 3://如果z是3的話,就按住不放
                    if (ldown == false)
                    {
                        mouse_event((int)(MouseEventTFlags.LEFTDOWN), 0, 0, 0, IntPtr.Zero);
                    }//必須是放開狀態下才能夠執行
                    ldown = true;
                    break;

                case 4://如果z是4的話,就是放開
                    if (ldown == true)
                    {
                        mouse_event((int)(MouseEventTFlags.LEFTUP), 0, 0, 0, IntPtr.Zero);
                        ldown = false;
                    }
                    break;

                case 5://如果z是5的話,就click右鍵一次
                    if (rdown == true) { mouse_event((int)(MouseEventTFlags.RIGHTUP), 0, 0, 0, IntPtr.Zero); }
                    mouse_event((int)(MouseEventTFlags.RIGHTDOWN), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventTFlags.RIGHTUP), 0, 0, 0, IntPtr.Zero);
                    break;

                case 6://如果z是6的話,就是右鍵點兩下
                    if (rdown == true) { mouse_event((int)(MouseEventTFlags.RIGHTUP), 0, 0, 0, IntPtr.Zero); }
                    mouse_event((int)(MouseEventTFlags.RIGHTDOWN), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventTFlags.RIGHTUP), 0, 0, 0, IntPtr.Zero);
                    Thread.Sleep(50);
                    mouse_event((int)(MouseEventTFlags.RIGHTDOWN), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventTFlags.RIGHTUP), 0, 0, 0, IntPtr.Zero);
                    break;

                case 7://如果z是7的話,就右鍵按住不放
                    if (rdown == false)
                    {
                        mouse_event((int)(MouseEventTFlags.RIGHTDOWN), 0, 0, 0, IntPtr.Zero);
                        rdown = true;
                    }
                    break;

                case 8://如果z是8的話,就放開右鍵
                    if (rdown == true)
                    {
                        mouse_event((int)(MouseEventTFlags.RIGHTUP), 0, 0, 0, IntPtr.Zero);
                    }
                    break;

                case 9://如果z是9的話,就click中鍵一次
                    if (mdown == true) { mouse_event((int)(MouseEventTFlags.MIDDLEUP), 0, 0, 0, IntPtr.Zero); }
                    mouse_event((int)(MouseEventTFlags.MIDDLEDOWN), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventTFlags.MIDDLEUP), 0, 0, 0, IntPtr.Zero);
                    break;

                case 10://如果z是10的話,就中鍵點兩下
                    if (mdown == true) { mouse_event((int)(MouseEventTFlags.MIDDLEUP), 0, 0, 0, IntPtr.Zero); }
                    mouse_event((int)(MouseEventTFlags.MIDDLEDOWN), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventTFlags.MIDDLEUP), 0, 0, 0, IntPtr.Zero);
                    Thread.Sleep(50);
                    mouse_event((int)(MouseEventTFlags.MIDDLEDOWN), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventTFlags.MIDDLEUP), 0, 0, 0, IntPtr.Zero);
                    break;

                case 11://如果z是11的話,中鍵按住不放
                    if (mdown == false)
                    {
                        mouse_event((int)(MouseEventTFlags.MIDDLEDOWN), 0, 0, 0, IntPtr.Zero);
                        mdown = true;
                    }
                    break;

                case 12://如果z是12的話,就放開中鍵
                    if (mdown == true)
                    {
                        mouse_event((int)(MouseEventTFlags.MIDDLEUP), 0, 0, 0, IntPtr.Zero);
                    }
                    break;

                case 100: break;
            }
            labelMsg.ForeColor = System.Drawing.Color.Red; labelMsg.Text = "滑鼠自動工作中....   正在執行 [" + name[atm] + "] 中的步驟" + Convert.ToString(step[atm] + 1) + ",已經過" + Convert.ToString(ce[atm]) + "次循環";
            step[atm] += 1;
            if (step[atm] == tt[atm]) { ce[atm] += 1; step[atm] = 0; }
            if (ce[atm] == ct[atm]) { ce[atm] = 0; next(na[atm]); stop(atm); }
        }
        //接續下一個動作的副程式
        public void next(Byte na) { if (bnext == true && na < 12) { start(na); } }
        //停止動作的副程式副程式
        public void stopAll() { for (Byte i = 0; i <= 11; i++) { stop(i); } }
        public void stop(Byte sp)
        {
            step[sp] = 0; ce[sp] = 0; doing[sp] = false;//把數值歸0
            if (bshow == true) { this.Show(); }//如果停止後恢復視窗的選項有打勾,就恢復視窗
            if (bcome == true) { SetCursorPos(xcome, ycome); mouse_event((int)(MouseEventTFlags.MOVE), 0, 0, 0, IntPtr.Zero); }//如果有選擇停止後滑鼠恢復原位的話,就把滑鼠恢復原位
            labelMsg.ForeColor = System.Drawing.Color.Navy; labelMsg.Text = "按住Record不放,將滑鼠拉到想要的位置,即可紀錄座標";
            System.Windows.Forms.Timer[] timer = new System.Windows.Forms.Timer[] { timer1, timer2, timer3, timer4, timer5, timer6, timer7, timer8, timer9, timer10, timer11, timer12 };
            timer[sp].Enabled = false;
        }




        //關閉視窗後儲存動作
        public void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            saveSattings(); savecsv1(); savecsv2(); savecsv3(); savecsv4(); savecsv5(); savecsv6(); savecsv7(); savecsv8(); savecsv9(); savecsv10(); savecsv11(); savecsv12();
        }
        //儲存設定的副程式
        public void saveSattings()
        {
            Properties.Settings.Default.ED = ED; Properties.Settings.Default.btop = btop;
            Properties.Settings.Default.bhide = bhide; Properties.Settings.Default.bshow = bshow; Properties.Settings.Default.opacity = opacity;
            Properties.Settings.Default.bcome = bcome; Properties.Settings.Default.bstop = bstop; Properties.Settings.Default.bnext = bnext;
            Properties.Settings.Default.name0 = name[0]; Properties.Settings.Default.name1 = name[1]; Properties.Settings.Default.name2 = name[2]; Properties.Settings.Default.name3 = name[3];
            Properties.Settings.Default.name4 = name[4]; Properties.Settings.Default.name5 = name[5]; Properties.Settings.Default.name6 = name[6]; Properties.Settings.Default.name7 = name[7];
            Properties.Settings.Default.name8 = name[8]; Properties.Settings.Default.name9 = name[9]; Properties.Settings.Default.name10 = name[10]; Properties.Settings.Default.name11 = name[11];
            Properties.Settings.Default.tt0 = tt[0]; Properties.Settings.Default.tt1 = tt[1]; Properties.Settings.Default.tt2 = tt[2]; Properties.Settings.Default.tt3 = tt[3];
            Properties.Settings.Default.tt4 = tt[4]; Properties.Settings.Default.tt5 = tt[5]; Properties.Settings.Default.tt6 = tt[6]; Properties.Settings.Default.tt7 = tt[7];
            Properties.Settings.Default.tt8 = tt[8]; Properties.Settings.Default.tt9 = tt[9]; Properties.Settings.Default.tt10 = tt[10]; Properties.Settings.Default.tt11 = tt[11];
            Properties.Settings.Default.ct0 = ct[0]; Properties.Settings.Default.ct1 = ct[1]; Properties.Settings.Default.ct2 = ct[2]; Properties.Settings.Default.ct3 = ct[3];
            Properties.Settings.Default.ct4 = ct[4]; Properties.Settings.Default.ct5 = ct[5]; Properties.Settings.Default.ct6 = ct[6]; Properties.Settings.Default.ct7 = ct[7];
            Properties.Settings.Default.ct8 = ct[8]; Properties.Settings.Default.ct9 = ct[9]; Properties.Settings.Default.ct10 = ct[10]; Properties.Settings.Default.ct11 = ct[11];
            Properties.Settings.Default.iv0 = iv[0]; Properties.Settings.Default.iv1 = iv[1]; Properties.Settings.Default.iv2 = iv[2]; Properties.Settings.Default.iv3 = iv[3];
            Properties.Settings.Default.iv4 = iv[4]; Properties.Settings.Default.iv5 = iv[5]; Properties.Settings.Default.iv6 = iv[6]; Properties.Settings.Default.iv7 = iv[7];
            Properties.Settings.Default.iv8 = iv[8]; Properties.Settings.Default.iv9 = iv[9]; Properties.Settings.Default.iv10 = iv[10]; Properties.Settings.Default.iv11 = iv[11];
            Properties.Settings.Default.hk0 = hk[0]; Properties.Settings.Default.hk1 = hk[1]; Properties.Settings.Default.hk2 = hk[2]; Properties.Settings.Default.hk3 = hk[3];
            Properties.Settings.Default.hk4 = hk[4]; Properties.Settings.Default.hk5 = hk[5]; Properties.Settings.Default.hk6 = hk[6]; Properties.Settings.Default.hk7 = hk[7];
            Properties.Settings.Default.hk8 = hk[8]; Properties.Settings.Default.hk9 = hk[9]; Properties.Settings.Default.hk10 = hk[10]; Properties.Settings.Default.hk11 = hk[11];
            Properties.Settings.Default.na0 = na[0]; Properties.Settings.Default.na1 = na[1]; Properties.Settings.Default.na2 = na[2]; Properties.Settings.Default.na3 = na[3];
            Properties.Settings.Default.na4 = na[4]; Properties.Settings.Default.na5 = na[5]; Properties.Settings.Default.na6 = na[6]; Properties.Settings.Default.na7 = na[7];
            Properties.Settings.Default.na8 = na[8]; Properties.Settings.Default.na9 = na[9]; Properties.Settings.Default.na10 = na[10]; Properties.Settings.Default.na11 = na[11];
            Properties.Settings.Default.Save();
        }
        //儲存成csv檔的副程式
        public void savecsv1()
        {
            string strValue = string.Empty;
            //CSV 匯出的標題 要先塞一樣的格式字串 充當標題
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView1[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView1[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView1[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView1[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            //存成檔案
            string strFile = "ATM-Data1.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv2()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView2.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView2[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView2[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView2[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView2[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data2.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv3()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView3.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView3.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView3[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView3[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView3[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView3[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data3.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv4()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView4.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView4.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView4[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView4[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView4[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView4[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data4.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv5()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView5.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView5.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView5[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView5[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView5[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView5[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data5.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv6()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView6.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView6.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView6[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView6[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView6[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView6[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data6.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv7()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView7.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView7.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView7[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView7[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView7[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView7[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data7.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv8()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView8.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView8.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView8[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView8[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView8[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView8[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data8.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv9()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView9.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView9.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView9[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView9[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView9[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView9[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data9.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv10()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView10.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView10.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView10[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView10[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView10[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView10[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data10.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv11()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView11.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView11.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView11[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView11[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView11[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView11[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data11.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        public void savecsv12()
        {
            string strValue = string.Empty;
            strValue = "步驟,X軸,Y軸,Z,動作,備註";
            for (int i = 0; i < dataGridView12.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView12.Rows[i].Cells.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dataGridView12[j, i].Value.ToString()))
                    {
                        if (j > 0)
                            strValue = strValue + "," + dataGridView12[j, i].Value.ToString();
                        else
                        {
                            if (string.IsNullOrEmpty(strValue))
                                strValue = dataGridView12[j, i].Value.ToString();
                            else
                                strValue = strValue + Environment.NewLine + dataGridView12[j, i].Value.ToString();
                        }
                    }
                    else
                    {
                        if (j > 0)
                            strValue = strValue + ",";
                        else
                            strValue = strValue + Environment.NewLine;
                    }
                }
            }
            string strFile = "ATM-Data12.csv";
            if (!string.IsNullOrEmpty(strValue))
            {
                File.WriteAllText(strFile, strValue, Encoding.UTF8);
            }
        }
        //讀取csv檔的副程式
        public static List<string> ReadCsvToList(string FileName)
        {
            FileInfo fi = new FileInfo(FileName);
            if (fi.Exists)
            {
                List<string> result = new List<string>();
                using (StreamReader sr = new StreamReader(FileName))
                {
                    while (sr.Peek() >= 0)
                    {
                        result.Add(sr.ReadLine());
                    }
                }
                return result;
            }
            else return null;
        }
        public static DataTable ReadCsvToDataTable(string FileName, bool HasColumnName)
        {
            List<string> Input = ReadCsvToList(FileName);
            if (Input != null)
            {
                string[] sep = new string[] { "," };
                DataTable dt = new DataTable();
                int StartCount = (HasColumnName == true) ? 1 : 0;
                string[] ColumnName = Input[0].Split(sep, StringSplitOptions.None);
                for (int i = 0; i < ColumnName.Length; i++)
                    dt.Columns.Add((HasColumnName == true) ? ColumnName[i] : "C" + i.ToString(), typeof(string));
                for (int j = StartCount; j < Input.Count; j++)
                {
                    string[] valuetemp = Input[j].Split(sep, StringSplitOptions.None);
                    dt.Rows.Add(valuetemp);
                }
                return dt;
            }
            else return null;
        }
        public void setdgv()
        {
            setdgv1(); setdgv2(); setdgv3(); setdgv4(); setdgv5(); setdgv6(); setdgv7(); setdgv8(); setdgv9(); setdgv10(); setdgv11(); setdgv12();
        }
        public void setdgv1()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data1.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView1.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView1.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv2()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data2.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView2.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView2.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv3()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data3.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView3.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView3.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv4()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data4.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView4.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView4.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv5()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data5.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView5.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView5.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv6()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data6.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView6.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView6.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv7()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data7.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView7.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView7.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv8()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data8.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView8.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView8.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv9()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data9.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView9.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView9.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv10()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data10.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView10.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView10.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv11()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data11.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView11.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView11.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
        public void setdgv12()
        {
            dataGridView0.DataSource = ReadCsvToDataTable("ATM-Data12.csv", true);
            for (int i = 0; i < dataGridView0.RowCount; i++)
            {
                dataGridView12.Rows.Add();
                for (int j = 0; j < dataGridView0.ColumnCount; j++)
                {
                    dataGridView12.Rows[i].Cells[j].Value = dataGridView0.Rows[i].Cells[j].Value;
                }
            }
            dataGridView0.Columns.Clear();
        }
    }
}

C# 自動滑鼠ATM_Lite ver0.97的程式碼

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq...