I am creating a timer Project
You will need:
- timer
- windows form
- 3 Buttons (btnstart,btnclear, btnOption)
- Link Label
- Label
When creating a windows form applciation you must name it
"timer".This first part of the code is for
Form1.csCODE
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace timer
{
public partial class Form1 : Form
{
private int t = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.timer1.Interval = 1;
}
public string GetAllTime(int time)
{
string hh, mm, ss, fff;
string j = "Please take a short break away from your Computer Screen to prevent adverse effect from prolonged use.";
int f = time % 100; // mSec
int s = time / 100; // Transfer to Sec
int m = s / 60; // Min
int h = m / 60; // Hour
s = s % 60; // Sec
if (f == 20&& s==1 && m==0&&h==0)
{
this.btnStar.Text = "Start";
this.timer1.Enabled = false;
MessageBox.Show(j);
}
//Format of mSec 00
if (f < 10)
{
fff = "0" + f.ToString();
}
else
{
fff = f.ToString();
}
//Format of Sec 00
if (s < 10)
{
ss = "0" + s.ToString();
}
else
{
ss = s.ToString();
}
//Format of Min 00
if (m < 10)
{
mm = "0" + m.ToString();
}
else
{
mm = m.ToString();
}
//Format of Hour 00
if (h < 10)
{
hh = "0" + h.ToString();
}
else
{
hh = h.ToString();
}
//return hh:mm:ss.ff
return hh + ":" + mm + ":" + ss + "." + fff;
}
private void btnStar_Click(object sender, EventArgs e)
{
if (timer1.Enabled == false)
{
this.btnStar.Text = "Pause";
this.timer1.Enabled = true;
}
else
{
this.btnStar.Text = "Start";
this.timer1.Enabled = false;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
t = 0;
//If running, stop it first, otherwise clear to zero
if (this.timer1.Enabled == true)
{
this.btnStar_Click(sender, e);
label1.Text = GetAllTime(t);
}
else
{
label1.Text = GetAllTime(t);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
t = t + 1;//mSec in total
this.label1.Text = GetAllTime(t);
}
private void btnOption_Click(object sender, EventArgs e)
{
Settings myNewForm = new Settings();
myNewForm.Show();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(
@"C:\Program Files\Internet Explorer\iexplore.exe",
"http://www.hotmail.com/");
}
}
}
In the second part of the code goes in
program.csCODE
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace timer
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
public class FileClass
{
public static void Main()
{
WriteToFile();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MessageBox.Show("Timer Project!\n(Version 1)");
Application.Run(new Form1());
}
static void WriteToFile()
{
StreamWriter SW;
SW = File.CreateText("c:\\MyTextFile.txt");
SW.WriteLine("It Work's!!!!");
SW.WriteLine("Problem Solved");
SW.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
SW.WriteLine("Current date and time: {0}", System.DateTime.Now);
SW.Close();
}
}
}
}
Please see attached image
[/URL]

[/img]
I need to this to the timer which is the main form
My main objective is create input for users to put numbers only and in the long textbox "enters a message".
Can someone help me plz?
Thanks
This post has been edited by MMD1X: 13 Oct, 2008 - 03:21 AM