我想在我的date.txt文件中添加带有文本的新行,但不是将其添加到现有的date.txt中,而是应用程序正在创建新的date.txt文件.
TextWriter tw = new StreamWriter("date.txt");
// write a line of text to the file
tw.WriteLine(DateTime.Now);
// close the stream
tw.Close();
Run Code Online (Sandbox Code Playgroud)
我想打开txt文件,添加一些文本,关闭它,然后点击一下后:打开date.txt,添加文本,然后再次关闭它.
所以我可以得到:
按下按钮:打开txt - >添加当前时间,然后关闭它.按下另一个按钮,txt打开 - >在同一行中添加文本"OK"或"NOT OK",然后再次关闭它.
所以我的txt文件看起来像这样:
2011-11-24 10:00:00 OK
2011-11-25 11:00:00 NOT OK
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?谢谢!
我需要在表单加载10秒后显示一条消息.我使用以下代码
private void Form1_Load(object sender, EventArgs e)
{
SetTimeInterval();
}
System.Windows.Forms.Timer MyTimer = new System.Windows.Forms.Timer();
public void SetTimeInterval()
{
MyTimer.Interval = ( 10 * 1000);
MyTimer.Tick += new EventHandler(TimerEventProcessor);
MyTimer.Start();
}
void TimerEventProcessor(Object myObject,EventArgs myEventArgs)
{
MessageBox.Show("TIME UP");
MyTimer.Stop();
MyTimer.Enabled = false;
}
Run Code Online (Sandbox Code Playgroud)
使用MyTimer.Stop()和MyTimer.Enabled = false尝试,但messagebox每10秒显示一次.如何在第一次实例后停止它?