c# 登陆实例代码。

form1 是登陆
form2 是首页

form1中,可以使用 form2.调用



//form1:

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

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "1")
            {
                MessageBox.Show("登录失败");
            }
            if (textBox1.Text == "2")
            {
                MessageBox.Show("登陆成功");
                this.Close();
                Form2.login_flag = 2;
            }
            if (textBox1.Text == "3")
            {
                MessageBox.Show("登陆成功");
                this.Close();
                Form2.login_flag = 3;
            }
            if (textBox1.Text == "4")
            {
                MessageBox.Show("登陆成功");
                this.Close();
                Form2.login_flag = 4;
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}


//program.css

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace jkidclogin
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form2());  //设置启动项
        }
    }
}


//form2:

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

namespace WinFormsApp1
{
    public partial class Form2 : Form
    {
        public static int login_flag;
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.ShowDialog();
            pictureBox1.BackColor = Color.Red;
            textBox1.Text = "welcome :" + login_flag;
        }
    }
}




分类:

发表评论

邮箱地址不会被公开。