windows应用开发程序.ppt

上传人:牧羊曲112 文档编号:6523730 上传时间:2023-11-08 格式:PPT 页数:40 大小:1.55MB
返回 下载 相关 举报
windows应用开发程序.ppt_第1页
第1页 / 共40页
windows应用开发程序.ppt_第2页
第2页 / 共40页
windows应用开发程序.ppt_第3页
第3页 / 共40页
windows应用开发程序.ppt_第4页
第4页 / 共40页
windows应用开发程序.ppt_第5页
第5页 / 共40页
点击查看更多>>
资源描述

《windows应用开发程序.ppt》由会员分享,可在线阅读,更多相关《windows应用开发程序.ppt(40页珍藏版)》请在三一办公上搜索。

1、第五章,Windows应用程序开发,2,目标,创建 Windows 窗体使用基本控件标签、文本、按钮控件、列表框和组合框消息框掌握窗体的常用属性和方法单选按钮、复选按钮、图片框,3,简介2-1,GUI界面,4,各种控件,属性,放置控件的区域,5,简介 2-2,WinForms应用程序可能存在多个窗体,用于获取用户输入的数据和向用户显示数据,简单而强大 改善了接口和基类 IntelliSense 新的管理数据提供程序 安全 灵活的控件 通晓数据 向导,6,创建 WinForms应用程序 6-1,“开始”“程序”“Microsoft Visual Studio.NET 2005”“Microsof

2、t Visual Studio.NET 2005”,7,创建 WinForms应用程序 6-2,设计窗口,8,创建 WinForms应用程序 6-3,using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication3 public partial class Form1:Form publi

3、c Form1()InitializeComponent();,提供了大量绘图工具的访问权限,基础核心命名空间,ArrayList、BitArray、Hashtable、Stack、StringCollection 和 StringTable 类,大量窗体和控件,从 派生,Visual Studio.NET 生成的代码,9,创建 WinForms应用程序 6-4,partial class Form1/必需的设计器变量。/private System.ComponentModel.IContainer components=null;,构造函数调用 InitializeComponent()方

4、法,#region Windows 窗体设计器生成的代码/设计器支持所需的方法-不要/使用代码编辑器修改此方法的内容。/private void InitializeComponent()this.SuspendLayout();/Form1/this.AutoScaleDimensions=new System.Drawing.SizeF(6F,12F);this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;this.ClientSize=new System.Drawing.Size(333,266);this.Name=Fo

5、rm1;this.Text=Form1;this.ResumeLayout(false);#endregion,项目的容器,10,创建 WinForms应用程序 6-5,/清理所有正在使用的资源。/如果应释放托管资源,为 true;否则为 false。protected override void Dispose(bool disposing)if(disposing,释放系统资源,11,创建 WinForms应用程序 6-6,static class Program/应用程序的主入口点。/STAThread static void Main()Application.EnableVisual

6、Styles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Form1();,程序的主入口点,12,WinForms 中的常用控件 2-1,可视化界面组件统称为控件,13,WinForms 中的常用控件 2-2,标签,按钮,组合框,列表框,文本框,14,标签,15,文本框,16,按钮,17,列表框,18,使用列表框,private void frmUserAdd_Load(object sender,System.EventArgs e)this.(“软件部);this.(“硬件部);thi

7、s.(“财务处);this.(“人事处);,private void cmdAdd_Click(object sender,System.EventArgs e)/注意SelectedIndex的值,第一个应该为0MessageBox.Show(已经选择上.“+lstCurrDeptName.SelectedIndex+“当前选择的值“+lstCurrDeptName.Text;,19,组合框,20,使用组合框,private void frmUserAdd_Load(object sender,System.EventArgs e)(“总经理);this.(“经理);this.(“科长);t

8、his.(“职员);/默认的选择是经理this.cboDesig.SelectedIndex=1;,private void cboPos_SelectedIndexChanged(object sender,System.EventArgs e)MessageBox.Show(选择的是第“+(this.cboPos.SelectedIndex+1).ToString()+“项);MessageBox.Show(选择的职务是“+this.cboPos.Text);,21,消息框窗口 2-1,MessageBox.Show(“消息文本);,消息框用于显示消息,Abort,Cancel,Ignor

9、e,No,None,Ok,Retry 和 Yes,if(MessageBox.Show(“保存文件”,“保存,MessageBoxButtons.YesNo,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1)=DialogResult.Yes)/保存文件所用的代码/保存后的 MessageBox,22,消息框窗口 2-2,23,应用程序示例 3-1,解决方案资源管理器,属性窗口,工具箱,24,应用程序示例 3-2,private void btnAdd_Click(object sender,System.EventArgs

10、e),private void btnAdd_Click(object sender,System.EventArgs e)=true;=true;=true;=true;,private void btnCancel_Click(object sender,System.EventArgs e)=;=;=“经理;,private void btnExit_Click(object sender,System.EventArgs e)string str=;for(int ctr=0;ctr=this.lstCurrDeptName.SelectedItems.Count-1;ctr+)str

11、+=n+this.lstCurrDeptName.SelectedItemsctr.ToString();MessageBox.Show(“选定的项目为n+str);Application.Exit();,25,应用程序示例 3-3,private void cboDesignation_SelectedIndexChanged(object sender,System.EventArgs e)MessageBox.Show(“您已经选定了+();,在退出应用程序之前,使用 MessageBox.Show()显示在 str 变量中存储选定项的消息框,26,窗体简介 2-1,图标,系统按钮,标题

12、栏,控件,27,窗体容器简介 2-2,SDI 单文档界面 MDI 多文档界面 模式窗口,28,窗体的属性,29,窗体的常用方法和事件,30,显示另一窗体,被调用的窗体类 窗体实例=new 被调用的窗体类();,窗体实例.Show();,private void cmdShow_Click(object sender,System.EventArgs e)frmA A=new frmA();A.Show();,31,应用程序示例 6-1,单击“发送”按钮,32,应用程序示例 6-2,33,应用程序示例 6-3,private void frmFeedBack_Load(object sender

13、,System.EventArgs e)(“文字效果反馈);(“版面设计反馈);(“颜色反馈);(“普通反馈);private void btnSend_Click(object sender,System.EventArgs e)frmUserDetails objfrmUserDetails=new,(),);objfrmUserDetails.Show();,34,应用程序示例 6-4,private void btnClose_Click(object sender,System.EventArgs e)this.Close();private void frmFeedBack_Clo

14、sed(object sender,System.EventArgs e)MessageBox.Show(“你的意见很好,非常感谢!);,35,应用程序示例 6-5,public class frmUserDetails:private string _name;private string _email;private string _subject;private string _feedBack;,36,应用程序示例 6-6,public frmUserDetails(string Name,string Email,string Subject,string FeedBack)Init

15、ializeComponent();/在 private 变量中存储值 this._name=Name;this._email=Email;this._subject=Subject;this._feedBack=FeedBack;/在列表框中放置值 this.lstValues.Items.Add(this._name);this.lstValues.Items.Add(this._email);this.lstValues.Items.Add(this._subject);this.lstValues.Items.Add(this._feedBack);,37,单选按钮(RadioButt

16、on),Windows 窗体单选按钮控件以组的形式使用若有多组,每组单选按钮必须放在组框控件中单选按钮允许用户从多个选项中选择一个选项,38,复选框(CheckBox),复选框按钮允许用户选择多个选项复选框按钮也要成组使用,39,图片框(PictureBox),图片框控件表示可用于显示图像的 Windows 图片框控件,显示位图、元文件、图标、JPEG、GIF 或 PNG 等格式的图形,40,总结 2-1,WinForms用于 Windows 窗体应用程序开发Windows 窗体控件是从 类派生的类组合框控件是列表框控件和文本框控件的组合,用户可以键入文本,也可以从所提供的列表中选择项目窗体提供了收集、显示和传送信息的界面,是 GUI的重要元素消息框显示消息WinForms的图片框控件允许用户在窗体上添加和显示位图、元文件、JPEG、GIF 或 PNG 等格式的图形,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号