notifyIcon1只是把自己的窗体最小化到托盘中,现在的问题是把打开的所有的窗体都最小化到任务栏上,可能窗体不是自己程序的

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace 系统托盘
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.ContextMenu contextMenu1;
    private System.Windows.Forms.NotifyIcon notifyIcon1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.MenuItem menuItem2;
    private System.Windows.Forms.MenuItem menuItem3;
    private System.Windows.Forms.Label label1;
    private System.ComponentModel.IContainer components; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.components = new System.ComponentModel.Container();
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
    this.contextMenu1 = new System.Windows.Forms.ContextMenu();
    this.menuItem1 = new System.Windows.Forms.MenuItem();
    this.menuItem2 = new System.Windows.Forms.MenuItem();
    this.menuItem3 = new System.Windows.Forms.MenuItem();
    this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
    this.label1 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // contextMenu1
    // 
    this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
     this.menuItem1,
     this.menuItem2,
     this.menuItem3});
    // 
    // menuItem1
    // 
    this.menuItem1.Index = 0;
    this.menuItem1.Text = "显示";
    this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
    // 
    // menuItem2
    // 
    this.menuItem2.Index = 1;
    this.menuItem2.Text = "隐藏";
    this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
    // 
    // menuItem3
    // 
    this.menuItem3.Index = 2;
    this.menuItem3.Text = "退出";
    this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
    // 
    // notifyIcon1
    // 
    this.notifyIcon1.ContextMenu = this.contextMenu1;
    this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
    this.notifyIcon1.Text = "这是一个演示程序,图标停放在任务栏上的测试程序";
    this.notifyIcon1.DoubleClick += new System.EventHandler(this.menuItem1_Click);
    // 
    // label1
    // 
    this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
    this.label1.Location = new System.Drawing.Point(96, 120);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(104, 24);
    this.label1.TabIndex = 0;
    this.label1.Text = "系统托盘";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.label1);
    this.Name = "Form1";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "Form1";
    this.Resize += new System.EventHandler(this.Form1_Resize);
    this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    e.Cancel=true;
    this.Hide();
    this.notifyIcon1.Visible=true;
    } private void menuItem1_Click(object sender, System.EventArgs e)
    {
    this.Show();
    this.Visible=true;
    this.notifyIcon1.Visible=false;

    } private void menuItem2_Click(object sender, System.EventArgs e)
    {
    this.Hide();
    } private void menuItem3_Click(object sender, System.EventArgs e)
    {
    this.notifyIcon1.Visible=false;
    this.Close();
    this.Dispose();
    Application.Exit();
    } private void Form1_Resize(object sender, System.EventArgs e)
    {
    if(this.WindowState==FormWindowState.Minimized)
    {
    notifyIcon1.Visible=true;
    this.Hide();
    }
    if(this.WindowState==FormWindowState.Maximized)
    {
    this.WindowState=FormWindowState.Maximized;
    }
    }
    }
    }
      

  2.   

    可以利用window的自带功能,在当前打开窗体的轴上来得到这些窗体后,进行处理,做个快捷键,就像是“老板键”一样
      

  3.   

    把窗口键+d一起按,实现这个就可以了
    请问怎样发: 用SendKeys.Send("{LWin}"+"D")?
    没有LWin 这个东东哇
      

  4.   

    在2000以上的系统中用Process.Start(@"C:\Documents and Settings\Administrator\Application Data\Microsoft\Internet Explorer\Quick Launch\显示桌面.scf");就可以实现。
      

  5.   

    添加引用 Microsoft Shell Controls and AutomationShell32.ShellClass sc = new Shell32.ShellClass();
    sc.MinimizeAll();  // Win+M
    sc.UnminimizeAll(); // Shift+Win+MIShellDispatch4 sd4 = (IShellDispatch4)sc;
    if(sd4 != null)
      sd4.ToggleDesktop(); // Win+D
      

  6.   

    请问怎样发: 用SendKeys.Send("{LWin}"+"D")?
      

  7.   

    iYoung 朋友的方法我试过了可用,不过得加一个引用,是不是C#本身有这个方法呢,
      

  8.   

    这个功能本来就是针对 Windows Shell 的,对其他平台或其他用户界面无效。.NET Framework 应该不会包括这样的功能吧。
      

  9.   

    再顶一下,但怎么发送键盘的 WIN 键呢
      

  10.   

    这个也可以模拟。试试吧。using System.Runtime.InteropServices;[DllImport("user32.dll", EntryPoint="keybd_event", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern void Keybd_event(byte vk, byte scan, int flags, int extrainfo);
    private static int KEYEVENTF_EXTENDEDKEY = 0x0001;
    private static int KEYEVENTF_KEYUP       = 0x0002;
    private static byte VK_LWIN = 0x5B;private void ToggleDesktop()
    {
    Keybd_event(VK_LWIN, (byte)0, KEYEVENTF_EXTENDEDKEY | 0, 0);
    Keybd_event((byte)'D', (byte)0, 0, 0);
    Keybd_event((byte)'D', (byte)0, KEYEVENTF_KEYUP, 0);
    Keybd_event(VK_LWIN, (byte)0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
    }