public MdiAdminMain()
{
InitializeComponent();
} string name = ""; public MdiAdminMain(string name)
: this()
{
this.name = name;
} private void MdiAdminMain_Load(object sender, EventArgs e)
{
this.getTime();
tmrTimeChanged_Tick(sender, e);//此处调用计时器事件函数,相当于一次手动计时
} private void mmsExit_Click(object sender, EventArgs e)
{
Application.Exit();
} private void MdiAdminMain_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("是否退出应用程序", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
////////////////////////////////////为什么会执行2次?
if (dr == DialogResult.Yes)
{
Application.Exit();
}
else if (dr == DialogResult.No)
{
e.Cancel = true;
}
} /// <summary>
/// 生成日期时间字符串
/// </summary>
private void getTime()
{
DateTime currentTime = DateTime.Now;
string date = currentTime.ToString("d");//得到日期
string time = currentTime.ToLongTimeString();//得到时间
string[] day = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
string d = day[Convert.ToInt16(currentTime.DayOfWeek)];//得到时间
int h = currentTime.Hour;
string s = "";
if (h >= 1 && h <= 4)
{
s = "凌晨";
}
else if (h >= 5 && h <= 7)
{
s = "早上";
}
else if (h >= 8 && h <= 10)
{
s = "上午";
}
else if (h >= 11 && h <= 12)
{
s = "中午";
}
else if (h >= 13 && h <= 16)
{
s = "下午";
}
else if (h >= 17 && h <= 18)
{
s = "傍晚";
}
else if (h >= 19 && h <= 22)
{
s = "晚上";
}
else if (h == 23 || h == 0)
{
s = "子夜";
} this.lblTime.Text = name + ",你好!现在是 " + date + "," + s + " " + time;
} /// <summary>
/// Timer控件
/// </summary>
private void tmrTimeChanged_Tick(object sender, EventArgs e)
{
tmrTimeChanged.Enabled = true;
tmrTimeChanged.Interval = 1000;
this.getTime();//备忘
}DialogResult dr = MessageBox.Show("是否退出应用程序", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
////////////////////////////////////为什么会执行2次? 这里这个窗口是可以关闭,但是这个对话框一直弹出2次,第二次按是窗口关闭,进程退出,按否窗口关闭进程还在,而且我有TIMER控件调试的时候一直在那里绕,怎么回事呢?
有兄弟回答说Application.Exit();
会再次触发.. FormClosing 改成这样
DialogResult dr = MessageBox.Show("是否退出应用程序", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
////////////////////////////////////为什么会执行2次? if (dr == DialogResult.Yes)
{
e.Cancel = false;
}
else if (dr == DialogResult.No)
{
e.Cancel = true;
} 但是这样进程不会退出,有什么好办法吗?
{
InitializeComponent();
} string name = ""; public MdiAdminMain(string name)
: this()
{
this.name = name;
} private void MdiAdminMain_Load(object sender, EventArgs e)
{
this.getTime();
tmrTimeChanged_Tick(sender, e);//此处调用计时器事件函数,相当于一次手动计时
} private void mmsExit_Click(object sender, EventArgs e)
{
Application.Exit();
} private void MdiAdminMain_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("是否退出应用程序", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
////////////////////////////////////为什么会执行2次?
if (dr == DialogResult.Yes)
{
Application.Exit();
}
else if (dr == DialogResult.No)
{
e.Cancel = true;
}
} /// <summary>
/// 生成日期时间字符串
/// </summary>
private void getTime()
{
DateTime currentTime = DateTime.Now;
string date = currentTime.ToString("d");//得到日期
string time = currentTime.ToLongTimeString();//得到时间
string[] day = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
string d = day[Convert.ToInt16(currentTime.DayOfWeek)];//得到时间
int h = currentTime.Hour;
string s = "";
if (h >= 1 && h <= 4)
{
s = "凌晨";
}
else if (h >= 5 && h <= 7)
{
s = "早上";
}
else if (h >= 8 && h <= 10)
{
s = "上午";
}
else if (h >= 11 && h <= 12)
{
s = "中午";
}
else if (h >= 13 && h <= 16)
{
s = "下午";
}
else if (h >= 17 && h <= 18)
{
s = "傍晚";
}
else if (h >= 19 && h <= 22)
{
s = "晚上";
}
else if (h == 23 || h == 0)
{
s = "子夜";
} this.lblTime.Text = name + ",你好!现在是 " + date + "," + s + " " + time;
} /// <summary>
/// Timer控件
/// </summary>
private void tmrTimeChanged_Tick(object sender, EventArgs e)
{
tmrTimeChanged.Enabled = true;
tmrTimeChanged.Interval = 1000;
this.getTime();//备忘
}DialogResult dr = MessageBox.Show("是否退出应用程序", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
////////////////////////////////////为什么会执行2次? 这里这个窗口是可以关闭,但是这个对话框一直弹出2次,第二次按是窗口关闭,进程退出,按否窗口关闭进程还在,而且我有TIMER控件调试的时候一直在那里绕,怎么回事呢?
有兄弟回答说Application.Exit();
会再次触发.. FormClosing 改成这样
DialogResult dr = MessageBox.Show("是否退出应用程序", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
////////////////////////////////////为什么会执行2次? if (dr == DialogResult.Yes)
{
e.Cancel = false;
}
else if (dr == DialogResult.No)
{
e.Cancel = true;
} 但是这样进程不会退出,有什么好办法吗?
private void MdiAdminMain_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("是否退出应用程序", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (dr == DialogResult.Yes)
e.Cancel = false;
else
e.Cancel = true;
}
这样就可以,进程会正常退出~
{
DialogResult dr = MessageBox.Show("是否退出应用程序", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
////////////////////////////////////为什么会执行2次?
if (dr == DialogResult.Yes)
{
e.Cancel=false;
Application.Exit();
}
else if (dr == DialogResult.No)
{
e.Cancel = true;
}
}