我刚刚开始学习C#,有些问题请教大家了!!
1:启动时不显示窗体
自己找了些资料查看,有人说:
   protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  {
      this.Hide();
  }
但是加入这句,实际上窗体会闪一下,通过Application.Run(new form1);实例化一个新的对象,如何才能有效的不显示窗体??
2:启动时同时显示多个窗体
        private static void Main()
        {
            Application.Run(new form1());
            Application.Run(new form1());
            Application.Run(new form1());
        }
我像上面那样写,发现只有一个窗体显示,而且只有关闭了一个窗体,才会产生下一个窗体,我想请问: 如何在一开始就能够让多个窗体同时被实例化,然后显示出来??

解决方案 »

  1.   

    1:我想启动程序时不显示窗体,启动的main函数如下,Application.Run会默认启动一个显示的窗体,更改form的visible=false或者调用this.hide()都是无效的.
            private static void Main()
            {
                Application.Run(new form());
            }
      //在类中加入以下函数,会先闪一下,然后才消失
      protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) 
      { 
          this.Hide(); 
      } 
    我像请问启动程序时如何才能有效的不显示窗体??,而是在之后由其余的事件触发?? 
    2:启动时同时显示多个窗体,我写的main函数如下. 
            private static void Main() 
            { 
                Application.Run(new form1()); 
                Application.Run(new form1()); 
                Application.Run(new form1()); 
            } 
    像上面那样写,始终只有一个窗体显示,而且只有关闭了一个窗体,才会产生下一个窗体.
    我想请问: 如何在程序一开始就能够让多个窗体同时被实例化,比如实例化3个窗体X1,X2,X3,然后让它们同时显示出来,而不是只有一个关闭后才能显示下一个?? LS的Big Brother,这下应该说清楚了吧??求助!!
      

  2.   

    1:启动时不显示窗体
    这个不知所谓
    2:启动时同时显示多个窗体
    Application.Run(new form1()); 这个方法一直到用户关闭窗口时才返回,继续执行下边的代码
      

  3.   

    1:我就是希望启动程序后窗体立刻被隐藏,而不是立刻显示出来.
    2:我知道Application.Run的这个特性,所以我想请问还有没有其它的方法使得不必关闭前面的窗体,而让后面的窗体也能紧随着实例化并显示处理.
      

  4.   

    先处理第二题,代码如下
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;namespace WindowsFormsApplication1 {
        static class Program {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main() {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault( false );
                Form1 frm1 = new Form1();
                frm1.Show();            Form1 frm2 = new Form1();
                frm2.Show();
                Application.Run( );
            }
        }
    }
      

  5.   

    第一题目,我的版本,应该有其它办法
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;namespace WindowsFormsApplication1 {
        static class Program {
            [STAThread]
            static void Main() {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault( false );            Form1 frm2 = new Form1();
                frm2.Load += new EventHandler( frm2_Load );
                Application.Run( frm2 );
            }        static void frm2_Load( object sender, EventArgs e ) {
                Form1 frm2 = sender as Form1;
                if( frm2 != null ) {
                    frm2.Show();
                }
            }
        }    public class Form1 : Form {
            public Form1() {
                InitializeComponent();
                System.Threading.Thread.Sleep( 1000 * 3 );
            }        private System.ComponentModel.IContainer components = null;
            protected override void Dispose( bool disposing ) {
                if( disposing && ( components != null ) ) {
                    components.Dispose();
                }
                base.Dispose( disposing );
            }
            private void InitializeComponent() {
                this.components = new System.ComponentModel.Container();
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.Text = "Form1";
            }
        }
    }
      

  6.   

    感谢kkun_3yue3热心的帮助和提供的代码,问题基本上解决了.