CSharp_Win实践开发教程(全)

上传人:资****亨 文档编号:130060274 上传时间:2020-04-24 格式:PPT 页数:408 大小:18.94MB
返回 下载 相关 举报
CSharp_Win实践开发教程(全)_第1页
第1页 / 共408页
CSharp_Win实践开发教程(全)_第2页
第2页 / 共408页
CSharp_Win实践开发教程(全)_第3页
第3页 / 共408页
CSharp_Win实践开发教程(全)_第4页
第4页 / 共408页
CSharp_Win实践开发教程(全)_第5页
第5页 / 共408页
点击查看更多>>
资源描述

《CSharp_Win实践开发教程(全)》由会员分享,可在线阅读,更多相关《CSharp_Win实践开发教程(全)(408页珍藏版)》请在金锄头文库上搜索。

1、 基于C 语言 主讲教师 钱哨a本课学时 72课时联系方式 qianshao Windows程序设计 课程地位 综合基础课程 SQLServer XML Ajax Javascript XML ASP NET Oracle RSS ComputerBase HTML JavaScript OOP Java C DatabaseBase JSP Servlet EJB WebService C Struts JSF Testing SQA Linux WinForms 第一章 Windows编程基础 本章主要内容介绍1 1windows和窗体1 2VisualSIDE简介1 3事件处理 CONT

2、ENTs 1 1Windows和窗体 本章学习目标 理解Windows窗体使用基本控件如标签 文本 按钮 列表框和组合框掌握窗体的常用属性和方法 GUI界面 1 1Windows和窗体 各种控件 属性 放置控件的区域 1 1Windows和窗体 WinForms应用程序可能存在多个窗体 用于获取用户输入的数据和向用户显示数据 System Windows Forms 简单而强大改善了接口和基类IntelliSense新的管理数据提供程序安全灵活的控件通晓数据向导 1 1Windows和窗体 1 1 2创建WinForms应用程序 开始 程序 MicrosoftVisualStudio NET2

3、005 MicrosoftVisualStudio NET2005 创建WinForms应用程序6 2 设计窗口 1 1 2创建WinForms应用程序 usingSystem usingSystem Drawing usingSystem Collections usingSystem ComponentModel usingSystem Windows Forms namespaceSampleProject Form1的摘要说明 publicclassForm1 System Windows Forms Form 必需的设计器变量 提供了大量绘图工具的访问权限 基础核心命名空间 Arra

4、yList BitArray Hashtable Stack StringCollection和StringTable类 大量窗体和控件 从System Windows Forms Form派生 VisualStudio NET生成的代码 1 1 2创建WinForms应用程序 privateSystem ComponentModel Containercomponents null publicForm1 Windows窗体设计器支持所必需的 InitializeComponent TODO 在InitializeComponent调用之后添加任何构造函数代码 构造函数调用Initializ

5、eComponent 方法 下面代码见 Form1 Designer cs文件privatevoidInitializeComponent ponents newSystem ComponentModel Container this Size newSystem Drawing Size 300 300 this Text Form1 项目的容器 创建WinForms应用程序 清理所有正在使用的资源 下面代码 Form1 Designer cs protectedoverridevoidDispose booldisposing if disposing if components null

6、 components Dispose base Dispose disposing 释放系统资源 1 1 2创建WinForms应用程序 下面代码见 program cs文件 STAThread staticvoidMain Application Run newForm1 程序的主入口点 1 1 3WinForms中的常用控件 可视化界面组件统称为控件 System Windows Forms Control 1 1 3WinForms中的常用控件 标签 按钮 组合框 列表框 文本框 标签 1 1 3WinForms中的常用控件 标签控件 按钮控件 文本框控件 列表控件 组合框控件 pri

7、vatevoidlinkLabel1 LinkClicked objectsender LinkLabelLinkClickedEventArgse linkLabel1 LinkVisited true Form2newform newForm2 newform Show this Hide privatevoidlinkLabel2 LinkClicked objectsender LinkLabelLinkClickedEventArgse label2 Visible true label2 Show privatevoidlinkLabel3 LinkClicked objectse

8、nder LinkLabelLinkClickedEventArgse label2 Visible false label2 Hide 案例 窗口的打开和关闭 文本框 1 1 3WinForms中的常用控件 按钮 1 1 3WinForms中的常用控件 案例 用户登录设计 privatevoidbutton2 Click objectsender EventArgse clear privatevoidbutton1 Click objectsender EventArgse if textBox1 Text string Empty textBox2 Text string Empty M

9、essageBox Show 信息禁止为空 登录提示 clear return if textBox1 Text Equals admin textBox2 Text Equals admin MessageBox Show 用户名称或密码为空 登录提示 clear return else MessageBox Show 欢迎您登录本系统 消息提示 clear publicvoidclear textBox1 Clear textBox2 Clear textBox2 Focus 列表框 1 1 3WinForms中的常用控件 使用列表框 1 privatevoidForm1 Load obj

10、ectsender EventArgse this listBox1 Items Add 软件部 this listBox1 Items Add 硬件部 this listBox1 Items Add 财务部 this listBox1 Items Add 人事部 privatevoidlistBox1 SelectedIndexChanged objectsender EventArgse MessageBox Show 您选择的部门是 listBox1 SelectedItem ToString 位列第 listBox1 SelectedIndex ToString 信息提示 使用列表框

11、2 privatevoidbutton1 Click objectsender EventArgse listBox1 Items Clear listBox1 Items Add 软件部 listBox1 Items Add 硬件部 listBox1 Items Add 财务部 listBox1 Items Add 人事部 privatevoidbutton2 Click objectsender EventArgse listBox1 Items Insert 2 插入值 label1 Text 已经添加 listBox1 Items Count ToString 条记录 组合框 1 1

12、3WinForms中的常用控件 使用组合框 privatevoidForm1 Load objectsender EventArgse 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 SelectedInde

13、x 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 MessageBoxDefaultButto

14、n Button1 DialogResult Yes 保存文件所用的代码 保存后的MessageBox 1 1 3WinForms中的常用控件 消息框窗口 privatevoidbutton1 Click objectsender EventArgse MessageBox Show 嘿 这是简单提示 信息提示 privatevoidbutton2 Click objectsender EventArgse DialogResultresult MessageBox Show 嘿 这是问询提示 问询提示 MessageBoxButtons YesNo if result DialogResul

15、t Yes label1 Text 您选择了YES else label1 Text 您选择了NO privatevoidbutton3 Click objectsender EventArgse DialogResultresult MessageBox Show 嘿 这是带有图标的问询提示 问询提示 MessageBoxButtons YesNoCancel MessageBoxIcon Question MessageBoxDefaultButton Button3 MessageBoxOptions RightAlign if result DialogResult Yes label

16、1 Text 您选择了图标YES elseif result DialogResult Cancel label1 Text 您选择了图标取消 elseif result DialogResult No label1 Text 您选择了图标NO 应用程序示例 解决方案资源管理器 属性窗口 工具箱 应用程序示例 privatevoidbtnAdd Click objectsender System EventArgse privatevoidbtnAdd Click objectsender System EventArgse this txtEmpName Enabled true this txtAddress Enabled true this cboDesignation Enabled true this lstCurrDeptName Enabled true privatevoidbtnCancel Click objectsender System EventArgse this txtEmpName Text this txtAddress Text this cboD

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号