Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,255 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,199 people online right now. Registration is fast and FREE... Join Now!




I Need Some Help...timer project

 
Reply to this topicStart new topic

I Need Some Help...timer project, How to a Textbox

MMD1X
13 Oct, 2008 - 02:00 AM
Post #1

New D.I.C Head
*

Joined: 8 Oct, 2008
Posts: 3

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.cs

CODE

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.cs

CODE

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]IPB Image[/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
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: I Need Some Help...timer Project
13 Oct, 2008 - 04:47 AM
Post #2

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 353



Thanked: 19 times
Dream Kudos: 25
My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:26AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month