C#登录界面

作者&投稿:斐厚 (若有异议请与网页底部的电邮联系)
如何用C#做一个登录界面~

真不是几句话就能说清楚的。画个界面你没问题的话就很简单了。如果只是类似,vs里,加个登录窗体,有模板的。很简单了吧。登录验证一楼写清楚了。帮你抄点有用的string strConnection="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(".")+"..user.mdb;";OleDbConnection myConn=new OleDbConnection(strConnection);string userid,pwd;userid=Userid.Text;pwd=Pwd.Text;string mySel="SELECT count(*) as iCount from user where UserID=""+userid+""";OleDbCommand myCmd1=new OleDbCommand(mySel,myConn);if(DrPwd==pwd) {  登录成功打开登录窗体; }  elseMsg.Text="登录密码错.";

asoremaiden 注意查收

Hi,你今年多大了?喜欢编程吗?
我有一个用C#编写的计算器(Windows窗体)的代码
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 计算器
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
// 存储前一个操作数
protected long iNum1;

//存储运算符
protected char cOperator;

//是否开始输入一个新的数字
protected bool bNumBegins;

private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Button button11;
private System.Windows.Forms.Button button0;
private System.Windows.Forms.Button buttonEquals;
private System.Windows.Forms.Button buttonAdd;
private System.Windows.Forms.Button buttonSubstract;
private System.Windows.Forms.Button buttonMultiply;
private System.Windows.Forms.TextBox txtOutput;
private System.Windows.Forms.Button buttonDivide;
public System.Windows.Forms.MainMenu help;
private System.Windows.Forms.MenuItem bangzhu;
private System.Windows.Forms.MenuItem howtouse;
private System.Windows.Forms.MenuItem about;
private System.Windows.Forms.MenuItem look;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

EventHandler eh = new EventHandler(this.Numbers_Click);
button0.Click += eh;
button1.Click += eh;
button2.Click += eh;
button3.Click += eh;
button5.Click += eh;
button6.Click += eh;
button7.Click += eh;
button9.Click += eh;
button10.Click += eh;
button11.Click += eh;

eh = new EventHandler(this.Operators_Click);
buttonAdd.Click += eh;
buttonSubstract.Click += eh;
buttonMultiply.Click += eh;
buttonDivide.Click += eh;
buttonEquals.Click += eh;

InitMembers();

}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

private void InitMembers()
{
iNum1 = 0;

cOperator = '=';

bNumBegins = true;
}

// 当用户按下 0 - 9 这10个键时的情况
private void Numbers_Click(object sender, System.EventArgs e)
{
if(txtOutput.Text == "Error")
{
txtOutput.Text = "0";
}

try
{
// 取得输入
long iCurrent = long.Parse(txtOutput.Text);
long i = long.Parse(((Button)sender).Text);

if(bNumBegins)
{
iCurrent = i;
bNumBegins = false;
}
else
{
// 要求检查运算溢出的情况
checked{iCurrent = (iCurrent * 10) + i;}
}

txtOutput.Text = iCurrent.ToString();
}
catch
{
// 捕捉异常不处理,这样如果用户输入的数字超过界限,
// 程序中显示的数字会保持不变
}

}

// 当用户按下5个运算符时的情况
private void Operators_Click(object sender, System.EventArgs e)
{
char op = ((Button)sender).Text[0];
long iCurrent;

try
{
iCurrent = long.Parse(txtOutput.Text);
}
catch
{
txtOutput.Text = "Error";
InitMembers();
return;
}

// 计算结果
long iResult;

try
{
switch(cOperator)
{
case '+':
checked{iResult = iNum1 + iCurrent;}
break;
case '-':
checked{iResult = iNum1 - iCurrent;}
break;
case '*':
checked{iResult = iNum1 * iCurrent;}
break;
case '/':
checked{iResult = iNum1 / iCurrent;}
break;
default:
iResult = iCurrent;
break;
}
}
catch
{
// 如果在计算中发生溢出,则显示"Error"
// 并重置整个状态
txtOutput.Text = "Error";
InitMembers();
return;
}

// 输出结果,并把当前的结果保存起来
txtOutput.Text = iResult.ToString();
iNum1 = iResult;

//准备接受下一个操作数
bNumBegins = true;

// 保存符号
cOperator = op;
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.txtOutput = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.buttonSubstract = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.button11 = new System.Windows.Forms.Button();
this.buttonMultiply = new System.Windows.Forms.Button();
this.buttonEquals = new System.Windows.Forms.Button();
this.button0 = new System.Windows.Forms.Button();
this.buttonDivide = new System.Windows.Forms.Button();
this.help = new System.Windows.Forms.MainMenu();
this.bangzhu = new System.Windows.Forms.MenuItem();
this.howtouse = new System.Windows.Forms.MenuItem();
this.about = new System.Windows.Forms.MenuItem();
this.look = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// txtOutput
//
this.txtOutput.Location = new System.Drawing.Point(60, 8);
this.txtOutput.MaxLength = 19;
this.txtOutput.Name = "txtOutput";
this.txtOutput.ReadOnly = true;
this.txtOutput.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.txtOutput.Size = new System.Drawing.Size(256, 21);
this.txtOutput.TabIndex = 0;
this.txtOutput.Text = "0";
//
// button1
//
this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button1.Location = new System.Drawing.Point(56, 40);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(48, 48);
this.button1.TabIndex = 1;
this.button1.Text = "1";
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(192)));
this.button2.Location = new System.Drawing.Point(128, 40);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(48, 48);
this.button2.TabIndex = 2;
this.button2.Text = "2";
//
// button3
//
this.button3.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button3.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button3.ForeColor = System.Drawing.Color.Lime;
this.button3.Location = new System.Drawing.Point(200, 40);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(48, 48);
this.button3.TabIndex = 3;
this.button3.Text = "3";
//
// buttonAdd
//
this.buttonAdd.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.buttonAdd.Location = new System.Drawing.Point(272, 40);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(48, 48);
this.buttonAdd.TabIndex = 4;
this.buttonAdd.Text = "+";
//
// button5
//
this.button5.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button5.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(0)));
this.button5.Location = new System.Drawing.Point(56, 96);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(48, 48);
this.button5.TabIndex = 5;
this.button5.Text = "4";
//
// button6
//
this.button6.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button6.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(192)));
this.button6.Location = new System.Drawing.Point(128, 96);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(48, 48);
this.button6.TabIndex = 6;
this.button6.Text = "5";
//
// button7
//
this.button7.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button7.ForeColor = System.Drawing.Color.Green;
this.button7.Location = new System.Drawing.Point(200, 96);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(48, 48);
this.button7.TabIndex = 7;
this.button7.Text = "6";
//
// buttonSubstract
//
this.buttonSubstract.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.buttonSubstract.Location = new System.Drawing.Point(272, 96);
this.buttonSubstract.Name = "buttonSubstract";
this.buttonSubstract.Size = new System.Drawing.Size(48, 48);
this.buttonSubstract.TabIndex = 8;
this.buttonSubstract.Text = "-";
//
// button9
//
this.button9.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button9.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(64)), ((System.Byte)(0)));
this.button9.Location = new System.Drawing.Point(56, 152);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(48, 48);
this.button9.TabIndex = 9;
this.button9.Text = "7";
//
// button10
//
this.button10.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button10.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button10.ForeColor = System.Drawing.Color.Purple;
this.button10.Location = new System.Drawing.Point(128, 152);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(48, 48);
this.button10.TabIndex = 10;
this.button10.Text = "8";
//
// button11
//
this.button11.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button11.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button11.ForeColor = System.Drawing.Color.Blue;
this.button11.Location = new System.Drawing.Point(200, 152);
this.button11.Name = "button11";
this.button11.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.button11.Size = new System.Drawing.Size(48, 48);
this.button11.TabIndex = 11;
this.button11.Text = "9";
//
// buttonMultiply
//
this.buttonMultiply.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.buttonMultiply.Location = new System.Drawing.Point(272, 152);
this.buttonMultiply.Name = "buttonMultiply";
this.buttonMultiply.Size = new System.Drawing.Size(48, 48);
this.buttonMultiply.TabIndex = 12;
this.buttonMultiply.Text = "*";
//
// buttonEquals
//
this.buttonEquals.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.buttonEquals.Location = new System.Drawing.Point(136, 224);
this.buttonEquals.Name = "buttonEquals";
this.buttonEquals.Size = new System.Drawing.Size(104, 32);
this.buttonEquals.TabIndex = 13;
this.buttonEquals.Text = "=";
//
// button0
//
this.button0.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button0.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button0.ForeColor = System.Drawing.SystemColors.MenuText;
this.button0.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.button0.Location = new System.Drawing.Point(56, 208);
this.button0.Name = "button0";
this.button0.Size = new System.Drawing.Size(48, 48);
this.button0.TabIndex = 14;
this.button0.Text = "0";
//
// buttonDivide
//
this.buttonDivide.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.buttonDivide.Location = new System.Drawing.Point(272, 208);
this.buttonDivide.Name = "buttonDivide";
this.buttonDivide.Size = new System.Drawing.Size(48, 48);
this.buttonDivide.TabIndex = 15;
this.buttonDivide.Text = "/";
//
// help
//
this.help.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.bangzhu});
//
// bangzhu
//
this.bangzhu.Index = 0;
this.bangzhu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.howtouse,
this.about,
this.look});
this.bangzhu.Text = "帮助";
//
// howtouse
//
this.howtouse.Index = 0;
this.howtouse.Text = "如何使用";
//
// about
//
this.about.Index = 1;
this.about.Text = "关于作者";
//
// look
//
this.look.Index = 2;
this.look.Text = "查看源代码";
//
// Form1
//
this.AllowDrop = true;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.AutoScroll = true;
this.AutoScrollMargin = new System.Drawing.Size(1, 1);
this.AutoScrollMinSize = new System.Drawing.Size(2, 2);
this.BackColor = System.Drawing.Color.Gainsboro;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(376, 310);
this.Controls.Add(this.buttonDivide);
this.Controls.Add(this.button0);
this.Controls.Add(this.buttonEquals);
this.Controls.Add(this.buttonMultiply);
this.Controls.Add(this.button11);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.buttonSubstract);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtOutput);
this.Cursor = System.Windows.Forms.Cursors.Arrow;
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.HelpButton = true;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.ImeMode = System.Windows.Forms.ImeMode.On;
this.KeyPreview = true;
this.MaximizeBox = false;
this.Menu = this.help;
this.Name = "Form1";
this.Opacity = 0.9;
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "计算器HappyZhe1.0";
this.TopMost = true;
this.TransparencyKey = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Load += new System.EventHandler(this.HappyZhe_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void HappyZhe_Load(object sender, System.EventArgs e)
{

}

private void button4_Click(object sender, System.EventArgs e)
{

}

}
}

我也是刚上路的,几乎对编程没什么了解,希望有人可以和我一起学习研究,我可以加你的QQ吗?

有兴趣的话,可以先来我的空间看看
http://hi.baidu.com/tobehappy
你可以先给我留言,希望能找到知己!

这个不用自己写代码哦,用.NET里面的控件拉一下就可以实现,稍微编写一点点后台的代码就可以了~

晕死,这个刚学C#就会的东西哦,不过帖代码真的不好帖啊,呵呵

这个学期刚学的C#,呵呵

设置下界面,自己动手写一点即可了。


北宁市15375291356: 如何使用c#制作登录界面 -
况尚甲磺: 打开Microsoft Visual Studio 2010软件,然后选择【新建项目】会弹出一个新建项目类型模块,在此模块中选择“Windows 窗体应用程序”,接着在【名称】文本框中将项目名改为自己方便记忆的名称,例如:demo.最后单击【确定】按钮即...

北宁市15375291356: C#登录界面怎么做 /C#如何从登录界面进入主界面 -
况尚甲磺: 通常的作法是这样的: 桌面应用程序启动后,首先会显示一个等待界面,用来提示用户加载数据准备环境 加载完毕后,通常是登录界面,用户输入凭证,系统验证通过后,系统显示出主界面一般设计这样的流程,都要有一个总的控制器或协调器,它知道用户当前所处在什么状态下,楼主要问的,如何从主界面加到登录界面,那就是一般所说的“安全退出”或“注销”或“更改登录”之类功能,这时就要控制器将主界面隐藏,将登录界面显示出来.

北宁市15375291356: 如何用C#做一个登录界面 -
况尚甲磺: 用窗体程序,装一个VS2005或以上版本,创建项目,选C#,之后选WINDOWS应用程序

北宁市15375291356: 如何用C#语言设计一个登陆界面,要求登录名和密码一样就可以登陆 -
况尚甲磺: <img src="https://pic.wenwen.soso.com/pqpic/wenwenpic/0/20200321041923-1245627519_jpeg_468_281_16342/0"/><br><br>然后在登陆的按钮方法里面写<br> protected void Button1_Click(object sender, EventArgs e)<br> {<br> if(txtLogin....

北宁市15375291356: c#登陆界面代码 -
况尚甲磺: myd.Fill(ds);//这个地方加判断语句//如 if ( DataSet.Tables[0].Rows.Count>0) { MessageBox.Show("登陆成功"); vip.yhm = textBox1.Text; Form2 a = new Form2(); a.Show(); }//代码仅供参考

北宁市15375291356: c#登录界面代码 -
况尚甲磺: private void button1_Click(object sender, EventArgs e) { string sqlstring = "database=students_info;Trusted_Connection=yes;"; SqlConnection a = new SqlConnection(sqlstring); a.Open(); SqlCommand b = new SqlCommand("select * from [...

北宁市15375291356: c#登录窗口制作 -
况尚甲磺: 窗体之间的值传递!登录窗口Form1 textBox1 为登录的用户名输入 private void button1_Click(object sender, EventArgs e) { Form2 fm2=new Form2(textBox1.text) fm2.show(); } 主窗体Form2 label1为主窗体显示登录的用户名 构造函数 Pubilc void Form2(string Name) { label1.text=Name; }

北宁市15375291356: 怎样用c#asp.net做一个登陆界面 -
况尚甲磺: if (z.Exists(TextBox1.Text.ToString(), TextBox2.Text.ToString())) //如果帐号和密码正确 { //登录成功并跳转到管理页面 Response.Redirect("Admin/newsadmin.aspx"); }////// 是否存在该记录 ///public bool Exists(string name, string passwd...

北宁市15375291356: 如何用C#做一个登录界面要求添加控件 -
况尚甲磺: 你做的windowsform就很简单啊,有一个工具箱 把控件 拖动出来就可以了.做一个登陆界面就2个lable和2个textBox 和一个或者两个 按钮 登陆(button) 重置(button)

北宁市15375291356: c#做一个简单的登陆,注册界面,请问具体步骤 -
况尚甲磺: 假若form1为登录注册窗体,点击注册后,treenode窗体show,注册完成后,treenode窗体close.

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网