本篇文章為大家展示了使用VS2012怎么實(shí)現(xiàn)一個(gè)登錄界面,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
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; using System.Data.SqlClient; namespace 登錄x { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void userInfoBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.userInfoBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.studentRecordDataSet); } private void Form1_Load(object sender, EventArgs e) { // TODO: 這行代碼將數(shù)據(jù)加載到表“studentRecordDataSet1.UserInfo”中。您可以根據(jù)需要移動(dòng)或刪除它。 this.userInfoTableAdapter1.Fill(this.studentRecordDataSet1.UserInfo); // TODO: 這行代碼將數(shù)據(jù)加載到表“studentRecordDataSet.UserInfo”中。您可以根據(jù)需要移動(dòng)或刪除它。 this.userInfoTableAdapter.Fill(this.studentRecordDataSet.UserInfo); } private void passwordLabel_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string connString = @"Data Source=.;Initial Catalog=studentrecord;Integrated Security=True"; SqlConnection conn = new SqlConnection(connString); string sql = "select count(*) from UserInfo where username='" + userNameComboBox.Text + "'and password='" + passwordTextBox.Text + "'"; conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); int num = (int)comm.ExecuteScalar(); if (num > 0) { Form2 frm2 = new Form2(); frm2.Show(); } else { MessageBox.Show("對(duì)不起,用戶名和密碼并不匹配!", "登陸失敗"); } conn.Close(); } private void userNameComboBox_SelectedIndexChanged(object sender, EventArgs e) { } private void passwordTextBox_TextChanged(object sender, EventArgs e) { } } }
這個(gè)是第二個(gè)界面的代碼:
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 登錄x { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } } }
上述內(nèi)容就是使用VS2012怎么實(shí)現(xiàn)一個(gè)登錄界面,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。