当前位置:编程学习 > C#/ASP.NET >>

C#窗体自动关闭后自动打开?

问题:我输入密码后进入,会“弹出一个窗体”(说明的功能),这个窗体会自动关闭。。然后又会自动“弹出另一个窗体”(主界面)

============================

自动关闭我实现了。。。现在问题是:第一个窗体自动关闭后。。主界面的窗体不会弹出来....?????请问要怎么实现呀?

追问:是呀是呀,就是这样。。。但你那代码我不怎么看的懂,你能不能加点注释呀。不好意思,刚学。。
答案://FrmPassword

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TEST
{
    public partial class FrmPassword : Form
    {
        public FrmPassword()
        {
            InitializeComponent();
        }

        public static int parameter = 0;

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "dream8fly")
            {
                parameter = 1;
                this.Close();
            }
            else
                MessageBox.Show("");
        }
    }
}

 

//FrmIntroductions

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TEST
{
    public partial class FrmIntroductions : Form
    {
        public FrmIntroductions()
        {
            InitializeComponent();
        }

        private void FrmIntroductions_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

 

//FrmMain

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TEST
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            FrmPassword FrmPass = new FrmPassword();
            FrmPass.ShowDialog();

            if (FrmPassword.parameter == 1)
            {
                new FrmIntroductions().ShowDialog();
            }
            else
            {
                this.Close();
            }
        }
    }
}

程序运行的第一个窗体不能用.Close()方法关闭,,应该用.Hide()

再在第一个窗体的关闭事件里面创建主窗体对象,调用show()方法打开主窗体

上一个:姹備釜锛欳#鐧婚檰楠岃瘉浠g爜 - 宸茶В鍐?- 鎼滄悳闂棶
下一个:谁知道有关C#的内容

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,