上海海洋大学windows编程技术期末整理

上传人:豆浆 文档编号:11365980 上传时间:2017-10-13 格式:DOCX 页数:35 大小:30.41KB
返回 下载 相关 举报
上海海洋大学windows编程技术期末整理_第1页
第1页 / 共35页
上海海洋大学windows编程技术期末整理_第2页
第2页 / 共35页
上海海洋大学windows编程技术期末整理_第3页
第3页 / 共35页
上海海洋大学windows编程技术期末整理_第4页
第4页 / 共35页
上海海洋大学windows编程技术期末整理_第5页
第5页 / 共35页
点击查看更多>>
资源描述

《上海海洋大学windows编程技术期末整理》由会员分享,可在线阅读,更多相关《上海海洋大学windows编程技术期末整理(35页珍藏版)》请在金锄头文库上搜索。

1、第 1 页 共 35 页实 验 一 : VS 环 境 认 识 和 程 序 设 计 初 步 1.开发一个控制台应用程序,输出你的姓名和学号namespace ConsoleApplication1class Programstatic void Main(string args)Console.WriteLine(my name is:zhonghua hong);Console.WriteLine(my is is 2014);Console.Read();2. 开发一个 WINDOWS 应用程序,实现加法计算和清除功能namespace WindowsFormsApplication1pub

2、lic partial class Form1 : Formpublic Form1()InitializeComponent();private void button1_Click(object sender, EventArgs e)textBox3.Text = (int.Parse(textBox1.Text) + int.Parse(textBox2.Text).ToString();private void button2_Click(object sender, EventArgs e)textBox1.Text = ;textBox2.Text = ;textBox3.Tex

3、t = ;第 2 页 共 35 页3.新建一个 form 窗体作为启动窗体,并在窗体上显示“学号,姓名”实 验 二 : C#编 程 语 言 基 础 _上 机1. 用控制台应用程序编写一个简单的学生成绩统计系统成绩:90,80,67,87,92,57,77,79,95,99;级别:优、良、中、差;条件:=90 8089 60 79 =59;用数组存储成绩:循环判断(if、switch、for);输出优、良、中、差所占成绩的百分比(WriteLine);输出成绩排序(从高到低排序)namespace ConsoleApplication1class Programstatic void Main(

4、string args)int score;score=new int1090,80,67,87,92,57,77,79,95,99;int numA=0,numB=0,numC=0,numD=0,num=0;/*for(int i=0;i=90) numA+;else if(scorei=80) numB+;else if(scorei=60) numC+;else numD+;for (int i=0;i 4)PicNum = 0;第 27 页 共 35 页pictureBox1.Image = bitmapPicNum;PicNum+;/速度控制private void trackBar

5、1_Scroll(object sender, EventArgs e)timer1.Interval = trackBar1.Value;实 验 十 一 - 进 程 和 多 线 程 程 序 设 计 1.pp:101-103 应用进程调用已有的计算器并打开namespace CProcesspublic partial class Form1 : Formpublic Form1()InitializeComponent();/启动一个 Windows 计算器第 28 页 共 35 页private void btnCalculatorStart_Click(object sender, Ev

6、entArgs e)CalculatorProcess.Start();/关闭全部已启动的 Windows 计算器private void btnCalculatorStopAll_Click(object sender, EventArgs e)/创建一个 Process 组件的数组Process CalculatorProcess;/将所建数组与指定的进程名称( calc)的所有进程资源相关联CalculatorProcess = Process.GetProcessesByName(calc);/遍历当前启动程序中,查找包含指定名称的进程foreach(Process instance

7、in CalculatorProcess)/终止当前进程,关闭应用程序窗体instance.CloseMainWindow();/启动一个上机自测系统private void btnSelfExamStart_Click(object sender, EventArgs e)FileInfo fInfo = new FileInfo(E:C#程序设计教材源代码 chpt5-1selfExamselfExambinDebugselfExam.exe);第 29 页 共 35 页if (fInfo.Exists)/实例一个 Process 类,启动一个独立进程Process prcsSelfExa

8、m = new Process();/Process 有一个 StartInfo 属性,这是 ProcessStartInfo 类,包括一些方法和属性 prcsSelfExam.StartInfo.FileName = fInfo.FullName;/待启动的程序文件prcsSelfExam.Start(); /启动进程elseMessageBox.Show(文件: + fInfo.FullName + 不存在!);/关闭所有上机自测系统private void btnSelfExamStopAll_Click(object sender, EventArgs e)/创建一个 Process

9、组件的数组Process SelfExamProcess;/将所建数组与指定的进程名称( selfExam)的所有进程资源相关联SelfExamProcess = Process.GetProcessesByName(selfExam);/遍历当前启动程序中,查找包含指定名称的进程foreach (Process instance in SelfExamProcess)第 30 页 共 35 页/终止当前进程,关闭应用程序窗体instance.CloseMainWindow();2.pp: 107-108 应用线程技术实现两个独立线程进行 0-999 累加并显示在 TextBox 里names

10、pace MThreadTest1public partial class Form1 : Formpublic Form1()InitializeComponent();CheckForIllegalCrossThreadCalls = false;/禁用此异常private Thread thread1 = null;/创建用来计数的线程对象private Thread thread2 = null;private void Form1_Load(object sender, EventArgs e)thread1 = new Thread(new ThreadStart(counter1

11、);/线程初始化第 31 页 共 35 页thread2 = new Thread(new ThreadStart(counter2);thread1.Start();/启动线程thread2.Start();/线程 1(thread1)的计数方法private void counter1()while (true)int i;for (i = 0; i 1000; i+)textBox1.Text = i.ToString();Thread.Sleep(3000);/线程休眠 3 秒/线程 2(thread2)的计数方法private void counter2()while (true)第

12、 32 页 共 35 页int j;for (j = 0; j 1000; j+)textBox2.Text = j.ToString();Thread.Sleep(3000);private void button1_Click(object sender, EventArgs e)thread1.Abort();/销毁线程thread2.Abort();button1.Enabled = false;3.pp: 111-113 应用多线程 lock 实现线程互斥,同时往 richTextBox 里输出大写 A 和小写 anamespace ThreadMutex1public partia

13、l class Form1 : Formpublic Form1()第 33 页 共 35 页InitializeComponent();CheckForIllegalCrossThreadCalls = false;/禁用此异常/创建显示字符的线程对象private Thread thread1 = null;private Thread thread2 = null;/显示字符private void ShowChar(char ch)lock (this)richTextBox1.Text += ch;/线程 thread1 调用的方法(显示字符 a)private void threa

14、d1Show()while (true)ShowChar(a);Thread.Sleep(60);第 34 页 共 35 页/线程 thread2 调用的方法(显示字符 A)private void thread2Show()while (true)ShowChar(A);Thread.Sleep(30);/线程初始化,并启动线程private void button1_Click(object sender, EventArgs e)thread1 = new Thread(new ThreadStart(thread1Show);thread2 = new Thread(new Threa

15、dStart(thread2Show);thread1.Start();thread2.Start();button1.Enabled = false;button2.Enabled = true;/终止线程第 35 页 共 35 页private void button2_Click(object sender, EventArgs e)thread1.Abort();thread2.Abort();button1.Enabled = true;button2.Enabled = false;/关闭窗体时终止线程(否则,VS 调试程序将仍处于运行状态)private void Form1_FormClosing(object sender, FormClosingEventArgs e)if (thread1 != null) thread1.Abort();if (thread2 != null) thread2.Abort();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

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