电子科技大学信息与软件工程学院
标 准 实 验 报 告
(实验)课程名称 人机界面设计
学号:2011222020025
姓名:卢泓宇
电子科技大学教务处制表
电 子 科 技 大 学
实 验 报 告
学生姓名:卢泓宇 学 号:2011222020025 指导教师:邓建
实验地点: 计算机大楼 实验时间:
1、 实验室名称303:
2、 实验项目名称:文件读写和目录信息提取
三、实验学时:2
四.实验原理:
1. 为支持中文目录和文件名的正确显示,采用StreamWriter类,它实现了一个 TextWriter,使其以一种特定的编码向流中写入字符,使用默认的编码System.Text.Encoding.Default,即UTF8Encoding。
2. 使用FolderBrowserDialog控件进行目录的浏览和选择。
3. 使用DirectoryInfo类的GetFiles()方法获取该目录下的文件信息。
4. 使用DirectoryInfo类的GetDirectories()方法获取子目录的信息。
使用RichTextBox控件的LoadFile("c:\ dir_info.txt", RichTextBoxStreamType.PlainText)方法显示c:\ dir_info.txt文件中的
内容
财务内部控制制度的内容财务内部控制制度的内容人员招聘与配置的内容项目成本控制的内容消防安全演练内容
五、实验目的:
1、通过Visual Studio 2008软件进行C#程序设计,熟悉开发工具的使用,特别是调试方法;
2、认识、熟悉数据流和文件,目录信息的使用方法,掌握文件的读写、目录信息的提取、字符串操作等。
六、实验内容:
1.应用程序的主界面包括“打开”和“退出”菜单项,点击“退出”则结束本应用程序。
2.点击“打开”菜单,显示目录选择对话框,用户选择一个文件夹后,将该文件夹下的所有文件和子目录的文件名输出到c:\ dir_info.txt文件中。
3.将c:\ dir_info.txt文件中的内容显示在多行文本框中
七、实验器材(设备、元器件):
1、试验环境:PC机
2、操作系统 Window XP
八、实验步骤:
wpf前端代码:
Wpf 后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Forms;
namespace WpfApplication2
{
///
/// MainWindow.xaml 的Ì?交?互£¤逻?辑-
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
try
{
string filename = string.Empty;
System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog();
System.Windows.Interop.HwndSource source = PresentationSource.FromVisual(this) as System.Windows.Interop.HwndSource;
System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);
System.Windows.Forms.DialogResult result = dlg.ShowDialog(win);
filename = dlg.SelectedPath;
//System.Windows.Forms.FolderBrowserDialog
Directory.SetCurrentDirectory(filename);
string[] directorys = Directory.GetFiles(filename);
foreach (string file in directorys)
{
this.textBox1.Text += file + "\n";
}
}
catch (Exception ex)
{
return;
}
}
private void MenuItem_Click_1(object sender, RoutedEventArgs e)
{
this.Close();
}
}
public class OldWindow : System.Windows.Forms.IWin32Window
{
IntPtr _handle;
public OldWindow(IntPtr handle)
{
_handle = handle;
}
#region IWin32Window Members
IntPtr System.Windows.Forms.IWin32Window.Handle
{
get { return _handle; }
}
#endregion
}
}
十、实验结论:
试验结果符合预期目的。
十一、
总结
初级经济法重点总结下载党员个人总结TXt高中句型全总结.doc高中句型全总结.doc理论力学知识点总结pdf
及心得体会:
试验后基本上没有收获。
十二、对本实验过程及方法、手段的改进建议:
还可以添加更多的功能在程序中
报告
软件系统测试报告下载sgs报告如何下载关于路面塌陷情况报告535n,sgs报告怎么下载竣工报告下载
评分
售楼处物业服务评分营养不良炎症评分法中国大学排行榜100强国家临床重点专科供应商现场质量稽核
:
指导教师签字:
学生姓名: 卢泓宇 学 号: 2011222020025 指导教师:邓建
实验地点:计算机大楼 实验时间:
一.实验室名称: 303
二.实验项目名称: Internet访问和数据提交
三.实验学时:2
四.实验原理:
5. 通过WebRequest .Create("http://www.google.com.hk")发出对统一资源标识符 (URI) 的请求。
6. 使用WebRequest .GetResponse()返回对 Internet 请求的响应,对其网络流进行读取。
7. 使用(HttpWebRequest)WebRequest.Create(urlstr)创建可提交的Web请求,设置Method = "Post",ContentType = "application/x-www-form-urlencoded"和ContentLength属性,调用GetRequestStream()方法创建请求流,通过Write方法进行数据提交。
8. 采用支持简单邮件传输协议 (SMTP)的SmtpClient类来发送电子邮件。
五.实验目的:
1、通过Visual Studio 2008软件进行C#程序设计,进一步熟悉开发工具的使用,特别是调试方法;
2、认识、熟悉WebRequest 和 WebResponse 模型,掌握Internet访问、数据提交和SMTP邮件的发送。
六.实验内容
1.应用程序的主界面如下,点击“退出”则结束本应用程序。
2.在Url地址输入文本框内输入合法Web地址,点击“Http”菜单或按钮,浏览页面的内容,并显示该页面的文本信息。
4.在SMTP等输入文本框内输入合法数据,点击“Send Mail”菜单或按钮,发送SMTP邮件。
七.实验器材(设备、元器件):
1.试验环境:PC机
2.操作系统 Window XP
八.实验步骤:
关键代码:
Wpf:前端
Wpf:后台关键代码:
private void exitMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void httpMenuItem_Click(object sender, EventArgs e)
{
httpAccess();
}
private void httpAccess()
{
string urlstr = httpUrlTextBox.Text; // "http://www.google.com.hk";
WebRequest req = WebRequest.Create(urlstr);
showResponse(req, urlstr);
}
private void btnPost_Click(object sender, EventArgs e)
{
postData();
}
private void postData()
{
string urlstr = postUrlTextBox.Text;
string sendDataStr = postDataTextBox.Text;
byte[] sendData = Encoding.UTF8.GetBytes(sendDataStr);
int sendLength = sendData.Length;
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(urlstr);
httpReq.Method = "Post";
httpReq.ContentType = "application/x-www-form-urlencoded";
httpReq.ContentLength = sendLength;
Stream sendStream = httpReq.GetRequestStream();
sendStream.Write(sendData, 0, sendLength);
sendStream.Close();
showResponse(httpReq, urlstr);
}
private void sendMail()
{
// 测试通过
MailAddress from = new MailAddress(emailAccountTextBox.Text, senderTextBox.Text ); // new MailAddress("ben@contoso.com", "Ben Miller");
MailAddress to = from; // // send to myself
MailMessage message = new MailMessage(from, to);
message.Subject = subjectTextBox.Text;
message.Body = contentTextBox.Text;
SmtpClient mailClient = new SmtpClient(smtpServerTextBox.Text, int.Parse(smtpPortTextBox.Text));
mailClient.EnableSsl = true;
NetworkCredential cred = new NetworkCredential(
emailAccountTextBox.Text, // user name
passwordTextBox.Text); // pass word
mailClient.Credentials = cred;
mailClient.Send(message);
// mailClient.Send( textBox1.Text, textBox1.Text, "test by dj", "email body for test."); // another way
}
private void buttonSendMail_Click(object sender, EventArgs e)
{
sendMail();
}
private void showResponse(WebRequest req, string urlstr)
{
WebResponse resp = req.GetResponse();
Stream respstrm = resp.GetResponseStream();
int bufferSize = 8192;
Byte[] buffer = new Byte[bufferSize];
int totalRead = 0;
int bytesRead = respstrm.Read(buffer, 0, bufferSize);
string respstr = "";
while (bytesRead > 0)
{
respstr += Encoding.ASCII.GetString(buffer, 0, bytesRead);
totalRead += bytesRead;
bytesRead = respstrm.Read(buffer, 0, bufferSize);
}
respstrm.Close();
resp.Close();
richTextBox1.Clear();
richTextBox1.AppendText(urlstr);
richTextBox1.AppendText("\n");
richTextBox1.AppendText("Response data length is ");
richTextBox1.AppendText(totalRead.ToString());
richTextBox1.AppendText("\n");
if (totalRead > 0)
{
webBrowser1.DocumentText = respstr;
richTextBox1.AppendText(respstr);
}
else
{
webBrowser1.DocumentText = "";
}
}
十.实验结论:
结果符合预期
十一.总结及心得体会:
学习了发送http请求的方法。
十二.对本实验过程及方法、手段的改进建议:
本实验可以添加更多的错误检测。
报告评分:
指导教师签字:
电 子 科 技 大 学
实 验 报 告
学生姓名:卢泓宇 学 号:2011222020025 指导教师:邓建
实验地点: 计算机大楼 实验时间:
二.实验室名称303:
3. 实验学时:2
4. 实验原理:
1.使用new创建窗体,窗体的Show()、Hide()、Close()分别对应显示、隐藏和关闭,2.窗体的Text属性为窗体的标题文字,StartPosition属性将影响窗体在首次显示时的位置。
3.NumericUpDown控件为数字选择列表,通过Maximum(默认值为 100,本实验均改为255)、Minimum(默认值为 0)限定数字范围。列表框的具体内容通过Items属性来访问,当用户在列表框中点击不同的项时,会触发SelectedIndexChanged事件。
哈希表的Add方法添加键和值,用键作数组的索引可返回对应的值。
通过属性元数据遍历颜色结构的所有预定义颜色名称和颜色值。
五、实验目的:
1、通过Visual Studio 2008软件进行C#程序设计,熟悉窗体的创建、显示、隐藏、关闭和背景颜色等属性的设置;
2、认识和使用菜单、按钮、标签、列表框、数字选择列表等控件的属性和事件。
3、掌握哈希表的使用。
4、学习属性元数据的使用。
六、实验内容:
应用程序的主界面一些菜单项,点击“退出”则结束本应用程,点击“红色”、“绿色”、“蓝色”菜单项设置窗体的背景颜色。
2.点击“自定义颜色值”显示如下窗体,用户可以从“典型颜色”列表框选择,也可以直接输入颜色分量。
3.点击“确定”按钮则设置主界面的背景颜色,点击“取消”按钮则将主界面的背景颜色恢复为显示“自定义颜色值”窗体前的值,点击“返回”时隐藏本窗体。
七、实验器材(设备、元器件):
1、试验环境:PC机
2、操作系统 Window XP
八、实验步骤:
Wpf:前端代码:
Wpf:后端代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
{
///
/// MainWindow.xaml 的Ì?交?互£¤逻?辑-
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
this.Background = Brushes.Red;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
this.Background = Brushes.Green;
}
private void button3_Click(object sender, RoutedEventArgs e)
{
this.Background = Brushes.Blue;
}
private void button4_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.ColorDialog colorDialog = new System.Windows.Forms.ColorDialog();
if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
System.Drawing.SolidBrush sb = new System.Drawing.SolidBrush(colorDialog.Color);
SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(sb.Color.A, sb.Color.R, sb.Color.G, sb.Color.B));
Application.Current.MainWindow.Background = solidColorBrush;
}
}
private void button5_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
十、实验结论:
实验结果符合预期目的。
十一、总结及心得体会:
试验后基本上没有收获。
十二、对本实验过程及方法、手段的改进建议:
试验还可以加更多的工具
报告评分:
指导教师签字:
实 验 报 告
学生姓名: 卢泓宇 学 号:2011222020025 指导教师:邓建
实验地点: 计算机 实验时间:
一、实验室名称: 303
二、实验项目名称:简单绘图程序
三、实验学时:2
四、实验原理:1.在GUI程序中,对话框主要用于捕捉用户输入。不像以前使用的其他GUI API,这里没有Dialog基类。更确切地说,Windows Forms中的对话框是派生于Form类的类型。此外,许多对话框被设计为不可更改大小。因此,需要把FormBorderStyle属性设置为FormBorderStyle.FixedDialog。同时,把对话框的MinimizeBox和MaximizeBox属性设置为false。这样,对话框的大小就固定不变了。最后,如果把ShowInTaskbar属性设置为false,那么此窗体将不会出现在Windows的任务栏中。
2.编写GDI+应用程序的时候会用到的大部分的类都包含在System.Drawing命名空间内,其中有很多类是用来代表图像、画刷、画笔和字体的。此外,System.Drawing还定义了一些相关的实用类型,比如Color、Point和Rectangle。。
3.为了获取Graphics对象,最常用的方法是,在你试图呈现的窗口中处理Paint事件,Paint事件可以在Visual Studio 2008的属性窗口中找到。此事件是根据PaintEventHandler委托定义的,此委托通过 GDI+呈现图形数据指向那些第一个参数是System.Object,第二个参数是PaintEventArgs的方法。PaintEventArgs参数包含要求呈现在Form上的Graphics对象。
五、实验目的:
1、通过Visual Studio 2008软件进行C#程序设计,熟悉GDI+ API;
2、认识和使用Paint事件。
3、掌握类的序列化。
4、学习数据反序列化。
六、实验内容:
创建一个基本的绘画程序,它允许用户根据选择的颜色来选择两种不同的形状(为简单起见,只有圆形或矩形),并且允许用户在窗体中呈现数据。此外,通过对象序列化功能,允许终端用户把图像保存到本地文件中以供日后使用。
七、实验器材(设备、元器件):
1、试验环境:PC机
2、操作系统 Window XP
八、实验步骤:
1.首先创建一个新的Windows Forms应用程序,并命名为MyPaintProgram,同时把初始的Form1.cs文件更名为MainWindow.cs。现在,在初始的窗口中设计一套菜单系统用于支持最顶端文件菜单,它提供Save…、Load…和Exit子菜单。
2.创建第二个顶端工具菜单,它提供了为用户呈现形状和颜色的选项以及清除窗体中的所有图形数据的选项。
3.为File→Exit菜单提供Click事件处理。
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
4.应用程序允许最终用户根据给定的颜色来选择预定义的两种形状。为了提供一种方法允许用户把图形数据保存到文件中,需要用户自定义类用于封装图形数据的各个细节。为简单起见,将使用C#的自动属性来实现。添加一个新类到项目中,并命名为ShapeData.cs。实现代码如下:
[Serializable]
class ShapeData
{
// The upper left of the shape to be drawn.
public Point UpperLeftPoint {get; set;}
// The current color of the shape to be drawn.
public Color Color { get; set; }
// The type of shape.
public SelectedShape ShapeType { get; set; }
}
ShapeData使用了3种自动属性,其中两个(Point和Color)定义在System.Drawing命名空间中,因此需要确保代码文件引入了此命名空间。同时应该注意这些类型需要使用[Serializable]特性进行修饰。
5.为了允许用户在圆形和矩形图像类型之间进行选择,现在创建一个简单的客户自定义对话框ShapePickerDialog(添加一个新窗体)。除了必须的OK和Cancel按钮(每个按钮分配了正确的DialogResult值),此对话框还将使用一个GroupBox,用于维护两个RadioButton对象,分别命名为radioButtonCircle和radioButtonRect。
通过右键点击窗体设计器为对话框打开代码窗口,并且选择View Code菜单选项。在MyPaintProgram命名空间中,定义一个枚举(命名为SelectedShape),枚举项为每种可能形状的名字:
public enum SelectedShape
{
Circle, Rectangle
}
6.按如下步骤更新当前ShapePickerDialog类。添加一个名为SelectedShape的自动属性。调用者可以通过它来决定呈现哪个形状。使用属性窗口添加Click事件处理程序。实现此事件处理程序,判断圆形按钮是否被选择了(通过Checked属性)。如果是,就把currentShape变量设置为SelectedShape.Cirecle;否则,设置为SelectedShape.Rectangle。下面是完整代码:
public partial class ShapePickerDialog : Form
{
public SelectedShape SelectedShape { get; set; }
public ShapePickerDialog()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
if (radioButtonCircle.Checked)
SelectedShape = SelectedShape.Circle;
else
SelectedShape = SelectedShape.Rectangle;
}
}
7.返回到主窗口,添加3个新的成员变量到F