Click here to Skip to main content
15,887,304 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a small project about manage time use on computer.
Form1:

C#
public partial class Form1 : Form
{
    private Timer t = new Timer();
    public static int counter = 60;
    public Form1()
    {
        InitializeComponent();
        t.Tick += new EventHandler(Timer_Tick);
        t.Interval = 1000;
        t.Enabled = true;                       
        t.Start();
        Form2 TheForm2 = new Form2();
        TheForm2.ShowDialog();
    }

    void Timer_Tick(object sender, EventArgs e)
    {
        counter -= 1;
        if (counter==20)
        {
            MessageBox.Show("Time remaining "+counter.ToString());
        }

    }
}


And Form2:

C#
public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        int userVal = int.Parse(textBox2.Text);
        Form1.counter += userVal;
    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
        textBox1.Text = Form1.counter.ToString();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }
}

Final program:

C#
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Form1 TheForm = new Form1();
        Application.Run();
    }
}


What I have tried:

I try to make this application run on Windows start up and the Form1 is hide. But I wanna make form2 invisible also. And it just show when user excute the application. How can I solve it? I just put this exe to folder start up to make it run on start.(I'll try to make it with Registry)
Posted
Updated 15-Oct-18 8:03am

1 solution

I think what you really want to do is create a Windows service to do the time keeping, most likely when a user logs in/out. Then you can write a separate app that can be used to visualize the usage info.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900