![Cnetwinform窗體登錄注冊(cè)_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-1/30/7be484b2-622f-4f35-83a5-f361c81961ff/7be484b2-622f-4f35-83a5-f361c81961ff1.gif)
![Cnetwinform窗體登錄注冊(cè)_第2頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-1/30/7be484b2-622f-4f35-83a5-f361c81961ff/7be484b2-622f-4f35-83a5-f361c81961ff2.gif)
![Cnetwinform窗體登錄注冊(cè)_第3頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-1/30/7be484b2-622f-4f35-83a5-f361c81961ff/7be484b2-622f-4f35-83a5-f361c81961ff3.gif)
![Cnetwinform窗體登錄注冊(cè)_第4頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-1/30/7be484b2-622f-4f35-83a5-f361c81961ff/7be484b2-622f-4f35-83a5-f361c81961ff4.gif)
![Cnetwinform窗體登錄注冊(cè)_第5頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-1/30/7be484b2-622f-4f35-83a5-f361c81961ff/7be484b2-622f-4f35-83a5-f361c81961ff5.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、用C#.Net寫(xiě)的一個(gè)簡(jiǎn)單的登錄及注冊(cè)的小程序1,首先設(shè)計(jì)登錄界面,共有三個(gè),如下:上圖登錄及注冊(cè)為linklabel控件,其他為label控件;上圖為登陸界面,兩個(gè)textbox文本輸入框,注冊(cè)為linklabel控件;界面設(shè)計(jì)很簡(jiǎn)單,不說(shuō)了。2,代碼介紹:1) 主界面(Form1):private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) this.Hide(); Form3 f3 = new Form3(); f3.ShowDialog(); /顯示注冊(cè)界面; private v
2、oid linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) this.Hide(); Form2 f = new Form2(); f.ShowDialog(); if (f.DialogResult = DialogResult.OK) this.Visible = true; /顯示登錄界面; private void Form1_FormClosing(object sender, FormClosingEventArgs e) try System.Diagnostics.Process myPr
3、ocesses = System.Diagnostics.Process.GetProcesses(); foreach (System.Diagnostics.Process myProcess in myProcesses) if ("LoginInterface.exe" = myProcess.ProcessName) myProcess.Kill(); catch (Exception ee) MessageBox.Show(ee.Message); /關(guān)掉程序;2) 注冊(cè)界面(Form3)本文使用的數(shù)據(jù)庫(kù)是sql sever2005,先在引用里加入:using
4、System.Data.SqlClient;以下為程序代碼: public partial class Form3 : Form public Form3() InitializeComponent(); bool flagRegister;/定義標(biāo)志位,確認(rèn)用戶注冊(cè) string strConnect = "Data Source=CAI-PCSQLEXPRESS;Initial Catalog=MyData1;Persist Security Info=True;User ID=sa;Password=*" /連接數(shù)據(jù)庫(kù)字符串 private void button1_
5、Click(object sender, EventArgs e) if (textBox1.Text.Length >= 4) && (textBox1.Text.Length <= 12) && (textBox2.Text.Length >= 6) && (textBox3.Text.Length >= 6) flagRegister = true; else if (textBox1.Text.Length < 4) | (textBox1.Text.Length > 12) MessageBox.Sh
6、ow("用戶名長(zhǎng)度不在約定范圍內(nèi),請(qǐng)重新輸入!", "提示"); return; if (textBox2.Text.Length < 6) MessageBox.Show("密碼長(zhǎng)度不足6位,請(qǐng)重新輸入!","提示"); return; if (textBox3.Text.Length < 6) MessageBox.Show("請(qǐng)重新輸入郵箱!", "提示"); return; /判斷用戶名條件; if (UserFlag = true) MessageBox
7、.Show("用戶已經(jīng)存在,請(qǐng)重新輸入!"); return; if (flagRegister = true) /確認(rèn)用戶注冊(cè)后,把用戶寫(xiě)入數(shù)據(jù)庫(kù) SqlConnection conConnection = new SqlConnection(strConnect); conConnection.Open(); string cmd = "insert into 用戶(用戶名,密碼,email) values ('" + textBox1.Text + "'," + "'" + textB
8、ox2.Text + "'," + "'" + textBox3.Text + "') " SqlCommand com = new SqlCommand(cmd, conConnection); com.ExecuteNonQuery(); conConnection.Close(); MessageBox.Show("注冊(cè)成功!點(diǎn)擊確定,返回登錄界面。", "提示"); this.Close(); Form1 f1 = new Form1(); f1.label2.T
9、ext = "歡迎你," + textBox1.Text; = false; f1.label3.Visible = false; f1.linkLabel1.Visible = false; f1.linkLabel2.Visible = false; f1.label2.Visible = true; f1.Show(); public bool UserFlag; /定義標(biāo)志位,來(lái)確認(rèn)用戶是否存在 private void textBox1_TextChanged(object sender, EventArgs e) SqlConnection conConnect
10、ion = new SqlConnection(strConnect); conConnection.Open(); string cmd = "select 用戶名 from 用戶" SqlCommand com = new SqlCommand(cmd, conConnection); SqlDataReader readerUser = com.ExecuteReader(); while (readerUser.Read() if (textBox1.Text = readerUser"用戶名".ToString().Trim() label5.
11、Text = "用戶已存在,請(qǐng)重新輸入!" UserFlag = true; /textBox1.Text = "" return; else if (textBox1.Text != readerUser"用戶名".ToString().Trim() label5.Text = "恭喜你,該用戶名可以使用。" UserFlag = false; /判斷用戶名是否滿足條件 private void textBox3_TextChanged(object sender, EventArgs e) int index
12、= textBox3.Text.IndexOf(""); if (index < 1) label7.Text = "郵箱格式不正確,請(qǐng)重新輸入!" else label7.Text = "郵箱格式正確" /判斷郵箱格式是否正確 3) 登錄界面(Form2)本文使用的數(shù)據(jù)庫(kù)是sql sever2005,先在引用里加入:using System.Data.SqlClient;以下為程序代碼:string User, Pwd; /用戶名,密碼bool flagshow = false;/用來(lái)標(biāo)注登錄名是否存在于數(shù)據(jù)庫(kù)private
13、void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) this.Hide(); Form3 f3 = new Form3(); f3.ShowDialog(); /顯示注冊(cè)界面 private void button1_Click(object sender, EventArgs e) /登錄 string strConnect = "Data Source=CAI-PCSQLEXPRESS;Initial Catalog=MyData1;Persist Security Info=Tr
14、ue;User ID=sa;Password=*" SqlConnection conConnection = new SqlConnection(strConnect); conConnection.Open(); string cmd = "select 用戶名,密碼,email from 用戶" SqlCommand com = new SqlCommand(cmd, conConnection); SqlDataReader reader = com.ExecuteReader(); while (reader.Read()/從數(shù)據(jù)庫(kù)讀取用戶信息 User
15、 = reader"用戶名".ToString(); Pwd = reader"密碼".ToString(); if (User.Trim () = textBox1.Text & Pwd.Trim () = textBox2.Text) flagshow = true; /用戶名存在于數(shù)據(jù)庫(kù),則為true reader.Close(); conConnection.Close(); if (flagshow = true) showMainForm();/用戶存在,返回登錄界面 else MessageBox.Show("用戶不存在或
16、密碼錯(cuò)誤!", "提示"); return; private void showMainForm()/登錄成功,顯示主界面 this.Close(); Form1 f1 = new Form1(); f1.label1.Visible = false; f1.label3.Visible = false; f1.linkLabel1.Visible = false; f1.linkLabel2.Visible = false; f1.label2.Visible = true; f1.label2.Text = "歡迎你," + textBox1 .Text ; f1.Show(); 3,為美化窗體,可下載winfor
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- idc租賃服務(wù)合同范例
- 存貨質(zhì)押合同范本
- 企業(yè)員工招聘合同范本
- 農(nóng)村安裝路燈合同范例
- 兼職配音協(xié)議合同范本
- 照明燈具采購(gòu)合同范本
- 工業(yè)固體廢物處置合同范本
- 冰箱保養(yǎng)合同范本
- 天籟侗歌苗寨傳
- 2025年度國(guó)際知識(shí)產(chǎn)權(quán)轉(zhuǎn)讓合同范本(含專利保護(hù))
- 施工周報(bào)表(標(biāo)準(zhǔn)模版)
- 4.5MWp分布式光伏項(xiàng)目主要設(shè)備材料清單(建筑工程安裝工程)
- von frey絲K值表完整版
- 云南省普通初中學(xué)生成長(zhǎng)記錄模板-好ok
- SB/T 10415-2007雞粉調(diào)味料
- 考古繪圖基礎(chǔ)
- GB/T 32574-2016抽水蓄能電站檢修導(dǎo)則
- 《社會(huì)主義市場(chǎng)經(jīng)濟(jì)理論(第三版)》第十三章社會(huì)主義市場(chǎng)經(jīng)濟(jì)標(biāo)準(zhǔn)論
- 變更索賠案例分析
- 過(guò)敏性休克的急救及處理流程教材課件(28張)
- 《花婆婆》兒童繪本故事
評(píng)論
0/150
提交評(píng)論