یک TextBox بزار روی فرم مثلا اسمش هست TextBox1 با یک Button اسمش Button1
و یکی label برای ساعت label1
حالا کد زیر رو بنویس
public partial class Form1 : Form
{
Timer timer = new Timer();
DateTime time = new DateTime();
public Form1()
{
InitializeComponent();
time = DateTime.Now;
label1.Text = "";
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = 1000;
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
time = time.AddSeconds(1);
label1.Text = time.ToString("HH:mm:ss tt");
}
private void button1_Click(object sender, EventArgs e)
{
if( ! DateTime.TryParse(textBox1.Text, out time))
time = DateTime.Now;
}
}
الان کافیه که توی text box زمان جدید رو بزنید و روی button کلیک کنید .
برای تاریخ هم میتونین از روش مشابه استفاده کنین .