can someone explain to me how to put the current time into a tekstbox...
i'm totaly new with this language and need to finish a program before school starts again.

it should be like this:

if i push button "BtnStart" then current time should be inputted in "textbox1"
if i push button "BtnStop" then current time should be inputten in "textbox2"
and time difference shouold be shown in "textbox3"

can someone help me with this?
i used to program this in delphi what i managed to work but never done anything with C# 2005

Hi,
To get the Current Time u can use DateTime.Now property. It returns CurrentTime. So in btnStart u can use like this

private void btnStart_Click(object sender, EventArgs e)
    {
        //Display the current Time
        textBox1.Text = DateTime.Now.ToString("hh:mm:ss tt");
        textBox2.Text = DateTime.Now.ToString("hh:mm:ss tt");
        //Start the Timer
        tmrTime.Enabled = true;
    }

Be sure to have three TextBoxes (textBox1, textBox2, textBox3)

DateTime.Now.ToString (String s)

Provides you to format the Time
like hour : min : secs

Draw a Timer controls and Make Enable property to false, Interval Property to 1000 and Add TimerTick handler

private void tmrTime_Tick(object sender, EventArgs e)
    {
        //Periodically update the values
        textBox2.Text = DateTime.Now.ToString("hh:mm:ss tt");
    }

This again change the time to DateTime variables.

At last Display the different in TextBox3
and Stop the timer

private void btnStop_Click(object sender, EventArgs e)
    {
        DateTime dateTime1, dateTime2;
        // Change Time String to DateTime object
        dateTime1 = DateTime.Parse(textBox1.Text);
        dateTime2 = DateTime.Parse(textBox2.Text);
        //Find the Difference
        TimeSpan timeDiff = dateTime2.Subtract(dateTime1);
        //Display the Difference
        textBox3.Text = timeDiff.ToString();
        //Stop the Timer
        tmrTime.Enabled = false;
    }

Why did you do the guys homework for him? A simple textBox2.Text = dateTime.ToString("hh:mm:ss tt"); would have sufficed.

All you do by doing someone's homework for them is encourage more of those kinds of questions without them putting any effort at all to at least take a stab at it.

tanx for info. this is just a litle piece of the homework i have to do :P
is alot more.. and will have to find out alot myself but i start learning this language now and it's getting more and more easy... although delphi is alot more easy ^^

i have textbox,listbox and a button.i want when i enter a date in textbox.the specified data in listbox is displayed which is from a log file.Now.I want only when i select a current time,only the output data is displayed,not all teh data which displayed before
here is the code for the button to display the data.

if (BioBridgeSDK.ReadGeneralLog(ref log) == 0)
            {
                while (BioBridgeSDK.GetGeneralLog(ref EnrollNo, ref yr, ref mth, ref day_Renamed, ref hr, ref min, ref sec, ref ver, ref io, ref work) == 0)
                //read the information logs from the memory buffer
{
if (io == 0)
                        {

                           listBox2.Items.Add(("No: " + Convert.ToString(EnrollNo) + " Date:" + Convert.ToString(day_Renamed) + "/" + Convert.ToString(mth) + "/" + Convert.ToString(yr) + " Time: " + Convert.ToString(hr) + ":" + Convert.ToString(min) + ":" + Convert.ToString(sec) + " I/O: Check In"));
                            //listBox2.Items.Add(textBox2.TextChanged);
                        }
                        else
                            listBox2.Items.Add(("No: " + Convert.ToString(EnrollNo) + " Date:" + Convert.ToString(day_Renamed) + "/" + Convert.ToString(mth) + "/" + Convert.ToString(yr) + " Time: " + Convert.ToString(hr) + ":" + Convert.ToString(min) + ":" + Convert.ToString(sec) + " I/O: Check Out"));
                       // if (textBox2.Text = DateTime())
{


}

i dont know what to write in order to make the selected date to appear the specified log.Also,do i need textBox2_TextChanged
to be fired each time i change teh date in the textbox or not?.

Thanks,

How to set value from server side code to an asp.net TextBox with TextMode=“Time”?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.