C#入门代码,csharp

C#入门代码,csharp
C#入门代码,csharp

一、从控制台读取东西代码片断:

using System;

class TestReadConsole

{

public static void Main()

{

Console.Write(Enter your name:);

string strName = Console.ReadLine();

Console.WriteLine( Hi + strName);

}

}

二、读文件代码片断:

using System;

using System.IO;

public class TestReadFile

{

public static void Main(String[] args)

{

// Read text file C:\temp\test.txt

FileStream fs = new FileStream(@c:\temp\test.txt , FileMode.Open, FileAccess.Read);

StreamReader sr = new StreamReader(fs);

String line=sr.ReadLine();

while (line!=null)

{

Console.WriteLine(line);

line=sr.ReadLine();

}

sr.Close();

fs.Close();

}

}

三、写文件代码:

using System;

using System.IO;

public class TestWriteFile

{

public static void Main(String[] args)

{

// Create a text file C:\temp\test.txt

FileStream fs = new FileStream(@c:\temp\test.txt , FileMode.OpenOrCreate, FileAccess.Write);

StreamWriter sw = new StreamWriter(fs);

// Write to the file using StreamWriter class

sw.BaseStream.Seek(0, SeekOrigin.End);

sw.WriteLine( First Line );

sw.WriteLine( Second Line);

sw.Flush();

}

}

四、拷贝文件:

using System;

using System.IO;

class TestCopyFile

{

public static void Main()

{

File.Copy(c:\\temp\\source.txt, C:\\temp\\dest.txt );

}

}

五、移动文件:

using System;

using System.IO;

class TestMoveFile

{

public static void Main()

{

File.Move(c:\\temp\\abc.txt, C:\\temp\\def.txt );

}

}

六、使用计时器:

using System;

using System.Timers;

class TestTimer

{

public static void Main()

{

Timer timer = new Timer();

timer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent ); timer.Interval = 1000;

timer.Start();

timer.Enabled = true;

while ( Console.Read() != 'q' )

{

//-------------

}

}

public static void DisplayTimeEvent( object source, ElapsedEventArgs e )

{

Console.Write(\r{0}, DateTime.Now);

}

}

七、调用外部程序:

class Test

{

static void Main(string[] args)

{

System.Diagnostics.Process.Start(notepad.exe);

}

}

https://www.360docs.net/doc/7317467181.html,方面的:

八、连接Access数据库:

using System;

using System.Data;

using System.Data.OleDb;

class TestADO

{

static void Main(string[] args)

{

string strDSN = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\test.mdb;

string strSQL = SELECT * FROM employees ;

OleDbConnection conn = new OleDbConnection(strDSN); OleDbCommand cmd = new OleDbCommand( strSQL, conn ); OleDbDataReader reader = null;

try

{

conn.Open();

reader = cmd.ExecuteReader();

while (reader.Read() )

{

Console.WriteLine(First Name:{0}, Last Name:{1}, reader[FirstName], reader[LastName]);

}

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

finally

{

conn.Close();

}

}

}

九、连接SQL Server数据库:

using System;

using System.Data.SqlClient;

public class TestADO

{

public static void Main()

{

SqlConnection conn = new SqlConnection(Data Source=localhost; Integrated Security=SSPI; Initial Catalog=pubs);

SqlCommand cmd = new SqlCommand(SELECT * FROM employees, conn);

try

{

conn.Open();

SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read())

{

Console.WriteLine(First Name: {0}, Last Name: {1}, reader.GetString(0), reader.GetString(1));

}

reader.Close();

conn.Close();

}

catch(Exception e)

{

Console.WriteLine(Exception Occured -->> {0},e);

}

}

}

十、从SQL内读数据到XML:

using System;

using System.Data;

using System.Xml;

using System.Data.SqlClient;

using System.IO;

public class TestWriteXML

{

public static void Main()

{

String strFileName=c:/temp/output.xml;

SqlConnection conn = new

SqlConnection(server=localhost;uid=sa;pwd=;database=db);

String strSql = SELECT FirstName, LastName FROM employees; SqlDataAdapter adapter = new SqlDataAdapter();

adapter.SelectCommand = new SqlCommand(strSql,conn);

// Build the DataSet

DataSet ds = new DataSet();

adapter.Fill(ds, employees);

// Get a FileStream object

FileStream fs = new

FileStream(strFileName,FileMode.OpenOrCreate,FileAccess.Write);

// Apply the WriteXml method to write an XML document

ds.WriteXml(fs);

fs.Close();

}

}

十一、用ADO添加数据到数据库中:

using System;

using System.Data;

using System.Data.OleDb;

class TestADO

{

static void Main(string[] args)

{

string strDSN =

Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\test.mdb;

string strSQL = INSERT INTO Employee(FirstName, LastName) VALUES('FirstName', 'LastName') ;

// create Objects of ADOConnection and ADOCommand

OleDbConnection conn = new OleDbConnection(strDSN);

OleDbCommand cmd = new OleDbCommand( strSQL, conn );

try

{

conn.Open();

cmd.ExecuteNonQuery();

}

catch (Exception e)

{

Console.WriteLine(Oooops. I did it again:\n{0},

e.Message);

}

finally

{

conn.Close();

}

}

}

十二、使用OLEConn连接数据库:

using System;

using System.Data;

using System.Data.OleDb;

class TestADO

{

static void Main(string[] args)

{

string strDSN =

Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\test.mdb;

string strSQL = SELECT * FROM employee ;

OleDbConnection conn = new OleDbConnection(strDSN);

OleDbDataAdapter cmd = new OleDbDataAdapter( strSQL, conn );

conn.Open();

DataSet ds = new DataSet();

cmd.Fill( ds, employee );

DataTable dt = ds.Tables[0];

foreach( DataRow dr in dt.Rows )

{

Console.WriteLine(First name: + dr[FirstName].ToString() + Last name: + dr[LastName].ToString());

}

conn.Close();

}

}

十三、读取表的属性:

using System;

using System.Data;

using System.Data.OleDb;

class TestADO

{

static void Main(string[] args)

{

string strDSN =

Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\test.mdb;

string strSQL = SELECT * FROM employee ;

OleDbConnection conn = new OleDbConnection(strDSN);

OleDbDataAdapter cmd = new OleDbDataAdapter( strSQL, conn );

conn.Open();

DataSet ds = new DataSet();

cmd.Fill( ds, employee );

DataTable dt = ds.Tables[0];

Console.WriteLine(Field Name DataType Unique AutoIncrement AllowNull);

Console.WriteLine(=========================================== =======================);

foreach( DataColumn dc in dt.Columns )

{

Console.WriteLine(dc.ColumnName+ , +dc.DataType

+ ,+dc.Unique + ,+dc.AutoIncrement+ ,+dc.AllowDBNull );

}

conn.Close();

}

}

https://www.360docs.net/doc/7317467181.html,方面的

十四、一个https://www.360docs.net/doc/7317467181.html,程序:

<%@ Page Language=C# %>


Enter your name:

runat=server>

Width=247px>

WinForm开发:

十五、一个简单的WinForm程序:

using System;

using System.Drawing;

using System.Collections;

using https://www.360docs.net/doc/7317467181.html,ponentModel;

using System.Windows.Forms;

using System.Data;

public class SimpleForm : System.Windows.Forms.Form

{

private https://www.360docs.net/doc/7317467181.html,ponentModel.Container components = null; private System.Windows.Forms.Button button1;

private System.Windows.Forms.TextBox textBox1;

public SimpleForm()

{

InitializeComponent();

}

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

private void InitializeComponent()

{

https://www.360docs.net/doc/7317467181.html,ponents = new https://www.360docs.net/doc/7317467181.html,ponentModel.Container(); this.Size = new System.Drawing.Size(300,300);

this.Text = Form1;

this.button1 = new System.Windows.Forms.Button();

this.textBox1 = new System.Windows.Forms.TextBox();

this.SuspendLayout();

//

// button1

//

this.button1.Location = new System.Drawing.Point(8, 16);

https://www.360docs.net/doc/7317467181.html, = button1;

this.button1.Size = new System.Drawing.Size(80, 24);

this.button1.TabIndex = 0;

this.button1.Text = button1;

//

// textBox1

//

this.textBox1.Location = new System.Drawing.Point(112, 16);

https://www.360docs.net/doc/7317467181.html, = textBox1;

this.textBox1.Size = new System.Drawing.Size(160, 20);

this.textBox1.TabIndex = 1;

this.textBox1.Text = textBox1;

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 273);

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.textBox1,

this.button1});

https://www.360docs.net/doc/7317467181.html, = Form1;

this.Text = Form1;

this.ResumeLayout(false);

}

#endregion

[STAThread]

static void Main()

{

Application.Run(new SimpleForm());

}

}

十六、运行时显示自己定义的图标:

//load icon and set to form

System.Drawing.Icon ico = new System.Drawing.Icon(@c:\temp\app.ico); this.Icon = ico;

十七、添加组件到ListBox中:

private void Form1_Load(object sender, System.EventArgs e)

{

string str = First item;

int i = 23;

float flt = 34.98f;

listBox1.Items.Add(str);

listBox1.Items.Add(i.ToString());

listBox1.Items.Add(flt.ToString());

listBox1.Items.Add(Last Item in the List Box);

}

网络方面的:

十八、取得IP地址:

using System;

using https://www.360docs.net/doc/7317467181.html,;

class GetIP

{

public static void Main()

{

IPHostEntry ipEntry = Dns.GetHostByName (localhost);

IPAddress [] IpAddr = ipEntry.AddressList;

for (int i = 0; i < IpAddr.Length; i++)

{

Console.WriteLine (IP Address {0}: {1} , i,

IpAddr.ToString ());

}

}

}

十九、取得机器名称:

using System;

using https://www.360docs.net/doc/7317467181.html,;

class GetIP

{

public static void Main()

{

Console.WriteLine (Host name : {0}, Dns.GetHostName()); }

}

二十、发送邮件:

using System;

using System.Web;

using System.Web.Mail;

public class TestSendMail

{

public static void Main()

{

try

{

// Construct a new mail message

MailMessage message = new MailMessage();

message.From = from@https://www.360docs.net/doc/7317467181.html,;

message.To = pengyun@https://www.360docs.net/doc/7317467181.html,;

https://www.360docs.net/doc/7317467181.html, = ;

message.Bcc = ;

message.Subject = Subject;

message.Body = Content of message;

//if you want attach file with this mail, add the line below

message.Attachments.Add(new MailAttachment(c:\\attach.txt, MailEncoding.Base64));

// Send the message

SmtpMail.Send(message);

System.Console.WriteLine(Message has been sent);

}

catch(Exception ex)

{

System.Console.WriteLine(ex.Message.ToString());

}

}

}

二十一、根据IP地址得出机器名称:

using System;

using https://www.360docs.net/doc/7317467181.html,;

class ResolveIP

{

public static void Main()

{

IPHostEntry ipEntry = Dns.Resolve(172.29.9.9);

Console.WriteLine (Host name : {0},

ipEntry.HostName);

}

}

GDI+方面的:

二十二、GDI+入门介绍:

using System;

using System.Drawing;

using System.Collections;

using https://www.360docs.net/doc/7317467181.html,ponentModel;

using System.Windows.Forms;

using System.Data;

public class Form1 : System.Windows.Forms.Form

{

private https://www.360docs.net/doc/7317467181.html,ponentModel.Container components = null;

public Form1()

{

InitializeComponent();

}

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

private void InitializeComponent()

{

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273);

https://www.360docs.net/doc/7317467181.html, = Form1;

this.Text = Form1;

this.Paint += new

System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

}

#endregion

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

private void Form1_Paint(object sender,

System.Windows.Forms.PaintEventArgs e)

{

Graphics g=e.Graphics;

g.DrawLine(new Pen(Color.Blue),10,10,210,110);

g.DrawRectangle(new Pen(Color.Red),10,10,200,100);

g.DrawEllipse(new Pen(Color.Yellow),10,150,200,100);

}

}

XML方面的:

二十三、读取XML文件:

using System;

using System.Xml;

class TestReadXML

{

public static void Main()

{

XmlTextReader reader = new XmlTextReader(C:\\test.xml); reader.Read();

while (reader.Read())

{

reader.MoveToElement();

Console.WriteLine(XmlTextReader Properties Test);

Console.WriteLine(===================);

// Read this properties of element and display them on console

Console.WriteLine(Name: + https://www.360docs.net/doc/7317467181.html,);

Console.WriteLine(Base URI: + reader.BaseURI);

Console.WriteLine(Local Name: + reader.LocalName);

Console.WriteLine(Attribute Count: +

reader.AttributeCount.ToString());

Console.WriteLine(Depth: + reader.Depth.ToString()); Console.WriteLine(Line Number: +

reader.LineNumber.ToString());

Console.WriteLine(Node Type: +

reader.NodeType.ToString());

Console.WriteLine(Attribute Count: +

reader.Value.ToString());

}

}

}

二十四、写XML文件:

using System;

using System.Xml;

public class TestWriteXMLFile

{

public static int Main(string[] args)

{

try

{

// Creates an XML file is not exist

XmlTextWriter writer = new

XmlTextWriter(C:\\temp\\xmltest.xml, null);

// Starts a new document

writer.WriteStartDocument();

//Write comments

writer.WriteComment(Commentss: XmlWriter Test Program); writer.WriteProcessingInstruction(Instruction,Person Record);

// Add elements to the file

writer.WriteStartElement(p, person, urn:person);

writer.WriteStartElement(LastName,);

writer.WriteString(Chand);

writer.WriteEndElement();

writer.WriteStartElement(FirstName,);

writer.WriteString(Mahesh);

writer.WriteEndElement();

writer.WriteElementInt16(age,, 25);

// Ends the document

writer.WriteEndDocument();

}

catch (Exception e)

{

Console.WriteLine (Exception: {0}, e.ToString());

}

return 0;

}

}

Web Service方面的:

二十五、一个Web Service的小例子:

<% @WebService Language=C# Class=TestWS %>

using System.Web.Services;

public class TestWS : System.Web.Services.WebService

{

[WebMethod()]

public string StringFromWebService()

{

return This is a string from web service.; }

}

VB登录界面代码

VB登录界面代码 方法一: VB登录界面代码 Option Explicit Private Sub cmdCancel_Click() Dim intResult As Integer '请求用户确认是否真的退出系统登录 intResult = MsgBox("你选择了退出系统登录,退出将不能启动企业人事管理系统!" & vbcrlf_ & "是否真的退出?", vbYesNo, "登录验证") If intResult = vbYes Then End '根据用户选择结束应用程序 End Sub Private Sub CmdOK_Click() Dim UserName As String Dim userpassword As String Dim str As String Dim nTryCount As Integer Dim rs As New ADODB.Recordset Set rs = New ADODB.Recordset UserName = Trim(txtUserName.Text) userpassword = Trim(txtpassword.Text) str = "select * from 用户信息表where 用户名='" & UserName & "' and 用户密码= '" & userpassword & " '" rs.Open str, connectString, adOpenKeyset, 2 If rs.EOF Then '登录失败 MsgBox "对不起,无此用户或者密码不正确!请重新输入!!", vbCritical, "错误" txtUserName.Text = "" txtpassword.Text = "" txtUserName.SetFocus nTryCount = nTryCount + 1

登录界面代码

在https://www.360docs.net/doc/7317467181.html,平台下用C#和Access实现用户登录界面的窗体应用程序 一直就想加个technology的类别,但却迟迟未能动笔.一来不得不承认直到现在,我在技术上还依然只是一个没怎么入门的菜鸟,二来技术本身也不是我的兴趣所在.但不管怎样,既然我现在还要攻读计算机专业的硕士学位,那么技术,总还是要学的. 需要说明的是,对于那些高手来说,这里的东西想必都是小菜一碟,不值一提.我写在这里,只是给自己的总结吧.另外我所写的东西,很多也是参考网络和书籍的,其实真正属于我自己的东西也不多.由于四处查找,具体的出处很多也已记不清了,而且在开源环境下也很难说某些代码就是谁的原创,所以这里虽然没有说明,但很多东西也都是参考他人的,在此先要对那些给了我帮助的书籍作者,网上的发贴人和回贴人表示感谢. 去年研一刚开学时,自己的实践能力还几乎为零.因为我心里清楚,自己本科的确是混过来的,计算机科学与技术的学士学位,我其实是不配去拿的.九月十号进实验室后,开始学习项目组里需要用到的C#,但单纯学习语言也没什么明确的目的性.实验室里和我同一导师本校保研的同学和我说起,他们大四下学期刚进实验室时,师兄就让他们先试着写一个类似QQ登录那样的一个用户登录程序.我自己没有任何经验,想也就像他们一样,从这里起步吧,于是在看C#的同时我就考虑怎么样去实现这样一个程序了. 我知道对于过来人来说,这样的一个程序实在是再简单不过了,但对于当时刚开始的我,着实费尽了不少周折.虽然后来基本实现了这样一个程序,但在数据库上还是有些问题.因此虽然当时也曾想过贴个technology类别的日志,但终究还是一直拖了下来. 前段时间通过同学的介绍,帮沈阳日报的一个朋友做了一个会员管理的软件.软件本身也极其简单,基本没有太多的技术含量,但在开发的过程中自己通过各种渠道去查找资料,也在各方面都学到了很多.所以这段经历对我还是很有意义的.而且自己在计算机专业学了四年有半后终于可以自己做出来一些可以应用到实际中的东西,也终于凭借自己的专业能力获得了一点回报,无论回报是多是少.嗯,是要鼓励一下自己的.也激励自己再接再厉! 此后我可能会把在这一软件中所学到的东西陆续总结一下到这里.而这一软件开发的第一个模块也就是用户登录模块.也就是我最初在尝试做的东西.好,说了这么多无关的话,现在言归正传,来看登录模块的具体实现. 由于用户登录模块的实现关键的一点就是要将用户的信息存储在数据库中,并在用户登录时到数据库中对信息进行查找和核对,所以首先要先建立一个数据库.实际上对于初学者来说,数据库的相关操作也正是实现本登录模块的难点所在.这也是当时我刚开始写这段程序时困扰我并困扰了我很久的地方.在数据量不是很大的情况下,可以就用微软Office组件里的Access数据库,比较方便.这里在D盘用Access建立一个数据库命名为db.mdb,并在数据库中建一个表,命名为users ,在表中建两个字段,命名为userName和userPassword,分别存储用户名和密码.然后在表中插入几条数据,用于登录界面的测试.下面是登录模块的开发. 在Visual Studio2005的C#开发环境下,新建一个Windows 应用程序的项目,将第一个窗体命名为Login,即作为用户登录窗体.在窗体上添加相应控件,设计效果如下:

登录界面代码(vs)

https://www.360docs.net/doc/7317467181.html,入门篇【项目实战】打造一个自己的相册(二)登录模块 2009年11月15日星期日 12:05 本文原创,转载请说明,本文地址: https://www.360docs.net/doc/7317467181.html,/44498/blog/item/59db5da17d24c28146106478.html 进行本次项目实战,需要有一定的C#基础知识,所以,在初期的几篇里面,我在文中尽可能的多贴图以进行示例,以后逐渐减少图片说明。 昨天已经介绍了流程和基本功能,今天简单的介绍一下用户登录模块的做法。 不要担心,非常简单。 打开Login.aspx页面,这是我们昨天设计的空白页面,用户登录,现在,我们来完善它的外观和功能。 简单的登录需要一个账号输入框,一个密码输入框,以及一个提交按钮;如图所示: 当然,喜欢用https://www.360docs.net/doc/7317467181.html,的标准控件库也行,喜欢用HTML组的控件也可以。 在输入密码的时候,都是以"*"号密文显示的,那么我们要调整一下密码框的属性,指定其类型是password类型。如图:

界面设计完毕,是个什么样子呢?大概的看一下吧,还算说得过去。 【如果要更好看,当然需要美工人员的帮助】 然后,该实现登录的功能了吧? 先谈谈我们的目标,也就是输入账号和密码以后,如果通过验证,则跳转到Default.aspx页面,提示登录成功,反之,则给予相应的提示。 账号和密码保存在哪里呢?当然是数据库里。 好,我们来创建一个数据库吧。【我这里使用的是SQL SERVER 2005,当然,你用其他的也行】 打开红圈选中的 SQL Server Management Studio ,其实也就等同于SQL SERVER

用户登陆界面程序vb设计说明书

工程学院 课程设计说明书 课程名称: 计算机应用基础课程设计 课程代码: 题目: 用户登录界面程序设计 年级/专业/班: 学生姓名: 学号: 开始时间: 2011 年 4 月25 日 完成时间: 2011 年 5 月 8 日 课程设计成绩: 指导教师签名:年月日 目录 摘要 (2) 1 引言 (3)

2 设计方案 (4) 2.1程序功能设计 (4) 2.1.1系功能描述 (5) 2.1.2系结构分析 (5) 2.1.3系统流程分析 (5) 2.2程序界面和代码设计 (7) 2.2.1系统工程设计框架 (7) 2.2.2系统各界面设计及代码设计 (7) 3 结果分析 (11) 结论 (14) 致谢 (15) 参考文献 (16)

摘要 随着计算机的普及,计算机高级语言已经运用到生活中的各个方面,本次课程设计使用VB语言作为开发工具,进行了用户登录系统的程序设计,该程序能实现用户登录系统的模拟功能,进行用户的登录,提醒,注册,退出等操作,这些操作都能模拟实际生活中的登录情况,最后分析所开发软件系统的优点和不足。该运行界面清晰实用,操作方便。 关键词:用户登录模拟操作界面

1 引言 随着科学技术的发展,计算机已经应用到生活、工作的各个方面。VB一种可视化的、面向对象和采用事件驱动方式的高级程序设计语言,可用于开发Windows环境下的各类应用程序。本次课程设计主要内容就是使用VB编制简单、实用的小程序,以巩固我们所学的计算机VB语言知识,提高分析问题和解决问题的能力,锻炼我们独立动手的能力以及综合创新能力。 1.1 选题背景 通过一个学期对Visual Basic 高级语言程序设计的学习,我已经掌握了一些常用的控件的使用方法,对简单的程序设计的常用算法也有了一定的了解,还掌握了对文件输入与输出的一些基本操作。为了进一步加深理解、验证、巩固课堂教学内容,加深对可视化编程思想的理解,强化Visual Basic对程序流程控制、常用控件的属性、事件、方法的理解和使用;为了进一步提高编程能力、程序的调试能力,理论联系实际的能力;巩固所学的这些程序设计的方法,为了达到后续课程对实际编程计算能力的要求,特选定“用户登录界面程序设计”题目作为课程设计实践教学环节的题目,有助于培养综合运用所学知识解决实际问题的能力,可以充分发挥想象力和创新能力;有助于提高独立思考能力,自学能力 1.2任务与分析 任务:设计一用户的登录窗口界面,实现模拟用户登录系统时的各种情况 具体要求:遵循面向对象和结构化程序设计的编程思路,设计合理的界面,设置所需控件及其属性,编写相应的事件过程,并上机调试程序,在基本要求达到后,进行一定创新设计 预期功能:实现用户成功登录系统,当用户明不正确或者密码错误时,提醒用户重新输入或者注册,当三次登录失败时,强制性退出操作界面。 涉及的VB知识点:界面设计,command控件、text控件及其属性,随机的读出于追加。

(完整版)JSP登陆页面代码

静态的登录界面的设计login.htm,代码如下: Html代码 1. 2. 3. 系统登录 4. 14. 15. 16.

17. 18. 19. 20. 22. 23. 24. 25.
26. 27.
28.
29.
33. 34. 35. 36. 37.
系统登录 21.
用户名
密  码
30.    31. 32.
38.

Android登录界面(步骤详细)

Android简单登录界面 设计一个登陆界面: 允许用户输入用户名,密码; 用户点击“Login”之后,如果用户名为admin, 密码为123则显示“登陆成功”;如果用户名密码其中之一不正确,红色字体显示“登陆失败!” 首先我们来建立一个新的项目:

图标那一步就随便选吧,下一步: 这一步与上次有点不同,这次我们不要ADT 帮我们创建任何的Activity,我们只需要一个空的项目。 点击Finish后,我们会发现,项目文件视图下,与上次的不一样,src, res/layout 是空的,这次需要我们自己去添加了。 首先来明确一下我们现在的目标: 建立一个包含登录框的界面,并将它显示在我们的手机(模拟器)上。 建立一个界面的主要步骤是什么呢?主要有以下几步: ?在res/layout下创建布局文件; ?在src下创建Activity子类,并将布局文件与这个Activity联系起来。 ?在AndroidManifest.xml程序配置文件中,添加Activity的声明。 我们先来 1. 创建布局文件: 在Eclipse项目文件中选中layout 文件夹,在工具栏里点击下面图标 在弹出的窗口,填上这个xml布局文件的文件名,Root Element 根节点就选择Linearlayout 即可

点击下一步,这一步是选择更多配置属性的,暂且不用理会,直接点击Finish。 我们发现,在res/layout 下面多了一个login.xml文件,同时Android 的Layout 编辑器也把它打开了。 切换到“source”代码视图,今天我们不用“所见即所得”的傻瓜拖拽方式。 我们看到xml代码是这样的: 根节点是LinearLayout,即线性布局,所谓线性布局,有点像J2SE上的流式布局,就是其中的UI元素,会按水平或者垂直方向顺序地铺开。 LinearLayout有个xml属性:android:orientation,它有两个可选值:vertical和horizontal,指明该线性布局中的元素,是以垂直(vertical)还是水平(horizontal)方向排列。

php用户登录页面代码源代码

//登入页面 $conn=mysql_connect('127.0.0.1','root','')or die("连接失败"); mysql_select_db('tujian',$conn)or die("未找到该数据库"); define(ALL_PS,"vivid");mysql_query("set names GBK"); if($_POST[submit]){ $postcode=strtolower($_POST["code"]); $postcode=strtoupper($_POST["code"]); $uid=str_replace(" ","",$_POST[uid]); $sql="select * from users where `uid`='$_POST[uid]'"; $query=mysql_query($sql); $user=is_array($row=mysql_fetch_array($query)); $mi=$user?md5($_POST[pass].ALL_PS)==$row[pass]:FALSE; if($mi){ $_SESSION[uid]=$row[uid]; $_SESSION[name]=$row[name]; $_SESSION[id]=$row[id]; $_SESSION[user_shell]=md5($row[uid].$row[pass].ALL_PS); if( $_SESSION["code"]==$postcode){ echo""; }else{ echo"

验证码输入错误,请重新输入!
"; } } else{ echo"
用户名或密码输入错误
"; session_destroy(); } } ?> ") Response.end End If if Instr(UserName,">")>0 or Instr(UserName,"<")>0 or Instr(UserName,"=")>0 or Instr(UserName,"%")>0 or Instr(UserName,chr(32))>0 or Instr(UserName,"?")>0 or Instr(UserName,"&")>0 or Instr(UserName,";")>0 or Instr(UserName,",")>0 or Instr(UserName,"'")>0 or

[最新]vb登录界面代码

[最新]vb登录界面代码 VB登录界面代码 方法一: VB登录界面代码 Option Explicit Private Sub cmdCancel_Click() Dim intResult As Integer '请求用户确认是否真的退出系统登录 intResult = MsgBox("你选择了退出系统登录,退出将不能启动企业人事管理系统~" & vbcrlf_ & "是否真的退出,", vbYesNo, "登录验证") If intResult = vbYes Then End '根据用户选择结束应用程序 End Sub Private Sub CmdOK_Click() Dim UserName As String Dim userpassword As String Dim str As String Dim nTryCount As Integer Dim rs As New ADODB.Recordset Set rs = New ADODB.Recordset UserName = Trim(txtUserName.Text) userpassword = Trim(txtpassword.Text) str = "select * from 用户信息表 where 用户名='" & UserName & "' and 用户密码 = '" & userpassword & " '" rs.Open str, connectString, adOpenKeyset, 2 If rs.EOF Then '登录失败 MsgBox "对不起,无此用户或者密码不正确~请重新输入~~", vbCritical, "错误" txtUserName.Text = "" txtpassword.Text = "" txtUserName.SetFocus

登录成功页面的代码

登录成功页面的代码 无标题文档

恭喜您!注册成功!
将在秒后跳转至登录页。

C语言实现图形界面登陆窗口

纯C语言实现图形界面登陆窗口 一下是界面图: 编程工具是:VC6.0 请根据个人需要对源代码进行修改使用,图片放在工程文件夹中。新建时应该将文件后缀设置为.cpp 以下是程序灯源代码: #include #include #include #include #include #include #define LEN_A 20//账户长度 #define LEN_P 10//密码长度 typedefstruct Account { char name[20]; longint password; }InAccount; typedefstructinputAPword { InAccount account;

int flag; }InputAPword; voidinputbox(void); void cursor(void); void cursor2(void); void name(void); intMouseEvent(IMAGE); InputAPwordmenu2(void) { initgraph(640,480);//初始化图形界面 IMAGE Img1;//声明一个IMAGE变量 IMAGE Img2(640,480);//声明一个IMAGE变量 char input1[LEN_A];//用于接收输入的字符串 char input2[LEN_P];//用于接收输入的字符串 int j; InputAPword account; loadimage(&Img1,_T("girl4.bmp"));//加载图片 SetWorkingImage(&Img1);//设置当前绘图设备为Img1 setlinestyle(PS_SOLID, NULL, 2);//设置线的样式 setfont(64,0,"华文隶书");//设置字体的样式和大小 settextcolor(RGB(134,0,255));//设置字体的颜色 setlinecolor(RGB(16,16,16));//设置线的颜色 setbkmode(TRANSPARENT);//设置字体的背景为透明 outtextxy(50,50,_T("A 用户登录"));//显示汉字 settextcolor(RGB(0,0,0));//设置字体的颜色 rectangle(50,150,350,340);//画矩形框 rectangle(254,515,302,585);//画一个矩形框 fillrectangle(100,280,173,315);//登录框 fillrectangle(223,280,296,315);//取消框 SetWorkingImage();//恢复当前绘图设备为默认设备 putimage(0,0,&Img1);//显示图片 do{ name();//显示文字信息 setbkmode(OPAQUE);//设置字体背景为默认 setbkcolor(RGB(255,255,255)); cursor();//显示输入框以及闪烁的光标 for(j=0;LEN_A;j++){//限制输入,最多允许输入LNE位数据input1[j]=getch();//读取键盘输入的字符并存入数组 outtextxy(161+8*j,193,input1[j]);//将字符显示在图片上 if(input1[j]==8){//按删除键时的操作 input1[j-1]=0;//字符数组内容删除一位 outtextxy(161+8*j,193," ");//将字符遮掩 outtextxy(161+8*(j-1),193," ");//将字符遮掩 j -=2;//数组坐标后退两个

jsp注册登录页面代码

jsp注册页面代码 用户信息的bean: package chen; public class UserBean { private String userid; private String password; public void setUserId(String userid) { https://www.360docs.net/doc/7317467181.html,erid=userid; } public void setPassword(String password) { this.password=password; } public String getUserId() { return https://www.360docs.net/doc/7317467181.html,erid; } public String getPassword() { return this.password; } } 提交数据库的bean: package chen; import com.mysql.jdbc.Driver; import java.sql.*; public class UserRegister { private UserBean userBean; private Connection con; //获得数据库连接。 public UserRegister() { String url="jdbc:mysql://localhost/"+"chao"+"?user="+"root"+"&password="+"850629"; try {

Class.forName("com.mysql.jdbc.Driver").newInsta nce(); con = DriverManager.getConnection(url); } catch(Exception e) { e.printStackTrace(); } } //设置待注册的用户信息。 public void setUserBean(UserBean userBean) { https://www.360docs.net/doc/7317467181.html,erBean=userBean; } //进行注册 public void regist() throws Exception { String reg="insert into userinfo(userid,password) values(?,?)"; try { PreparedStatement pstmt=con.prepareStatement(reg); pstmt.setString(1,userBean.getU serId()); pstmt.setString(2,userBean.getP assword()); pstmt.executeUpdate(); } catch(Exception e) { e.printStackTrace(); throw e; } } } 提交注册数据进入数据库: <%@ page contentType="text/html;charset=gb2312" pageEncoding="gb2312" import="chen.*" %>

C#登录界面代码

登录窗体代码 using System; using System.Collections.Generic; using https://www.360docs.net/doc/7317467181.html,ponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Reflection; namespace TelephoneMS { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } //点击"登录"按钮实现数据库验证登录功能 private void button1_Click(object sender, EventArgs e) { //字符串赋值:用户名密码 string username = textBox1.Text.Trim(); string userpwd = textBox2.Text.Trim(); //定义数据库连接语句:服务器=.(本地) 数据库名=TelephoneMS(手机管理系统) string consqlserver = "Data Source=.;Initial Catalog=TelephoneMS;Integrated Security=True;"; //定义SQL查询语句:用户名密码 string sql = "select * from Users where username='"+ username + "' and userpwd='" + userpwd + "'"; //定义SQL Server连接对象打开数据库

用户登录界面代码

系统入口类中这样: LoginFrame lf=new LoginFrame(); lf.setVisible(true); LoginFrame 中,按钮“OK”的监听事件这样: ……//连接数据库,并验证用户名和密码 if(success)//验证成功 MainFrame mf=new MainFrame(); mf.setVisible(true); dispose(); //销毁LoginFrame else 提示错误信息 2 import javax.swing.*; import java.awt.*; import java.awt.event.*; //下面代码创建JFrame框架窗体 class FrameTest extends JFrame { public FrameTest() { super("客户登录"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); setSize(406,195); } } //下面代码创建JPanel面板,并将面板添加到框架窗体class PanelTest extends FrameTest { JPanel panelObj; public PanelTest() { panelObj=new JPanel(); getContentPane().add(panelObj); } } //下面代码创建javax.swing控件,并将控件添加到面板class ComponentTest extends PanelTest //构造组件类{

学生成绩管理系统登录界面设计

计算机应用系统与开发 实 训 报 告 实训地点:实训楼四楼 班级:网络0912 姓名:孙德灵 学号:0900002236 指导教师:李伟老师

一、实训题目 学生成绩管理系统登录界面设计。 二、学习任务与目的 1、了解相关控件的创建与设置。 2、了解https://www.360docs.net/doc/7317467181.html,的相关知识,逐步掌握https://www.360docs.net/doc/7317467181.html,中数据库开发的基本步骤。 3、学习使用Connection对象用于连接SQL Server或Access数据库的连接,了解其相关的属性和方法。对比连接两种数据库的异同。 4、学习使用Command对象访问数据进行对数据的访问、修改、运行存储过程以及发送或检索参数值的命令、 5、以及用于Datasset和数据源之间进行桥接、进行保存数据和检索数据的DataAdapter和Dataset对像的使用。 6、了解DataReader对象:可从数据源提供高性能的数据流,其从数据源中获得只读和只进数据,在任何时候只在内存中保存一行数据,减少了内存开销,提高了性能。 三、任务实施 1、对于要设计的界面进行分析: 设计界面首先要对用户输入的数据进行初步验证,判断输入数据

是否有效,如果无效返回从新输入,跳出“输入数据有误”的提示。如果有效则进行下步验证,调用数据库,看输入的数据是否与数据库中某个相符,否则返回从新输入,有则跳出“登录成功”的提示。 2、具体是实施步骤 (1)、新建解决方案,启动visual studio2005,在【文件】菜单下,选择[新建][项目]命令,在弹出的【新建项目】对话框中选择【windows应用程序】选项。并在对话框中输入名称及保存路径,具体见图1-新建解决方案。 图1-1新建解决方案 (2)、创建等录界面的设计,其相关的控键属性如表1-1控键属性,界面如图1-2登录界面所示。 控件name text

用HTML代码制作简单的登录界面

用HTML代码制作简单的登录界面 HTML部分

忘记密码?
账户名
密  码
验证码
CSS部分 .input_text{ width: 150px; height: 24px; cursor: pointer; } .input_button{

java管理员登陆界面

import java.awt.*; import java.awt.event.*; public class glydenglu extends Frame implements ActionListener { Label username=new Label("管理员姓名:");//使用文本创建一个用户名标签 TextField t1=new TextField();//创建一个文本框对象 Label password=new Label("密码:");//创建一个密码标签 TextField t2=new TextField(); Button b1=new Button("登陆");//创建登陆按钮 Button b2=new Button("取消");//创建取消按钮 public glydenglu() { this.setTitle("管理员登陆窗口");//设置窗口标题 this.setLayout(null);//设置窗口布局管理器 username.setBounds(50,40,60,20);//设置姓名标签的初始位置 this.add(username);// 将姓名标签组件添加到容器 t1.setBounds(120,40,80,20);// 设置文本框的初始位置 this.add(t1);// 将文本框组件添加到容器 password.setBounds(50,100,60,20);//密码标签的初始位置 this.add(password);//将密码标签组件添加到容器 t2.setBounds(120,100,80,20);//设置密码标签的初始位置 this.add(t2);//将密码标签组件添加到容器 b1.setBounds(50,150,60,20);//设置登陆按钮的初始位置 this.add(b1);//将登陆按钮组件添加到容器 b2.setBounds(120,150,60,20);//设置取消按钮的初始位置 this.add(b2);// 将取消按钮组件添加到容器 b1.addActionListener(this);//给登陆按钮添加监听器 b2.addActionListener(this);// 给取消按钮添加监听器 this.setVisible(true);//设置窗口的可见性 this.setSize(300,200);//设置窗口的大小 addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });//通过内部类重写关闭窗体的方法 } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1)//处理登陆事件 { String username=t1.getText(); String password=t2.getText(); if(username.equals("laoshi")&&password.equals("123456")) {new guanliyuan();} } }

相关文档
最新文档