發現這款遊戲均採用時間緒來處理事件
---
--
我也剛好要練習 C# , 也就寫了一個簡單的
--
程式碼:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
int count;
double ptr;
public Form1()
{
InitializeComponent();
//timer1.Interval = 100;
//timer1.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
count++;
label1.Text = count.ToString();
if (count > Convert.ToInt32(ptr))
{
timer1.Enabled = false;
}
else
{
progressBar1.Value = count;
}
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Interval = Convert.ToInt16 (textBox1.Text);
//
DateTime h1 = DateTime.Now;
DateTime h2 = DateTime.Now;
h1 =h1.AddHours(Convert.ToDouble(textBox2.Text.Substring(0, 2)));
h1=h1.AddMinutes(Convert.ToDouble (textBox2.Text.Substring(3, 2)));
h1=h1.AddSeconds (Convert.ToDouble(textBox2.Text.Substring(6, 2)));
TimeSpan h3 = h1.Subtract(h2);
//ptr = h3.TotalMilliseconds ;
ptr = h3.TotalSeconds;
progressBar1.Maximum = Convert.ToInt32(ptr);
//
timer1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
}
}
沒有留言:
張貼留言