资源预览内容
第1页 / 共408页
第2页 / 共408页
第3页 / 共408页
第4页 / 共408页
第5页 / 共408页
第6页 / 共408页
第7页 / 共408页
第8页 / 共408页
第9页 / 共408页
第10页 / 共408页
亲,该文档总共408页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
-基于C#语言,主讲教师:钱 哨a 本课学时:72课时 联系方式:qianshao,Windows程序设计,课程地位,综合基础课程,SQL Server,XML,Ajax Javascript&XML,ASP.NET,Oracle,RSS,Computer Base,HTML&JavaScript,OOPJava,C,Database Base,JSP/Servlet,EJB/WebService,C#,Struts/JSF,Testing/SQA,Linux,WinForms,第一章、Windows编程基础,本章主要内容介绍 1.1 windows和窗体 1.2 Visual Stutio .net IDE简介 1.3 事件处理,CONTENTs,1.1 Windows和窗体,本章学习目标:,理解 Windows 窗体 使用基本控件如标签、文本、按钮、列表框和组合框 掌握窗体的常用属性和方法,GUI界面,1.1 Windows和窗体,各种控件,属性,放置控件的区域,1.1 Windows和窗体,WinForms应用程序可能存在多个窗体,用于获取用户输入的数据和向用户显示数据,System.Windows.Forms,简单而强大 改善了接口和基类 IntelliSense 新的管理数据提供程序 安全 灵活的控件 通晓数据 向导,1.1 Windows和窗体,1.1.2 创建 WinForms应用程序,“开始”“程序”“Microsoft Visual Studio.NET 2005”“Microsoft Visual Studio.NET 2005”,创建 WinForms应用程序 6-2,设计窗口,1.1.2 创建 WinForms应用程序,using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace SampleProject / / Form1 的摘要说明。 / public class Form1 : System.Windows.Forms.Form / / 必需的设计器变量. / ,提供了大量绘图工具的访问权限,基础核心命名空间,ArrayList、BitArray、Hashtable、Stack、StringCollection 和 StringTable 类,大量窗体和控件,从 System.Windows.Forms.Form 派生,Visual Studio .NET 生成的代码,1.1.2 创建 WinForms应用程序,private System.ComponentModel.Container components = null; public Form1() / / Windows 窗体设计器支持所必需的 / InitializeComponent(); / / TODO:在 InitializeComponent 调用之后 添加任何构造函数代码 / ,构造函数调用 InitializeComponent() 方法,/下面代码见:Form1.Designer.cs文件 private void InitializeComponent() ponents = new System.ComponentModel.Container(); this.Size = new System.Drawing.Size(300,300); this.Text = “Form1“; ,项目的容器,创建 WinForms应用程序,/ / 清理所有正在使用的资源。【下面代码: Form1.Designer.cs 】 / protected override void Dispose( bool disposing ) if( disposing ) if(components != null) components.Dispose(); base.Dispose( disposing ); ,释放系统资源,1.1.2 创建 WinForms应用程序,/下面代码见:program.cs文件 STAThread static void Main() Application.Run(new Form1(); ,程序的主入口点,1.1.3 WinForms 中的常用控件,可视化界面组件统称为控件,System.Windows.Forms.Control,1.1.3 WinForms 中的常用控件,标签,按钮,组合框,列表框,文本框,标签,1.1.3 WinForms 中的常用控件,标签控件,按钮控件,文本框控件,列表控件,组合框控件,private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) linkLabel1.LinkVisited = true; Form2 newform = new Form2(); newform.Show(); this.Hide(); private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) /label2.Visible = true; label2.Show(); private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) label2.Visible = false; label2.Hide(); ,案例:窗口的打开和关闭,文本框,1.1.3 WinForms 中的常用控件,按钮,1.1.3 WinForms 中的常用控件,案例:用户登录设计,private void button2_Click(object sender, EventArgs e) clear(); private void button1_Click(object sender, EventArgs e) if (textBox1.Text = string.Empty | textBox2.Text = string.Empty) MessageBox.Show(“信息禁止为空!“,“登录提示“); clear(); return; if (!textBox1.Text.Equals(“admin“) | !textBox2.Text.Equals(“admin“) MessageBox.Show(“用户名称或密码为空!“, “登录提示“); clear(); return; else MessageBox.Show(“欢迎您登录本系统!“,“消息提示“); clear(); public void clear() textBox1.Clear(); textBox2.Clear(); textBox2.Focus(); ,列表框,1.1.3 WinForms 中的常用控件,使用列表框(1),private void Form1_Load(object sender, EventArgs e) this.listBox1.Items.Add(“软件部“); this.listBox1.Items.Add(“硬件部“); this.listBox1.Items.Add(“财务部“); this.listBox1.Items.Add(“人事部“); ,private void listBox1_SelectedIndexChanged(object sender, EventArgs e) MessageBox.Show(“您选择的部门是:“+listBox1.SelectedItem.ToString()+“,位列第“+listBox1.SelectedIndex.ToString(),“信息提示“); ,使用列表框(2),private void button1_Click(object sender, EventArgs e) listBox1.Items.Clear(); listBox1.Items.Add(“软件部“); listBox1.Items.Add(“硬件部“); listBox1.Items.Add(“财务部“); listBox1.Items.Add(“人事部“); private void button2_Click(object sender, EventArgs e) listBox1.Items.Insert(2,“插入值“); label1.Text = “已经添加“ + listBox1.Items.Count.ToString() + “条记录“; ,组合框,1.1.3 WinForms 中的常用控件,使用组合框,private void Form1_Load(object sender, EventArgs e) boBox1.Items.Add(“财务部“); boBox1.Items.Add(“产品部“); boBox1.Items.Add(“销售部“); boBox1.Items.Add(“生产部“); /默认的选择是“产品部“ boBox1.SelectedIndex = 1; boBox2.Items.Add(“财务部“); boBox2.Items.Add(“产品部“); boBox2.Items.Add(“销售部“); boBox2.Items.Add(“生产部“); /默认的选择是“产品部“ boBox2.SelectedIndex = 1; boBox3.Items.Add(“财务部“); boBox3.Items.Add(“产品部“); boBox3.Items.Add(“销售部“); boBox3.Items.Add(“生产部“); /默认的选择是“产品部“ boBox3.SelectedIndex = 1; ,消息框窗口,MessageBox.Show(“消息文本“);,消息框用于显示消息,Abort, Cancel, Ignore, No, None, Ok, Retry 和 Yes,if (MessageBox.Show(“保存文件”,“保存“, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) = DialogResult.Yes) /保存文件所用的代码 /保存后的 MessageBox ,1.1.3 WinForms 中的常用控件,消息框窗口,private void button1_Click(object sender, EventArgs e) MessageBox.Show(“嘿,这是简单提示!“,“信息提示“); private void button2_Click(object sender, EventArgs e) DialogResult result = MessageBox.Show(“嘿,这是问询提示!“,“问询提示“,MessageBoxButtons.YesNo); if (result = DialogResult.Yes) l
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号