C# creates a form application

1. Create a new project and select Form Application

 2. Open the relevant view

Toolbox: Drag the controls in the toolbox directly into the interface, and the corresponding controls will be automatically generated.

Properties: You can set the relevant properties of the control, including events, double-click

3. Design application interface

 4. Create a new interactive window

 5. Add some simple logic to the login window

Login.cs

using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace LibraryManagementSystem
{
    public partial class DailyReading : Form
    {
        public DailyReading()
        {
            InitializeComponent();
        }
        // 点击 登录 按钮显示LibraryManage界面
        private void loginBtn_Click(object sender, EventArgs e)
        {
            // 空输入检查
            if (string.IsNullOrEmpty(usernameInput.Text) || string.IsNullOrEmpty(passwordInput.Text))
            {
                MessageBox.Show("请先填写完整的登录信息!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                return;
            }
            // 检查用户名和密码,假设为 admin 和 123456
            if (usernameInput.Text == "admin" && passwordInput.Text == "123456")
            {
                // 隐藏登录界面,打开 另一个窗口 LibraryManage
                this.Visible = false;
                LibraryManage libraryManage = new LibraryManage();
                libraryManage.Owner = this;
                libraryManage.Show();
            }
            else
            {
                MessageBox.Show("账号或密码错误!请正确填写登录信息!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                return;
            }
        }

        public void windowShow()
        {
            // 当关闭 LibraryManage 界面时返回登录界面,设置登录界面可见
            this.Visible = true;
        }

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

        private void DailyReading_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
    }
}

Add the corresponding interactive code in LibraryManage.cs

using System.Runtime.CompilerServices;
using System.Windows.Forms;

namespace LibraryManagementSystem
{
    public partial class LibraryManage : Form
    {
        public LibraryManage()
        {
            InitializeComponent();
        }
        // 创建一个 登录窗口的实例
        DailyReading dailyReading = new DailyReading();
        // 当关闭 LibraryManage 窗口时,打开登录窗口
        private void LibraryManage_FormClosed(object sender, FormClosedEventArgs e)
        {
            dailyReading.windowShow();
        }
    }
}

At this point, a simple form interaction is completed.

Guess you like

Origin blog.csdn.net/wuxiaoquan_520/article/details/131365296