timer控件问题 我有2个winfrom窗体。A窗体我放了一个timer,然后我想在B窗体关闭时候让A窗体的timer开启。有什么办法么?求代码,然后听说如果一个页面里放多个timer的话时间会有冲突?求解决方法。我打算放3个,但是多久时间运行一次不一样,求解决方法。急。在线等 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个需求,貌似很简单哈...每个窗体放一个 timer, B关闭的时候给A传递个标志,然后再 A启动就可以了...还有,如果你想直接在B的页面操作A,把 A的timer的 modified属性设置为public不就行 了... 建议lz不要用timer控件,那东西效率差、占用空间大、容易有冲突……lz可以用多线程技术实现,别说放3个后台线程了,就算是10个都没问题,只要电脑资源足够就行。还有要注意下线程间的数据同步问题,尽量不要有多个线程调用一个全局变量,有的话一定要加锁。 A注册B窗口的事件,B窗体关闭时,执行事件让A窗体中的timer开始运行. 主要我是新手。多线程不会。然后又非得实现这种所以就只能timer了。现在我现在个毛病。因为写的A窗体把是个登陆窗体。我点击登陆后就在右下角挂个图标,但是现在我现在F5运行的时候右下角就出先2图标。是不是和我A页面用2个Timer有关系呀。 现在我现在个毛病。因为写的A窗体把是个登陆窗体。我点击登陆后就在右下角挂个图标,但是现在我现在F5运行的时候右下角就出先2图标。是不是和我A页面用2个Timer有关系呀。 现在我现在个毛病。因为写的A窗体把是个登陆窗体。我点击登陆后就在右下角挂个图标,但是现在我现在F5运行的时候右下角就出先2图标。是不是和我A页面用2个Timer有关系呀。 不知道你在说什么,你timer中的事件写的什么?如果你在编译器调试模式下,还能按F5吗?程序怎么运行的,在哪里按的F5... using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using login_sample;using Aladdin.HASP;using System.Runtime.InteropServices;using System.Xml.XPath;using System.Xml;using System.IO;using System.Collections;using System.Diagnostics;using Model;using BLL;namespace WindowsApp{ public partial class Login : Form { private Point mPoint = new Point(); static string ob = ""; static string name = ""; static string pwd = ""; static int JS = 0; public Login() { InitializeComponent(); //txtName.Enter += new EventHandler(txtName_Enter); //获得焦点事件 //txtName.Leave += new EventHandler(txtName_Leave); //失去焦点事件。 //txtPwd.Enter += new EventHandler(txtPwd_Enter); //获得焦点事件 //txtPwd.Leave += new EventHandler(txtPwd_Leave); //失去焦点事件。 } private void Form1_Load(object sender, EventArgs e) { InitializeComponent(); ob = ProgramHasp.getHaspKey();//电子狗状态 if (ob == "没有该OKEY的用户信息,请联系管理员") { lblXsCg.Text = "请插入OKEY,并点击登陆按钮"; btnDengKEY.Visible = false; pbxJG.Visible = true; } else { lblXsCg.Text = "您的用户信息正确,请点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = true; pbxJG.Visible = false; } timer1.Start(); } #region 焦点 //private void txtName_Enter(object sender, EventArgs e) //{ // if (txtName.Text.Trim() != "请输入用户名") // { // } // else if (txtName.Text == "") // { // txtName.Text = "请输入用户名"; // } // else // { // txtName.Text = ""; // } //} //private void txtName_Leave(object sender, EventArgs e) //{ // if (txtName.Text.Trim() != "请输入用户名") // { // } // else if (txtName.Text.Trim() == "") // { // txtName.Text = "请输入用户名"; // } // else // { // txtName.Text = "请输入用户名"; // } //} //private void txtPwd_Enter(object sender, EventArgs e) //{ // if (txtPwd.Text.Trim() != "请输入密码") // { // } // else if (txtPwd.Text == "") // { // txtPwd.Text = "请输入密码"; // } // else // { // txtPwd.Text = ""; // } //} //private void txtPwd_Leave(object sender, EventArgs e) //{ // if (txtPwd.Text.Trim() != "请输入密码") // { // } // else if (txtPwd.Text == "") // { // txtPwd.Text = "请输入密码"; // } // else // { // txtPwd.Text = ""; // } //} #endregion #region 双击右下角 /// <summary> /// 双击右下角 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void notifyIcon_DoubleClick(object sender, EventArgs e) { if (this.Visible) { this.Hide(); } else { this.Show(); this.WindowState = FormWindowState.Normal; } } #endregion #region 打开主界面 private void 打开主界面ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.Visible) { this.Hide(); } else { this.Show(); this.WindowState = FormWindowState.Normal; } } #endregion #region 当窗体最小化时候 private void Form1_SizeChanged(object sender, EventArgs e) { if (WindowState == FormWindowState.Minimized) { this.Hide(); this.notifyIcon.Visible = true; this.notifyIcon.ShowBalloonTip(20, "提示", "欢迎使用离线消息推送OKEY", ToolTipIcon.Info); } } #endregion #region 普通登陆时候 ///// <summary> ///// 普通登陆中的登陆按钮 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //private void benDengLu_Click_1(object sender, EventArgs e) //{ // name = txtName.Text.Trim(); // pwd = txtPwd.Text.Trim(); // //if(name.Equals("houc")) // //{ // System.Diagnostics.Process ie = new System.Diagnostics.Process(); // ie.StartInfo.FileName = "IEXPLORE.EXE"; // ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd; // ie.Start(); // this.Hide(); // //} //} ///// <summary> ///// 普通登陆中的取消 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //private void benQuXiao_Click_1(object sender, EventArgs e) //{ //} #endregion private void timer1_Tick(object sender, EventArgs e) { ob = ProgramHasp.getHaspKey();//电子狗状态 if (JS == 0)//只打开了页面(要不就是先插电子狗了要不就是只打开页面没点电子狗呢) { if (ob == "没有该OKEY的用户信息,请联系管理员") { pbxJG.Visible = true; lblXsCg.Text = "请插入OKEY,并点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = false; } else { pbxJG.Visible = false; lblXsCg.Text = "您的用户信息正确,请点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = true; } } else if (JS == 1)//点击过登陆后(插了或者扒了) { if (ob == "没有该OKEY的用户信息,请联系管理员") { timer1.Stop(); DialogResult rs = MessageBox.Show("为了您的帐号安全,系统将关闭所有IE正在打开的页面,关闭后请您重新打开!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (rs == DialogResult.OK) { Process[] processes = Process.GetProcesses();//获得当前所有运行的进程 foreach (Process p in processes) { if (p.ProcessName.ToLower() == "iexplore") { p.Kill(); JS = 0; timer1.Start(); } } } } } } private void btnDengKEY_Click_1(object sender, EventArgs e) { List<LoginKey> lt = LoginKeyManager.getOkey(); string KEY = ""; for (int i = 0; i < lt.Count; i++) { KEY = lt[i].Key; if (ob != KEY) { MessageBox.Show("没有查询到该OKEY的用户信息,请联系管理员"); } else { System.Diagnostics.Process ie = new System.Diagnostics.Process(); ie.StartInfo.FileName = "IEXPLORE.EXE"; ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd + "&key=" + ob; ie.Start(); this.Hide(); Form3 f3 = new Form3(); f3.Show(); JS = 1; } } } #region 右键退出 private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e) { this.Close(); JS = 0; } #endregion private void button2_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } #region 拖动窗体 private void Login_MouseDown(object sender, MouseEventArgs e) { mPoint.X = e.X; mPoint.Y = e.Y; } private void Login_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point myPosittion = MousePosition; myPosittion.Offset(-mPoint.X, -mPoint.Y); Location = myPosittion; } } #endregion private void btnGB_Click(object sender, EventArgs e) { this.Close(); } private void btnDengKEY_MouseMove_1(object sender, MouseEventArgs e) { btnDengKEY.BackColor = Color.Red; } private void btnDengKEY_MouseLeave_1(object sender, EventArgs e) { btnDengKEY.BackColor = Color.Transparent; } private void timer2_Tick(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.Show(); timer2.Stop(); } using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using login_sample;using Aladdin.HASP;using System.Runtime.InteropServices;using System.Xml.XPath;using System.Xml;using System.IO;using System.Collections;using System.Diagnostics;using Model;using BLL;namespace WindowsApp{ public partial class Login : Form { private Point mPoint = new Point(); static string ob = ""; static string name = ""; static string pwd = ""; static int JS = 0; public Login() { InitializeComponent(); //txtName.Enter += new EventHandler(txtName_Enter); //获得焦点事件 //txtName.Leave += new EventHandler(txtName_Leave); //失去焦点事件。 //txtPwd.Enter += new EventHandler(txtPwd_Enter); //获得焦点事件 //txtPwd.Leave += new EventHandler(txtPwd_Leave); //失去焦点事件。 } private void Form1_Load(object sender, EventArgs e) { InitializeComponent(); ob = ProgramHasp.getHaspKey();//电子狗状态 if (ob == "没有该OKEY的用户信息,请联系管理员") { lblXsCg.Text = "请插入OKEY,并点击登陆按钮"; btnDengKEY.Visible = false; pbxJG.Visible = true; } else { lblXsCg.Text = "您的用户信息正确,请点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = true; pbxJG.Visible = false; } timer1.Start(); } #region 焦点 //private void txtName_Enter(object sender, EventArgs e) //{ // if (txtName.Text.Trim() != "请输入用户名") // { // } // else if (txtName.Text == "") // { // txtName.Text = "请输入用户名"; // } // else // { // txtName.Text = ""; // } //} //private void txtName_Leave(object sender, EventArgs e) //{ // if (txtName.Text.Trim() != "请输入用户名") // { // } // else if (txtName.Text.Trim() == "") // { // txtName.Text = "请输入用户名"; // } // else // { // txtName.Text = "请输入用户名"; // } //} //private void txtPwd_Enter(object sender, EventArgs e) //{ // if (txtPwd.Text.Trim() != "请输入密码") // { // } // else if (txtPwd.Text == "") // { // txtPwd.Text = "请输入密码"; // } // else // { // txtPwd.Text = ""; // } //} //private void txtPwd_Leave(object sender, EventArgs e) //{ // if (txtPwd.Text.Trim() != "请输入密码") // { // } // else if (txtPwd.Text == "") // { // txtPwd.Text = "请输入密码"; // } // else // { // txtPwd.Text = ""; // } //} #endregion #region 双击右下角 /// <summary> /// 双击右下角 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void notifyIcon_DoubleClick(object sender, EventArgs e) { if (this.Visible) { this.Hide(); } else { this.Show(); this.WindowState = FormWindowState.Normal; } } #endregion #region 打开主界面 private void 打开主界面ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.Visible) { this.Hide(); } else { this.Show(); this.WindowState = FormWindowState.Normal; } } #endregion #region 当窗体最小化时候 private void Form1_SizeChanged(object sender, EventArgs e) { if (WindowState == FormWindowState.Minimized) { this.Hide(); this.notifyIcon.Visible = true; this.notifyIcon.ShowBalloonTip(20, "提示", "欢迎使用离线消息推送OKEY", ToolTipIcon.Info); } } #endregion #region 普通登陆时候 ///// <summary> ///// 普通登陆中的登陆按钮 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //private void benDengLu_Click_1(object sender, EventArgs e) //{ // name = txtName.Text.Trim(); // pwd = txtPwd.Text.Trim(); // //if(name.Equals("houc")) // //{ // System.Diagnostics.Process ie = new System.Diagnostics.Process(); // ie.StartInfo.FileName = "IEXPLORE.EXE"; // ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd; // ie.Start(); // this.Hide(); // //} //} ///// <summary> ///// 普通登陆中的取消 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //private void benQuXiao_Click_1(object sender, EventArgs e) //{ //} #endregion private void timer1_Tick(object sender, EventArgs e) { ob = ProgramHasp.getHaspKey();//电子狗状态 if (JS == 0)//只打开了页面(要不就是先插电子狗了要不就是只打开页面没点电子狗呢) { if (ob == "没有该OKEY的用户信息,请联系管理员") { pbxJG.Visible = true; lblXsCg.Text = "请插入OKEY,并点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = false; } else { pbxJG.Visible = false; lblXsCg.Text = "您的用户信息正确,请点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = true; } } else if (JS == 1)//点击过登陆后(插了或者扒了) { if (ob == "没有该OKEY的用户信息,请联系管理员") { timer1.Stop(); DialogResult rs = MessageBox.Show("为了您的帐号安全,系统将关闭所有IE正在打开的页面,关闭后请您重新打开!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (rs == DialogResult.OK) { Process[] processes = Process.GetProcesses();//获得当前所有运行的进程 foreach (Process p in processes) { if (p.ProcessName.ToLower() == "iexplore") { p.Kill(); JS = 0; timer1.Start(); } } } } } } private void btnDengKEY_Click_1(object sender, EventArgs e) { List<LoginKey> lt = LoginKeyManager.getOkey(); string KEY = ""; for (int i = 0; i < lt.Count; i++) { KEY = lt[i].Key; if (ob != KEY) { MessageBox.Show("没有查询到该OKEY的用户信息,请联系管理员"); } else { System.Diagnostics.Process ie = new System.Diagnostics.Process(); ie.StartInfo.FileName = "IEXPLORE.EXE"; ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd + "&key=" + ob; ie.Start(); this.Hide(); Form3 f3 = new Form3(); f3.Show(); JS = 1; } } } #region 右键退出 private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e) { this.Close(); JS = 0; } #endregion private void button2_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } #region 拖动窗体 private void Login_MouseDown(object sender, MouseEventArgs e) { mPoint.X = e.X; mPoint.Y = e.Y; } private void Login_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point myPosittion = MousePosition; myPosittion.Offset(-mPoint.X, -mPoint.Y); Location = myPosittion; } } #endregion private void btnGB_Click(object sender, EventArgs e) { this.Close(); } private void btnDengKEY_MouseMove_1(object sender, MouseEventArgs e) { btnDengKEY.BackColor = Color.Red; } private void btnDengKEY_MouseLeave_1(object sender, EventArgs e) { btnDengKEY.BackColor = Color.Transparent; } private void timer2_Tick(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.Show(); timer2.Stop(); }我知道那的原因了。谢谢你 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using login_sample;using Aladdin.HASP;using System.Runtime.InteropServices;using System.Xml.XPath;using System.Xml;using System.IO;using System.Collections;using System.Diagnostics;using Model;using BLL;namespace WindowsApp{ public partial class Login : Form { private Point mPoint = new Point(); static string ob = ""; static string name = ""; static string pwd = ""; static int JS = 0; public Login() { InitializeComponent(); //txtName.Enter += new EventHandler(txtName_Enter); //获得焦点事件 //txtName.Leave += new EventHandler(txtName_Leave); //失去焦点事件。 //txtPwd.Enter += new EventHandler(txtPwd_Enter); //获得焦点事件 //txtPwd.Leave += new EventHandler(txtPwd_Leave); //失去焦点事件。 } private void Form1_Load(object sender, EventArgs e) { InitializeComponent(); ob = ProgramHasp.getHaspKey();//电子狗状态 if (ob == "没有该OKEY的用户信息,请联系管理员") { lblXsCg.Text = "请插入OKEY,并点击登陆按钮"; btnDengKEY.Visible = false; pbxJG.Visible = true; } else { lblXsCg.Text = "您的用户信息正确,请点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = true; pbxJG.Visible = false; } timer1.Start(); } #region 焦点 //private void txtName_Enter(object sender, EventArgs e) //{ // if (txtName.Text.Trim() != "请输入用户名") // { // } // else if (txtName.Text == "") // { // txtName.Text = "请输入用户名"; // } // else // { // txtName.Text = ""; // } //} //private void txtName_Leave(object sender, EventArgs e) //{ // if (txtName.Text.Trim() != "请输入用户名") // { // } // else if (txtName.Text.Trim() == "") // { // txtName.Text = "请输入用户名"; // } // else // { // txtName.Text = "请输入用户名"; // } //} //private void txtPwd_Enter(object sender, EventArgs e) //{ // if (txtPwd.Text.Trim() != "请输入密码") // { // } // else if (txtPwd.Text == "") // { // txtPwd.Text = "请输入密码"; // } // else // { // txtPwd.Text = ""; // } //} //private void txtPwd_Leave(object sender, EventArgs e) //{ // if (txtPwd.Text.Trim() != "请输入密码") // { // } // else if (txtPwd.Text == "") // { // txtPwd.Text = "请输入密码"; // } // else // { // txtPwd.Text = ""; // } //} #endregion #region 双击右下角 /// <summary> /// 双击右下角 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void notifyIcon_DoubleClick(object sender, EventArgs e) { if (this.Visible) { this.Hide(); } else { this.Show(); this.WindowState = FormWindowState.Normal; } } #endregion #region 打开主界面 private void 打开主界面ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.Visible) { this.Hide(); } else { this.Show(); this.WindowState = FormWindowState.Normal; } } #endregion #region 当窗体最小化时候 private void Form1_SizeChanged(object sender, EventArgs e) { if (WindowState == FormWindowState.Minimized) { this.Hide(); this.notifyIcon.Visible = true; this.notifyIcon.ShowBalloonTip(20, "提示", "欢迎使用离线消息推送OKEY", ToolTipIcon.Info); } } #endregion #region 普通登陆时候 ///// <summary> ///// 普通登陆中的登陆按钮 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //private void benDengLu_Click_1(object sender, EventArgs e) //{ // name = txtName.Text.Trim(); // pwd = txtPwd.Text.Trim(); // //if(name.Equals("houc")) // //{ // System.Diagnostics.Process ie = new System.Diagnostics.Process(); // ie.StartInfo.FileName = "IEXPLORE.EXE"; // ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd; // ie.Start(); // this.Hide(); // //} //} ///// <summary> ///// 普通登陆中的取消 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //private void benQuXiao_Click_1(object sender, EventArgs e) //{ //} #endregion private void timer1_Tick(object sender, EventArgs e) { ob = ProgramHasp.getHaspKey();//电子狗状态 if (JS == 0)//只打开了页面(要不就是先插电子狗了要不就是只打开页面没点电子狗呢) { if (ob == "没有该OKEY的用户信息,请联系管理员") { pbxJG.Visible = true; lblXsCg.Text = "请插入OKEY,并点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = false; } else { pbxJG.Visible = false; lblXsCg.Text = "您的用户信息正确,请点击登陆按钮"; lblXsCg.ForeColor = Color.Red; lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold); btnDengKEY.Visible = true; } } else if (JS == 1)//点击过登陆后(插了或者扒了) { if (ob == "没有该OKEY的用户信息,请联系管理员") { timer1.Stop(); DialogResult rs = MessageBox.Show("为了您的帐号安全,系统将关闭所有IE正在打开的页面,关闭后请您重新打开!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (rs == DialogResult.OK) { Process[] processes = Process.GetProcesses();//获得当前所有运行的进程 foreach (Process p in processes) { if (p.ProcessName.ToLower() == "iexplore") { p.Kill(); JS = 0; timer1.Start(); } } } } } } private void btnDengKEY_Click_1(object sender, EventArgs e) { List<LoginKey> lt = LoginKeyManager.getOkey(); string KEY = ""; for (int i = 0; i < lt.Count; i++) { KEY = lt[i].Key; if (ob != KEY) { MessageBox.Show("没有查询到该OKEY的用户信息,请联系管理员"); } else { System.Diagnostics.Process ie = new System.Diagnostics.Process(); ie.StartInfo.FileName = "IEXPLORE.EXE"; ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd + "&key=" + ob; ie.Start(); this.Hide(); Form3 f3 = new Form3(); f3.Show(); JS = 1; } } } #region 右键退出 private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e) { this.Close(); JS = 0; } #endregion private void button2_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } #region 拖动窗体 private void Login_MouseDown(object sender, MouseEventArgs e) { mPoint.X = e.X; mPoint.Y = e.Y; } private void Login_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point myPosittion = MousePosition; myPosittion.Offset(-mPoint.X, -mPoint.Y); Location = myPosittion; } } #endregion private void btnGB_Click(object sender, EventArgs e) { this.Close(); } private void btnDengKEY_MouseMove_1(object sender, MouseEventArgs e) { btnDengKEY.BackColor = Color.Red; } private void btnDengKEY_MouseLeave_1(object sender, EventArgs e) { btnDengKEY.BackColor = Color.Transparent; } private void timer2_Tick(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.Show(); timer2.Stop(); }我知道那的原因了。谢谢你现在的问题是,我A窗体登陆后右下角不是有图标么。然后我让他点击登陆时候在右下角打开了个B窗体,样子类似提醒窗体是的,然后我关闭B窗体触发A窗体里的第2个timer控件。就Timer2,但是现在我关闭B窗体时候右下角出2个图标。为啥呢 namespace WindowsApp{ public partial class Form3 : Form { Timer T; int n = 0; System.Threading.Thread show; public Form3() { InitializeComponent(); T = new Timer(); T.Interval = 100; T.Tick += new EventHandler(timer_Tick); } private void btnQBHL_Click(object sender, EventArgs e) { this.Close(); Login ll = new Login(); ll.timer2.Start(); } private void btnGB_Click(object sender, EventArgs e) { this.Close(); Login ll = new Login(); ll.timer2.Start(); } private void timer_Tick(object sender, EventArgs e) { if (n < 50) { Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width - n, Screen.PrimaryScreen.WorkingArea.Height - this.Height - n); this.Location = p; n += 50; } } private void Form3_Load(object sender, EventArgs e) { //屏幕右下角出现 Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height); this.Location = p; T.Start(); lblTianqi.Text = DateTime.Now.ToString(); }这个是B窗体。麻烦了哥,真心卡这了 放多个timer时间不会冲突的,都是单独的实例,时间有误差倒是真的,只不过基本可以忽略对它们分别设置不同的Interval即可实现不同的触发间隔 B关闭时开启,//FormA.csvar b = new FormB();b.Closed += (obj, e) => this.timer1.Start();b.Show(); 那个我知道了。楼上的大神帮我解决了。但是我现在有别的问题了。我在A窗体登陆后隐藏到右下角图标。并且弹出B窗体,然后我在B窗体的关闭按钮里写的调用A页面的timer2打开,现在我一点关闭B窗体右下角图标就多出一个点一次多一个。不知道怎么回事。求助啊 加到弹出B窗口的地方就行了,比如在A窗口登陆成功后if(登陆成功){ this.隐藏至右下角图标.. //弹出B窗口 var b = new FormB(); //注册B窗口关闭时的事件处理(启动当前窗口A的一个timer) b.Closed += (obj, e) => this.timer1.Start(); //显示B窗口 b.Show();}去了解事件驱动 if(登陆成功){ this.隐藏至右下角图标.. //弹出B窗口 var b = new FormB(); //注册B窗口关闭时的事件处理(启动当前窗口A的一个timer) b.FormClosed += (obj, e) => this.timer1.Start(); //显示B窗口 b.Show();} pbxJG.Visible = false;你这个有问题,需要在关闭窗口的时候加这个,我看你成功的时候,将pbxJG.Visible = true了 C# 中有三种 timer,不要用控件库中的那个可以拖到界面的timer,改用THread下的timer,可以拖到界面的timer 会占用 主线程 怎么用这个啊如果我想在网上找这个timer我怎么搜索呀,这个真心没用过 看这里:http://blog.csdn.net/busydonkey/article/details/5327665 我也有这的遭遇~这是我的帖子:http://bbs.csdn.net/topics/390521036 GridView自动列设置列宽 C# 关于自己写一个c#代码编辑器的问题,请不吝赐教 无法参与分布式事务处理(100分求助) 请教大家一个关于vs.net系统的问题!高分相送! WPF,一个数据验证的问题 一个 ADO.NET 操作Oracle 的奇怪问题 怎么判断一个元素在不在一个集合里面? C#程序如何定义全局热键!!!! 怎么将excel中数据用C#读取并存在一个数组中? C#怎样让WebBrowser滚动条自动上下滚动一定时间 在C#中怎么解析JSON数据,并获取到其中的值?
不知道你在说什么,你timer中的事件写的什么?
如果你在编译器调试模式下,还能按F5吗?
程序怎么运行的,在哪里按的F5...
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using login_sample;
using Aladdin.HASP;
using System.Runtime.InteropServices;
using System.Xml.XPath;
using System.Xml;
using System.IO;
using System.Collections;
using System.Diagnostics;
using Model;
using BLL;
namespace WindowsApp
{
public partial class Login : Form
{
private Point mPoint = new Point();
static string ob = "";
static string name = "";
static string pwd = "";
static int JS = 0;
public Login()
{
InitializeComponent();
//txtName.Enter += new EventHandler(txtName_Enter); //获得焦点事件
//txtName.Leave += new EventHandler(txtName_Leave); //失去焦点事件。
//txtPwd.Enter += new EventHandler(txtPwd_Enter); //获得焦点事件
//txtPwd.Leave += new EventHandler(txtPwd_Leave); //失去焦点事件。
} private void Form1_Load(object sender, EventArgs e)
{
InitializeComponent();
ob = ProgramHasp.getHaspKey();//电子狗状态
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
lblXsCg.Text = "请插入OKEY,并点击登陆按钮";
btnDengKEY.Visible = false;
pbxJG.Visible = true;
}
else
{
lblXsCg.Text = "您的用户信息正确,请点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = true;
pbxJG.Visible = false;
} timer1.Start(); } #region 焦点 //private void txtName_Enter(object sender, EventArgs e)
//{
// if (txtName.Text.Trim() != "请输入用户名")
// { // }
// else if (txtName.Text == "")
// {
// txtName.Text = "请输入用户名";
// }
// else
// {
// txtName.Text = "";
// } //} //private void txtName_Leave(object sender, EventArgs e)
//{
// if (txtName.Text.Trim() != "请输入用户名")
// { // }
// else if (txtName.Text.Trim() == "")
// {
// txtName.Text = "请输入用户名";
// }
// else
// {
// txtName.Text = "请输入用户名";
// }
//} //private void txtPwd_Enter(object sender, EventArgs e)
//{
// if (txtPwd.Text.Trim() != "请输入密码")
// { // }
// else if (txtPwd.Text == "")
// {
// txtPwd.Text = "请输入密码";
// }
// else
// {
// txtPwd.Text = "";
// }
//} //private void txtPwd_Leave(object sender, EventArgs e)
//{
// if (txtPwd.Text.Trim() != "请输入密码")
// { // }
// else if (txtPwd.Text == "")
// {
// txtPwd.Text = "请输入密码";
// }
// else
// {
// txtPwd.Text = "";
// }
//}
#endregion #region 双击右下角
/// <summary>
/// 双击右下角
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> private void notifyIcon_DoubleClick(object sender, EventArgs e)
{
if (this.Visible)
{
this.Hide(); }
else
{
this.Show();
this.WindowState = FormWindowState.Normal;
} }
#endregion
#region 打开主界面
private void 打开主界面ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.Visible)
{
this.Hide();
}
else
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
}
#endregion
#region 当窗体最小化时候
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon.Visible = true;
this.notifyIcon.ShowBalloonTip(20, "提示", "欢迎使用离线消息推送OKEY", ToolTipIcon.Info);
}
}
#endregion #region 普通登陆时候
///// <summary>
///// 普通登陆中的登陆按钮
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void benDengLu_Click_1(object sender, EventArgs e)
//{
// name = txtName.Text.Trim();
// pwd = txtPwd.Text.Trim();
// //if(name.Equals("houc"))
// //{ // System.Diagnostics.Process ie = new System.Diagnostics.Process();
// ie.StartInfo.FileName = "IEXPLORE.EXE";
// ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd;
// ie.Start();
// this.Hide();
// //}
//}
///// <summary>
///// 普通登陆中的取消
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void benQuXiao_Click_1(object sender, EventArgs e)
//{ //}
#endregion
private void timer1_Tick(object sender, EventArgs e)
{ ob = ProgramHasp.getHaspKey();//电子狗状态
if (JS == 0)//只打开了页面(要不就是先插电子狗了要不就是只打开页面没点电子狗呢)
{
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
pbxJG.Visible = true;
lblXsCg.Text = "请插入OKEY,并点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = false;
}
else
{
pbxJG.Visible = false;
lblXsCg.Text = "您的用户信息正确,请点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = true;
}
}
else if (JS == 1)//点击过登陆后(插了或者扒了)
{
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
timer1.Stop();
DialogResult rs = MessageBox.Show("为了您的帐号安全,系统将关闭所有IE正在打开的页面,关闭后请您重新打开!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
if (rs == DialogResult.OK)
{
Process[] processes = Process.GetProcesses();//获得当前所有运行的进程
foreach (Process p in processes)
{
if (p.ProcessName.ToLower() == "iexplore")
{
p.Kill();
JS = 0;
timer1.Start();
}
}
}
}
} }
private void btnDengKEY_Click_1(object sender, EventArgs e)
{
List<LoginKey> lt = LoginKeyManager.getOkey();
string KEY = "";
for (int i = 0; i < lt.Count; i++)
{
KEY = lt[i].Key;
if (ob != KEY)
{
MessageBox.Show("没有查询到该OKEY的用户信息,请联系管理员");
}
else
{
System.Diagnostics.Process ie = new System.Diagnostics.Process();
ie.StartInfo.FileName = "IEXPLORE.EXE";
ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd + "&key=" + ob;
ie.Start();
this.Hide();
Form3 f3 = new Form3();
f3.Show();
JS = 1;
}
}
} #region 右键退出
private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e)
{
this.Close();
JS = 0;
}
#endregion private void button2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized; }
#region 拖动窗体
private void Login_MouseDown(object sender, MouseEventArgs e)
{ mPoint.X = e.X;
mPoint.Y = e.Y;
} private void Login_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point myPosittion = MousePosition;
myPosittion.Offset(-mPoint.X, -mPoint.Y);
Location = myPosittion;
}
}
#endregion private void btnGB_Click(object sender, EventArgs e)
{
this.Close();
} private void btnDengKEY_MouseMove_1(object sender, MouseEventArgs e)
{ btnDengKEY.BackColor = Color.Red;
} private void btnDengKEY_MouseLeave_1(object sender, EventArgs e)
{
btnDengKEY.BackColor = Color.Transparent;
} private void timer2_Tick(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
timer2.Stop();
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using login_sample;
using Aladdin.HASP;
using System.Runtime.InteropServices;
using System.Xml.XPath;
using System.Xml;
using System.IO;
using System.Collections;
using System.Diagnostics;
using Model;
using BLL;
namespace WindowsApp
{
public partial class Login : Form
{
private Point mPoint = new Point();
static string ob = "";
static string name = "";
static string pwd = "";
static int JS = 0;
public Login()
{
InitializeComponent();
//txtName.Enter += new EventHandler(txtName_Enter); //获得焦点事件
//txtName.Leave += new EventHandler(txtName_Leave); //失去焦点事件。
//txtPwd.Enter += new EventHandler(txtPwd_Enter); //获得焦点事件
//txtPwd.Leave += new EventHandler(txtPwd_Leave); //失去焦点事件。
} private void Form1_Load(object sender, EventArgs e)
{
InitializeComponent();
ob = ProgramHasp.getHaspKey();//电子狗状态
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
lblXsCg.Text = "请插入OKEY,并点击登陆按钮";
btnDengKEY.Visible = false;
pbxJG.Visible = true;
}
else
{
lblXsCg.Text = "您的用户信息正确,请点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = true;
pbxJG.Visible = false;
} timer1.Start(); } #region 焦点 //private void txtName_Enter(object sender, EventArgs e)
//{
// if (txtName.Text.Trim() != "请输入用户名")
// { // }
// else if (txtName.Text == "")
// {
// txtName.Text = "请输入用户名";
// }
// else
// {
// txtName.Text = "";
// } //} //private void txtName_Leave(object sender, EventArgs e)
//{
// if (txtName.Text.Trim() != "请输入用户名")
// { // }
// else if (txtName.Text.Trim() == "")
// {
// txtName.Text = "请输入用户名";
// }
// else
// {
// txtName.Text = "请输入用户名";
// }
//} //private void txtPwd_Enter(object sender, EventArgs e)
//{
// if (txtPwd.Text.Trim() != "请输入密码")
// { // }
// else if (txtPwd.Text == "")
// {
// txtPwd.Text = "请输入密码";
// }
// else
// {
// txtPwd.Text = "";
// }
//} //private void txtPwd_Leave(object sender, EventArgs e)
//{
// if (txtPwd.Text.Trim() != "请输入密码")
// { // }
// else if (txtPwd.Text == "")
// {
// txtPwd.Text = "请输入密码";
// }
// else
// {
// txtPwd.Text = "";
// }
//}
#endregion #region 双击右下角
/// <summary>
/// 双击右下角
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> private void notifyIcon_DoubleClick(object sender, EventArgs e)
{
if (this.Visible)
{
this.Hide(); }
else
{
this.Show();
this.WindowState = FormWindowState.Normal;
} }
#endregion
#region 打开主界面
private void 打开主界面ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.Visible)
{
this.Hide();
}
else
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
}
#endregion
#region 当窗体最小化时候
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon.Visible = true;
this.notifyIcon.ShowBalloonTip(20, "提示", "欢迎使用离线消息推送OKEY", ToolTipIcon.Info);
}
}
#endregion #region 普通登陆时候
///// <summary>
///// 普通登陆中的登陆按钮
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void benDengLu_Click_1(object sender, EventArgs e)
//{
// name = txtName.Text.Trim();
// pwd = txtPwd.Text.Trim();
// //if(name.Equals("houc"))
// //{ // System.Diagnostics.Process ie = new System.Diagnostics.Process();
// ie.StartInfo.FileName = "IEXPLORE.EXE";
// ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd;
// ie.Start();
// this.Hide();
// //}
//}
///// <summary>
///// 普通登陆中的取消
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void benQuXiao_Click_1(object sender, EventArgs e)
//{ //}
#endregion
private void timer1_Tick(object sender, EventArgs e)
{ ob = ProgramHasp.getHaspKey();//电子狗状态
if (JS == 0)//只打开了页面(要不就是先插电子狗了要不就是只打开页面没点电子狗呢)
{
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
pbxJG.Visible = true;
lblXsCg.Text = "请插入OKEY,并点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = false;
}
else
{
pbxJG.Visible = false;
lblXsCg.Text = "您的用户信息正确,请点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = true;
}
}
else if (JS == 1)//点击过登陆后(插了或者扒了)
{
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
timer1.Stop();
DialogResult rs = MessageBox.Show("为了您的帐号安全,系统将关闭所有IE正在打开的页面,关闭后请您重新打开!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
if (rs == DialogResult.OK)
{
Process[] processes = Process.GetProcesses();//获得当前所有运行的进程
foreach (Process p in processes)
{
if (p.ProcessName.ToLower() == "iexplore")
{
p.Kill();
JS = 0;
timer1.Start();
}
}
}
}
} }
private void btnDengKEY_Click_1(object sender, EventArgs e)
{
List<LoginKey> lt = LoginKeyManager.getOkey();
string KEY = "";
for (int i = 0; i < lt.Count; i++)
{
KEY = lt[i].Key;
if (ob != KEY)
{
MessageBox.Show("没有查询到该OKEY的用户信息,请联系管理员");
}
else
{
System.Diagnostics.Process ie = new System.Diagnostics.Process();
ie.StartInfo.FileName = "IEXPLORE.EXE";
ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd + "&key=" + ob;
ie.Start();
this.Hide();
Form3 f3 = new Form3();
f3.Show();
JS = 1;
}
}
} #region 右键退出
private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e)
{
this.Close();
JS = 0;
}
#endregion private void button2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized; }
#region 拖动窗体
private void Login_MouseDown(object sender, MouseEventArgs e)
{ mPoint.X = e.X;
mPoint.Y = e.Y;
} private void Login_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point myPosittion = MousePosition;
myPosittion.Offset(-mPoint.X, -mPoint.Y);
Location = myPosittion;
}
}
#endregion private void btnGB_Click(object sender, EventArgs e)
{
this.Close();
} private void btnDengKEY_MouseMove_1(object sender, MouseEventArgs e)
{ btnDengKEY.BackColor = Color.Red;
} private void btnDengKEY_MouseLeave_1(object sender, EventArgs e)
{
btnDengKEY.BackColor = Color.Transparent;
} private void timer2_Tick(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
timer2.Stop();
}我知道那的原因了。谢谢你
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using login_sample;
using Aladdin.HASP;
using System.Runtime.InteropServices;
using System.Xml.XPath;
using System.Xml;
using System.IO;
using System.Collections;
using System.Diagnostics;
using Model;
using BLL;
namespace WindowsApp
{
public partial class Login : Form
{
private Point mPoint = new Point();
static string ob = "";
static string name = "";
static string pwd = "";
static int JS = 0;
public Login()
{
InitializeComponent();
//txtName.Enter += new EventHandler(txtName_Enter); //获得焦点事件
//txtName.Leave += new EventHandler(txtName_Leave); //失去焦点事件。
//txtPwd.Enter += new EventHandler(txtPwd_Enter); //获得焦点事件
//txtPwd.Leave += new EventHandler(txtPwd_Leave); //失去焦点事件。
} private void Form1_Load(object sender, EventArgs e)
{
InitializeComponent();
ob = ProgramHasp.getHaspKey();//电子狗状态
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
lblXsCg.Text = "请插入OKEY,并点击登陆按钮";
btnDengKEY.Visible = false;
pbxJG.Visible = true;
}
else
{
lblXsCg.Text = "您的用户信息正确,请点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = true;
pbxJG.Visible = false;
} timer1.Start(); } #region 焦点 //private void txtName_Enter(object sender, EventArgs e)
//{
// if (txtName.Text.Trim() != "请输入用户名")
// { // }
// else if (txtName.Text == "")
// {
// txtName.Text = "请输入用户名";
// }
// else
// {
// txtName.Text = "";
// } //} //private void txtName_Leave(object sender, EventArgs e)
//{
// if (txtName.Text.Trim() != "请输入用户名")
// { // }
// else if (txtName.Text.Trim() == "")
// {
// txtName.Text = "请输入用户名";
// }
// else
// {
// txtName.Text = "请输入用户名";
// }
//} //private void txtPwd_Enter(object sender, EventArgs e)
//{
// if (txtPwd.Text.Trim() != "请输入密码")
// { // }
// else if (txtPwd.Text == "")
// {
// txtPwd.Text = "请输入密码";
// }
// else
// {
// txtPwd.Text = "";
// }
//} //private void txtPwd_Leave(object sender, EventArgs e)
//{
// if (txtPwd.Text.Trim() != "请输入密码")
// { // }
// else if (txtPwd.Text == "")
// {
// txtPwd.Text = "请输入密码";
// }
// else
// {
// txtPwd.Text = "";
// }
//}
#endregion #region 双击右下角
/// <summary>
/// 双击右下角
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> private void notifyIcon_DoubleClick(object sender, EventArgs e)
{
if (this.Visible)
{
this.Hide(); }
else
{
this.Show();
this.WindowState = FormWindowState.Normal;
} }
#endregion
#region 打开主界面
private void 打开主界面ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.Visible)
{
this.Hide();
}
else
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
}
#endregion
#region 当窗体最小化时候
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon.Visible = true;
this.notifyIcon.ShowBalloonTip(20, "提示", "欢迎使用离线消息推送OKEY", ToolTipIcon.Info);
}
}
#endregion #region 普通登陆时候
///// <summary>
///// 普通登陆中的登陆按钮
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void benDengLu_Click_1(object sender, EventArgs e)
//{
// name = txtName.Text.Trim();
// pwd = txtPwd.Text.Trim();
// //if(name.Equals("houc"))
// //{ // System.Diagnostics.Process ie = new System.Diagnostics.Process();
// ie.StartInfo.FileName = "IEXPLORE.EXE";
// ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd;
// ie.Start();
// this.Hide();
// //}
//}
///// <summary>
///// 普通登陆中的取消
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void benQuXiao_Click_1(object sender, EventArgs e)
//{ //}
#endregion
private void timer1_Tick(object sender, EventArgs e)
{ ob = ProgramHasp.getHaspKey();//电子狗状态
if (JS == 0)//只打开了页面(要不就是先插电子狗了要不就是只打开页面没点电子狗呢)
{
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
pbxJG.Visible = true;
lblXsCg.Text = "请插入OKEY,并点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = false;
}
else
{
pbxJG.Visible = false;
lblXsCg.Text = "您的用户信息正确,请点击登陆按钮";
lblXsCg.ForeColor = Color.Red;
lblXsCg.Font = new Font(lblXsCg.Font, lblXsCg.Font.Style | FontStyle.Bold);
btnDengKEY.Visible = true;
}
}
else if (JS == 1)//点击过登陆后(插了或者扒了)
{
if (ob == "没有该OKEY的用户信息,请联系管理员")
{
timer1.Stop();
DialogResult rs = MessageBox.Show("为了您的帐号安全,系统将关闭所有IE正在打开的页面,关闭后请您重新打开!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
if (rs == DialogResult.OK)
{
Process[] processes = Process.GetProcesses();//获得当前所有运行的进程
foreach (Process p in processes)
{
if (p.ProcessName.ToLower() == "iexplore")
{
p.Kill();
JS = 0;
timer1.Start();
}
}
}
}
} }
private void btnDengKEY_Click_1(object sender, EventArgs e)
{
List<LoginKey> lt = LoginKeyManager.getOkey();
string KEY = "";
for (int i = 0; i < lt.Count; i++)
{
KEY = lt[i].Key;
if (ob != KEY)
{
MessageBox.Show("没有查询到该OKEY的用户信息,请联系管理员");
}
else
{
System.Diagnostics.Process ie = new System.Diagnostics.Process();
ie.StartInfo.FileName = "IEXPLORE.EXE";
ie.StartInfo.Arguments = @"http://192.168.1.100/appv1/logoCL.aspx?PageUrl=" + name + "&Title=" + pwd + "&key=" + ob;
ie.Start();
this.Hide();
Form3 f3 = new Form3();
f3.Show();
JS = 1;
}
}
} #region 右键退出
private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e)
{
this.Close();
JS = 0;
}
#endregion private void button2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized; }
#region 拖动窗体
private void Login_MouseDown(object sender, MouseEventArgs e)
{ mPoint.X = e.X;
mPoint.Y = e.Y;
} private void Login_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point myPosittion = MousePosition;
myPosittion.Offset(-mPoint.X, -mPoint.Y);
Location = myPosittion;
}
}
#endregion private void btnGB_Click(object sender, EventArgs e)
{
this.Close();
} private void btnDengKEY_MouseMove_1(object sender, MouseEventArgs e)
{ btnDengKEY.BackColor = Color.Red;
} private void btnDengKEY_MouseLeave_1(object sender, EventArgs e)
{
btnDengKEY.BackColor = Color.Transparent;
} private void timer2_Tick(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
timer2.Stop();
}我知道那的原因了。谢谢你现在的问题是,我A窗体登陆后右下角不是有图标么。然后我让他点击登陆时候在右下角打开了个B窗体,样子类似提醒窗体是的,然后我关闭B窗体触发A窗体里的第2个timer控件。就Timer2,但是现在我关闭B窗体时候右下角出2个图标。为啥呢
{
public partial class Form3 : Form
{
Timer T;
int n = 0;
System.Threading.Thread show;
public Form3()
{
InitializeComponent();
T = new Timer();
T.Interval = 100;
T.Tick += new EventHandler(timer_Tick);
} private void btnQBHL_Click(object sender, EventArgs e)
{
this.Close();
Login ll = new Login();
ll.timer2.Start();
} private void btnGB_Click(object sender, EventArgs e)
{
this.Close();
Login ll = new Login();
ll.timer2.Start();
} private void timer_Tick(object sender, EventArgs e)
{
if (n < 50)
{
Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width - n, Screen.PrimaryScreen.WorkingArea.Height - this.Height - n);
this.Location = p;
n += 50;
}
} private void Form3_Load(object sender, EventArgs e)
{
//屏幕右下角出现
Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
this.Location = p;
T.Start();
lblTianqi.Text = DateTime.Now.ToString();
}这个是B窗体。麻烦了哥,真心卡这了
对它们分别设置不同的Interval即可实现不同的触发间隔
//FormA.cs
var b = new FormB();
b.Closed += (obj, e) => this.timer1.Start();
b.Show();
那个我知道了。楼上的大神帮我解决了。但是我现在有别的问题了。我在A窗体登陆后隐藏到右下角图标。并且弹出B窗体,然后我在B窗体的关闭按钮里写的调用A页面的timer2打开,现在我一点关闭B窗体右下角图标就多出一个点一次多一个。不知道怎么回事。求助啊
if(登陆成功)
{
this.隐藏至右下角图标..
//弹出B窗口
var b = new FormB();
//注册B窗口关闭时的事件处理(启动当前窗口A的一个timer)
b.Closed += (obj, e) => this.timer1.Start();
//显示B窗口
b.Show();
}
去了解事件驱动
{
this.隐藏至右下角图标..
//弹出B窗口
var b = new FormB();
//注册B窗口关闭时的事件处理(启动当前窗口A的一个timer)
b.FormClosed += (obj, e) => this.timer1.Start();
//显示B窗口
b.Show();
}
看这里:
http://blog.csdn.net/busydonkey/article/details/5327665
我也有这的遭遇~
这是我的帖子:http://bbs.csdn.net/topics/390521036