[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
1.打开Microsoft Visual Studio新建C#窗体应用程序,命名为login
2.修改窗体的Text属性,添加控件Label、TextEdit(ps:注意设置Name属性以及位置的调整),然后添加控件SimpleButton(ps:控件前的图片通过Image属性设置),效果如下:
3.在项目中添加类,命名为DemoCls,代码如下:
using System; using System.Collections.Generic; using System.Linq; using
System.Text;using System.Threading.Tasks; namespace login { class DemoCls {
public string sqlSelect() { return "OK"; } } }
4.添加按钮确定的点击事件,添加用户和密码TextEdit的KeyDown事件,代码如下(ps:数据库根据自己的本地数据库进行设置):
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 login {public partial class Form1 : Form {
public Form1() { InitializeComponent(); } private void btnOK_Click(object
sender, EventArgs e) {string conn = "server=.;database=数据库名字;user id =
用户名;password=密码"; SqlConnection con = new SqlConnection(conn); con.Open();
SqlDataAdapter sqlDa =new SqlDataAdapter("select * from tb_stu", con);
DataTable dt =new DataTable(); sqlDa.Fill(dt); MessageBox.Show(dt.Rows[0][1
].ToString());//调用类DemoCls中的sqlSelect方法 DemoCls my1 = new DemoCls();
MessageBox.Show(my1.sqlSelect()); }//当用户第一个文本框输入信息完毕时按下Enter键自动聚焦到密码输入框 private
void txtUser_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode ==
Keys.Enter) { txtPWD.Focus(); } }//当用户第二个文本框输入信息完毕按下Enter键相当于click确认按钮 private
void txtPWD_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode ==
Keys.Enter) { btnOK_Click(sender,null); } } } }