表单C#应用程序 [英] forms C# applications

查看:68
本文介绍了表单C#应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在登录表单中按确定"按钮时如何打开表单?
我正在制作两种形式的简单项目
如果用户合法的确定"按钮打开,则第一个表单包含带有两个按钮的用户名和密码
并关闭登录表单
第二种形式包含用于数据库的按钮.

How to open a form when press OK button in log in form ?
I am making a simple project of two forms
first form contains user name and password with two buttons if user legal OK button open next form
and close log in form
second form contains buttons for data base

推荐答案

将第一种形式显示为模式窗口.您的应用程序将等待关闭表单,然后您可以显示下一个表单.相同的材料: http://msdn.microsoft.com/en-us/library/aa984358(v = VS.71).aspx [ ^ ]
Show your first form as modal window. Your application will wait to close form and then you can show next form. Same material: http://msdn.microsoft.com/en-us/library/aa984358(v=VS.71).aspx[^]


按钮点击事件

frm_new objform = new frm_new();
objform.showdailog();
on buttonclick event

frm_new objform=new frm_new();
objform.showdailog();


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

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string Username = "ezz";
        string Password = "zezo";

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != null && textBox1.Text == Username)
            {
                if (textBox2.Text != null && textBox2.Text == Password)
                {
                    this.Close();
                }
                else
                {
                    MessageBox.Show("wrong password");
                }
            }
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            Application.Exit();
        }

    }
}







将此添加到主要内容

Application.Run(新Form1());
Application.Run(new Form2());







ADD THIS TO MAIN

Application.Run(new Form1());
Application.Run(new Form2());


这篇关于表单C#应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆