프로그램을 분단위로 반복 할수 있게 만들기
1.디자인
2.소스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
using System; using System.Drawing; using System.Windows.Forms; using System.Threading; namespace WinRuleCache { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //Start Stop 버튼 init btnStart.Enabled = true; btnStop.Enabled = false; // Timer init timer1.Enabled = false; // cmbTime init cmbTime.SelectedIndex = 1; //timer2 int timer2.Enabled = false; timer2.Interval = 2000; } private void Form1_Resize(object sender, EventArgs e) { groupBox1.Size = new Size(this.Width - 40, (this.Height - 75) / 2); groupBox2.Top = groupBox1.Height + 20; groupBox2.Size = new Size(this.Width - 40, this.Height - groupBox1.Height - 55); //log resize txtLog.Size = new Size(groupBox2.Width - 40, groupBox2.Height - 60); } private void btnStart_Click(object sender, EventArgs e) { int sTime = 1000000; switch (cmbTime.SelectedIndex) { case 0: sTime = 1 * 60 * 1000; //1분 break; case 1: sTime = 5 * 60 * 1000; //5분 break; case 2: sTime = 10 * 60 * 1000; //10분 break; default: sTime = 20 * 60 * 1000; //20분 break; } timer2.Interval = 2000; timer2.Enabled = true; timer2.Start(); timer1.Interval = sTime; timer1.Enabled = true; timer1.Start(); btnStart.Enabled = false; btnStop.Enabled = true; LogShow("프로그램을 시작 합니다."); Repeat(); } private void btnStop_Click(object sender, EventArgs e) { //stop 버튼을 누르면 btnStart.Enabled = true; btnStop.Enabled = false; LogShow("중지 되었습니다."); timer2.Stop(); timer2.Enabled = false; timer1.Stop(); timer1.Enabled = false; toolStripProgressBar1.Value = 0; } private void timer1_Tick(object sender, EventArgs e) { Repeat(); } //로그 뿌려주기 함수 private void LogShow(string LogDate) { if (txtLog.Text.Length > 1000) txtLog.Text = DateTime.Now.ToString() + " " + LogDate; else txtLog.Text = txtLog.Text + "\r\n" + DateTime.Now.ToString() + " " + LogDate; txtLog.SelectionStart = txtLog.Text.Length; txtLog.ScrollToCaret(); txtLog.Refresh(); } private void timer2_Tick(object sender, EventArgs e) { toolStripProgressBar1.Value = 0; Thread.Sleep(1000); toolStripProgressBar1.Value = 100; } private void cmbTime_KeyUp(object sender, KeyEventArgs e) { e.Handled = true; } private void Repeat() { LogShow(" 계속 반복 합니다.."); } } } |