为何form1关闭。form2也不见了

miaomiaomxt 2002-03-01 10:55:03


namespace WindowsApplication2
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
static Form1 myform1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

public static void Main()
{ myform1= new Form1();
Application.Run(myform1);}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.SuspendLayout();
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,this.toolBarButton2});
this.toolBar1.ButtonClick += new ToolBarButtonClickEventHandler(this.toolbarclick);
this.toolBar1.DropDownArrows = true;
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(552, 38);
this.toolBar1.TabIndex = 0;
//
// toolBarButton1
//
this.toolBarButton1.Text = "new";
this.toolBarButton1.ToolTipText = "3434";

//
// toolBarButton2
//
this.toolBarButton2.Text = "open";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(552, 325);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.toolBar1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
private void toolbarclick(object sender,ToolBarButtonClickEventArgs e)
{
if(e.Button.Equals(toolBarButton1))
{
Form2 myform2 = new Form2();
myform2.Show();
myform1.Close();
}
}
#endregion
}
}
...全文
55 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
anamnesis 2002-03-04
  • 打赏
  • 举报
回复
试试
Application.Run(new Form2());
blahblah 2002-03-02
  • 打赏
  • 举报
回复
你可以吧myform1.Close()改成myform1.Hide()
blahblah 2002-03-02
  • 打赏
  • 举报
回复
form1关闭,Application也结束了。from2是Application里的一个From,所以以就自动关闭了。

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧