主题:请教各位帮忙
mqese
[专家分:0] 发布于 2006-08-01 13:18:00
原来没有做过应用程序,请大家帮忙。我看有的程序,在登陆以后,登陆界面消失,进入主程序界面,不知道具体是怎么实现的。请各位帮忙给看看,最好给代码看看。谢谢
回复列表 (共8个回复)
沙发
linjian5552000 [专家分:10] 发布于 2006-08-01 13:32:00
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace luntan1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnForm2;
private System.Windows.Forms.Label lbluserName;
private System.Windows.Forms.Label lbluserPwd;
private System.Windows.Forms.TextBox txtuserName;
private System.Windows.Forms.TextBox txtuserPwd;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.Label lblKing;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
板凳
linjian5552000 [专家分:10] 发布于 2006-08-01 13:33:00
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnForm2 = new System.Windows.Forms.Button();
this.lbluserName = new System.Windows.Forms.Label();
this.lbluserPwd = new System.Windows.Forms.Label();
this.txtuserName = new System.Windows.Forms.TextBox();
this.txtuserPwd = new System.Windows.Forms.TextBox();
this.btnClear = new System.Windows.Forms.Button();
this.lblKing = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnForm2
//
this.btnForm2.Location = new System.Drawing.Point(40, 176);
this.btnForm2.Name = "btnForm2";
this.btnForm2.TabIndex = 0;
this.btnForm2.Text = "登陆";
this.btnForm2.Click += new System.EventHandler(this.btnForm2_Click);
3 楼
linjian5552000 [专家分:10] 发布于 2006-08-01 13:33:00
//
// lbluserName
//
this.lbluserName.Location = new System.Drawing.Point(0, 72);
this.lbluserName.Name = "lbluserName";
this.lbluserName.Size = new System.Drawing.Size(96, 23);
this.lbluserName.TabIndex = 1;
this.lbluserName.Text = "用户名:";
this.lbluserName.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// lbluserPwd
//
this.lbluserPwd.Location = new System.Drawing.Point(0, 120);
this.lbluserPwd.Name = "lbluserPwd";
this.lbluserPwd.Size = new System.Drawing.Size(96, 23);
this.lbluserPwd.TabIndex = 2;
this.lbluserPwd.Text = "密 码:";
this.lbluserPwd.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtuserName
//
this.txtuserName.Location = new System.Drawing.Point(120, 72);
this.txtuserName.Name = "txtuserName";
this.txtuserName.TabIndex = 3;
this.txtuserName.Text = "";
//
// txtuserPwd
//
this.txtuserPwd.Location = new System.Drawing.Point(120, 120);
this.txtuserPwd.Name = "txtuserPwd";
this.txtuserPwd.TabIndex = 4;
this.txtuserPwd.Text = "";
//
// btnClear
//
this.btnClear.Location = new System.Drawing.Point(168, 176);
this.btnClear.Name = "btnClear";
this.btnClear.TabIndex = 5;
this.btnClear.Text = "清空";
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// lblKing
//
this.lblKing.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.lblKing.Location = new System.Drawing.Point(72, 8);
this.lblKing.Name = "lblKing";
this.lblKing.Size = new System.Drawing.Size(112, 24);
this.lblKing.TabIndex = 6;
this.lblKing.Text = "我的日记本";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.lblKing);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.txtuserPwd);
this.Controls.Add(this.txtuserName);
this.Controls.Add(this.lbluserPwd);
this.Controls.Add(this.lbluserName);
this.Controls.Add(this.btnForm2);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
4 楼
linjian5552000 [专家分:10] 发布于 2006-08-01 13:33:00
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void btnForm2_Click(object sender, System.EventArgs e)
{
SqlConnection con=new SqlConnection("server=.;database=linjian;uid=sa;pwd=;");
con.Open();
SqlCommand cmd=new SqlCommand("select count(*) from a where userName='"+txtuserName.Text+"' and userPwd='"+txtuserPwd.Text+"'",con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
Form2 f2=new Form2();
f2.Show();
}
else
{
MessageBox.Show("对不起,您不能进入!");
}
}
private void btnClear_Click(object sender, System.EventArgs e)
{
this.txtuserName.Text="" ;
this.txtuserPwd.Text="";
}
}
}
这个是和数据库连接的哦
5 楼
mqese [专家分:0] 发布于 2006-08-01 13:36:00
谢谢。那么form1不用隐藏?
6 楼
linjian5552000 [专家分:10] 发布于 2006-08-01 13:39:00
这样的话 好象要用panel 我着在学着做呢
也不大懂 不好意思
7 楼
mqese [专家分:0] 发布于 2006-08-01 13:55:00
加个qq吧,大家以后共同学习。
我来回复