首页上一页 1 下一页尾页 5 条记录 1/1页
每次点父窗口菜单,打开一个子窗口,可下方的notifyIcon1图标就会多出一个
发表在C#图书答疑
2010-07-17
是否精华
是
否
版块置顶:
是
否
private void ShowNewForm(object sender, EventArgs e)
{
frm_Networking_Maintenance childForm = new frm_Networking_Maintenance();
childForm.MdiParent = this;
childForm.Show();
this.notifyIcon1.Visible = false; [font color=#FF0000]//加了这句都没有用,每次点父窗口菜单,打开一个子窗口,可下方的notifyIcon1图标就会多出一个,要关了再点,又会再多出一个图标,要怎样作才可以让程序只显示一个图标呀?请老师指点一下,谢谢。[/font]
}
[font color=#FF0000]//以下是完整的代码[/font]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace IT部门管理系统
{
public partial class frm_main : Form
{
public frm_main()
{
InitializeComponent();
}
private void ShowNewForm(object sender, EventArgs e)
{
frm_Networking_Maintenance childForm = new frm_Networking_Maintenance();
childForm.MdiParent = this;
childForm.Show();
this.notifyIcon1.Visible = false;
}
private void OpenFile(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = openFileDialog.FileName;
}
}
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = saveFileDialog.FileName;
}
}
private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void CutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}
private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}
private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.ArrangeIcons);
}
private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childForm in MdiChildren)
{
childForm.Close();
}
}
private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
{
frm_dbConf frmdb = new frm_dbConf(); //显示主窗体
frmdb.Show();
}
private void timer1_Tick(object sender, EventArgs e)
{
tsslSTime.Text = "系统时间:" + DateTime.Now.ToString();
}
private void frm_main_Load(object sender, EventArgs e)
{
frm_note childForm = new frm_note();
childForm.MdiParent = this;
childForm.Show();
timer1.Start();
tsslLTime.Text = "|登录时间:" + DateTime.Now.ToShortTimeString();
tsslSTime.Text = "|系统时间:" + DateTime.Now.ToString();
this.notifyIcon1.Visible = false;
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
//if (MessageBox.Show("将要要关闭窗体,是否继续?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes)
//{
// e.Cancel = false;
//}
//else
//{
// e.Cancel = true;
//}
e.Cancel = true;
this.Hide();
this.notifyIcon1.Visible = true;
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible == true) //根据窗口的显示和隐藏设置Trayico对象的显示
{
this.Hide();
this.notifyIcon1.Visible = true;
}
else
{
this.Show();
this.notifyIcon1.Visible = false;
}
}
private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.ExitThread();
this.notifyIcon1.Visible = false;
}
private void 打开主界面ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Show();
this.notifyIcon1.Visible = false;
}
}
}
{
frm_Networking_Maintenance childForm = new frm_Networking_Maintenance();
childForm.MdiParent = this;
childForm.Show();
this.notifyIcon1.Visible = false; [font color=#FF0000]//加了这句都没有用,每次点父窗口菜单,打开一个子窗口,可下方的notifyIcon1图标就会多出一个,要关了再点,又会再多出一个图标,要怎样作才可以让程序只显示一个图标呀?请老师指点一下,谢谢。[/font]
}
[font color=#FF0000]//以下是完整的代码[/font]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace IT部门管理系统
{
public partial class frm_main : Form
{
public frm_main()
{
InitializeComponent();
}
private void ShowNewForm(object sender, EventArgs e)
{
frm_Networking_Maintenance childForm = new frm_Networking_Maintenance();
childForm.MdiParent = this;
childForm.Show();
this.notifyIcon1.Visible = false;
}
private void OpenFile(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = openFileDialog.FileName;
}
}
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = saveFileDialog.FileName;
}
}
private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void CutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}
private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}
private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.ArrangeIcons);
}
private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childForm in MdiChildren)
{
childForm.Close();
}
}
private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
{
frm_dbConf frmdb = new frm_dbConf(); //显示主窗体
frmdb.Show();
}
private void timer1_Tick(object sender, EventArgs e)
{
tsslSTime.Text = "系统时间:" + DateTime.Now.ToString();
}
private void frm_main_Load(object sender, EventArgs e)
{
frm_note childForm = new frm_note();
childForm.MdiParent = this;
childForm.Show();
timer1.Start();
tsslLTime.Text = "|登录时间:" + DateTime.Now.ToShortTimeString();
tsslSTime.Text = "|系统时间:" + DateTime.Now.ToString();
this.notifyIcon1.Visible = false;
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
//if (MessageBox.Show("将要要关闭窗体,是否继续?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes)
//{
// e.Cancel = false;
//}
//else
//{
// e.Cancel = true;
//}
e.Cancel = true;
this.Hide();
this.notifyIcon1.Visible = true;
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible == true) //根据窗口的显示和隐藏设置Trayico对象的显示
{
this.Hide();
this.notifyIcon1.Visible = true;
}
else
{
this.Show();
this.notifyIcon1.Visible = false;
}
}
private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.ExitThread();
this.notifyIcon1.Visible = false;
}
private void 打开主界面ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Show();
this.notifyIcon1.Visible = false;
}
}
}