我在构造里写this.Hide();没有作用
我要是真正的隐藏,而不是最小化不显示在任务栏中

解决方案 »

  1.   

    在窗体的paint事件中加入this.visible=false
      

  2.   

    static void Main() 
    {
    login newForm=new login();
    newForm.ShowDialog();
    Application.Run(new Form1());
    }
    这样Form1出来就是隐藏的!login是显示的!
      

  3.   

    楼上的办法不错.但是如果说你只是想运行一些不需要Windows窗口显示的程序的话,完全可以"生成控制台应用程序"或"Windows服务"类的项目.这样的程序体积更小运行更快.
      

  4.   

    不知你为何要将其设置成“隐藏”,如果只是想暂时隐藏窗体,在 From_Load 中写“this.visible=false”。如果想永远隐藏,建议做成“Windows Service”
      

  5.   

    From_Load 中写“this.visible=false”不好用
      

  6.   

    \\下面是按你的问题刚写的代码,
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using Microsoft.Win32;
    using System.Data.SqlClient;namespace Zhzuo.WindowsTest
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.NotifyIcon notifyIcon1;
    private System.Windows.Forms.Button button1;
    private System.ComponentModel.IContainer components; public Form1()
    {
    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.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // notifyIcon1
    // 
    this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
    this.notifyIcon1.Text = "notifyIcon1";
    this.notifyIcon1.Visible = true;
    this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(344, 200);
    this.button1.Name = "button1";
    this.button1.TabIndex = 0;
    this.button1.Text = "隐藏";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(464, 289);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }

    private void ShowHideWindow(bool showWindow)
    {
    if(showWindow == true)//显示
    {
    if(this.ShowInTaskbar==false)
    {
    this.ShowInTaskbar = true;
    this.Visible = true;
    //this.Show();
    }
    if(this.WindowState == FormWindowState.Minimized)
    {
    this.WindowState = FormWindowState.Normal;
    }
    this.Activate();
    }
    else//隐藏
    {
    if(this.WindowState == FormWindowState.Minimized)
    {
    this.WindowState = FormWindowState.Normal;
    }
    if(this.ShowInTaskbar == true)
    {
    this.ShowInTaskbar = false;
    this.Visible = false;
    //this.Hide();

    }
    }
    } private void Form1_Load(object sender, System.EventArgs e)
    {
    ShowHideWindow(false);
    } private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
    {
    //显示
    ShowHideWindow(true);
    } private void button1_Click(object sender, System.EventArgs e)
    {
    //隐藏
    ShowHideWindow(false);
    }
    }
    }