菜鸟问题:关于如何设定第一个启动的 Form . Application.Run(new Land());将Land()改成你想要启动的窗体的构造函数。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看看public static void Main()中的代码,思考一下,就可以想出方法了。 在MainForm的load事件中实现化登录窗口,不然mainForm不会启动消息泵。 各位老大,我要的不是这样的效果,我的意思是:一开始只启动Loginform ,通过验证后再出现Mainform,好多应用软件都是这样的呀,就象QQ似的,一开始只是个登录界面,通过验证后再出现主界面的,谢谢了,这个问题困惑我好久了! 在VB里面,可以通过 工程属性 -->通用 -->启动对象 设定,启动对象是个下拉框,里面包括这个工程的所有form,选定哪一个,运行时就先启动那一个form. 源码如下:Form1:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Threading;namespace WindowsApplication7{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private static Form1 MainForm; Form2 chilForm; 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() { // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { MainForm = new Form1(); Application.Run(MainForm); } private void Form1_Load(object sender, System.EventArgs e) { ThreadStart ts = new ThreadStart(ShowForm2); Thread t = new Thread(ts); t.Start(); } private void ShowForm2() { chilForm = new Form2(this); chilForm.ShowDialog(); } }}Form2:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace WindowsApplication7{ /// <summary> /// Form2 的摘要说明。 /// </summary> public class Form2 : System.Windows.Forms.Form { private System.ComponentModel.IContainer components = null; private Form1 MainF; //此为主窗体的句柄 public Form2(Form1 MainForm) { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // MainF = MainForm; } /// <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() { // // Form2 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "Form2"; this.Text = "Form2"; this.Load += new System.EventHandler(this.Form2_Load); this.Closed += new System.EventHandler(this.Form2_Closed); } #endregion private void Form2_Load(object sender, System.EventArgs e) { MainF.Visible = false; //主窗体隐藏 } private void Form2_Closed(object sender, System.EventArgs e) { MainF.Visible = true;//主窗体显示 } }} 方法二:private void Form1_Load(object sender, System.EventArgs e) { chilForm = new Form2(); chilForm.ShowDialog(); } 这是主菜单的Load事件,打开Form2后,如果验证不能通过,就用Application.Exit();关闭程序。上面的那个太复杂,没必要用。 非也,找到你目前启动窗口,里面有下面一段话: /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); }你把它“剪切”到你想要的窗口中去,注意,将Form1修改成对应的窗口名称即可。 再补充一点,假如你想用form2启动,修改成: /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form2()); }响应“确定”按钮后:Form1 myForm=new Form1();myForm.ShowDialog(); 在VB里面,可以通过 工程属性 -->通用 -->启动对象 设定,启动对象是个下拉框,里面包括这个工程的所有form,选定哪一个,运行时就先启动那一个form. static void Main() { frmLogin f = new frmLogin(); if (f.ShowDialog() == DialogResult.OK) { Application.Run(new frmMain()); } else { f.Close(); }} 关于DevExpress的GridControl控件中gridview默认选中第一行的问题 局域网防攻击问题 继承问题 TO:思归/其它朋友,帮忙找本电子书. 喜欢技术钻研的进,操蛋的UI设计出的效果,请问大神这个效果可以实现吗?怎么实现? 各位朋友帮忙呀!?? plinq可以指定最大线程数吗? 分割datagridview算法 有没有人用过CrystalReport.SetDataSource方法加载XML数据源 几个巨重要的问题!!!(当然,是对俺来说的) 请教&运算符: 请教,自定义控件如何调用窗口中的事件
public static void Main()中的代码,思考一下,就可以想出方法了。
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;namespace WindowsApplication7
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private static Form1 MainForm;
Form2 chilForm;
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()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
MainForm = new Form1();
Application.Run(MainForm);
} private void Form1_Load(object sender, System.EventArgs e)
{ ThreadStart ts = new ThreadStart(ShowForm2);
Thread t = new Thread(ts);
t.Start(); }
private void ShowForm2()
{
chilForm = new Form2(this);
chilForm.ShowDialog();
}
}
}
Form2:using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace WindowsApplication7
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components = null;
private Form1 MainF; //此为主窗体的句柄 public Form2(Form1 MainForm)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
MainF = MainForm;
} /// <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()
{
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.Closed += new System.EventHandler(this.Form2_Closed); }
#endregion private void Form2_Load(object sender, System.EventArgs e)
{
MainF.Visible = false; //主窗体隐藏
} private void Form2_Closed(object sender, System.EventArgs e)
{
MainF.Visible = true;//主窗体显示
}
}
}
{ chilForm = new Form2();
chilForm.ShowDialog();
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
你把它“剪切”到你想要的窗口中去,注意,将Form1修改成对应的窗口名称即可。
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form2());
}
响应“确定”按钮后:
Form1 myForm=new Form1();
myForm.ShowDialog();
{
frmLogin f = new frmLogin();
if (f.ShowDialog() == DialogResult.OK)
{
Application.Run(new frmMain());
}
else
{
f.Close();
}
}