| | |
set current time in textbox
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 18
Reputation:
Solved Threads: 0
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
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
Be sure to have three TextBoxes (textBox1, textBox2, textBox3)
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
This again change the time to DateTime variables.
At last Display the different in TextBox3
and Stop the timer
To get the Current Time u can use DateTime.Now property. It returns CurrentTime. So in btnStart u can use like this
c# Syntax (Toggle Plain Text)
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)
C# Syntax (Toggle Plain Text)
DateTime.Now.ToString (String s)
like hour : min : secs
Draw a Timer controls and Make Enable property to false, Interval Property to 1000 and Add TimerTick handler
C# Syntax (Toggle Plain Text)
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
C# Syntax (Toggle Plain Text)
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; }
KSG
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
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.
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,
here is the code for the button to display the data.
C# Syntax (Toggle Plain Text)
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) <span class="ad_notxt"><code class="inlinecode"> //read the information logs from the memory buffer</code></span> { 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()) { }
to be fired each time i change teh date in the textbox or not?.
Thanks,
![]() |
Similar Threads
- Object reference not set to an instance of an object (ASP.NET)
- AutoComplete Feature (ASP.NET)
- Printing to a Textbox (C#)
- Flex Grid error "Invalid procedure call or argument" (Visual Basic 4 / 5 / 6)
- Pop3 Mail Watcher (Part 1) (Visual Basic 4 / 5 / 6)
Other Threads in the C# Forum
- Previous Thread: reading a certain word from a text file
- Next Thread: How to Encrypt and Decrypt using C# in window base programme
| Thread Tools | Search this Thread |
.net access algorithm alignment app array barchart bitmap box broadcast c# c#gridviewcolumn cast check checkbox client combobox communication concurrency control conversion csharp custom database datagrid datagridview dataset datatable datetime degrees development draganddrop drawing elevated encryption enum excel file focus form format forms function gdi+ hospitalmanagementsystem image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml






