.NET编程技术实验报告

上传人:文库蛋蛋多 文档编号:2384204 上传时间:2023-02-17 格式:DOC 页数:27 大小:605KB
返回 下载 相关 举报
.NET编程技术实验报告_第1页
第1页 / 共27页
.NET编程技术实验报告_第2页
第2页 / 共27页
.NET编程技术实验报告_第3页
第3页 / 共27页
.NET编程技术实验报告_第4页
第4页 / 共27页
.NET编程技术实验报告_第5页
第5页 / 共27页
点击查看更多>>
资源描述

《.NET编程技术实验报告》由会员分享,可在线阅读,更多相关《.NET编程技术实验报告(27页珍藏版)》请在三一办公上搜索。

1、 实验报告 (2012-2013学年第二学期) 课程名称: .NET编程技术 学生姓名: 兰天翔 专业班级: 10级计算机2班 学 院: 信电学院 学 号: 14514026 学生成绩: 实验一Windows应用编程实验目的1 掌握windows窗体的基本属性、事件和方法的使用。2 掌握常用控件的具体使用。实验内容完成字体设置程序。实验代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Te

2、xt;using System.Windows.Forms;namespace FontSet public partial class Form1 : Form string fontFamily=宋体; float fontSize=10.0f; FontStyle fontStyle=FontStyle.Regular; public Form1() InitializeComponent(); private void setFont() this.richTextBox1.Font = new Font(fontFamily, fontSize, fontStyle); privat

3、e void rbSongti_CheckedChanged(object sender, EventArgs e) if (rbSongti.Checked) this.fontFamily = 宋体; setFont(); private void rbLishu_CheckedChanged(object sender, EventArgs e) if (rbLishu.Checked) this.fontFamily = 隶书; setFont(); private void cbBold_CheckedChanged(object sender, EventArgs e) if (c

4、bBold.Checked) this.fontStyle = this.fontStyle| FontStyle.Bold; else this.fontStyle -= FontStyle.Bold; setFont(); private void cbItalic_CheckedChanged(object sender, EventArgs e) if (cbItalic.Checked) this.fontStyle =this.fontStyle| FontStyle.Italic; else this.fontStyle -= FontStyle.Italic; setFont(

5、); private void cbUnderline_CheckedChanged(object sender, EventArgs e) if (cbUnderline.Checked) this.fontStyle = this.fontStyle | FontStyle.Underline; else this.fontStyle -= FontStyle.Underline; setFont(); private void numericUpDown1_ValueChanged(object sender, EventArgs e) this.fontSize = Convert.T

6、oSingle(this.numericUpDown1.Value); setFont(); Programusing System;using System.Collections.Generic;using System.Windows.Forms;namespace FontSet static class Program / 应用程序的主入口点。 STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Appl

7、ication.Run(new Form1(); Forml.Designernamespace FontSet partial class Form1 / 必需的设计器变量。 private System.ComponentModel.IContainer components = null; / 清理所有正在使用的资源。 / 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) if (disposing & (components != null) components.Dispose();

8、 base.Dispose(disposing); #region Windows 窗体设计器生成的代码 / 设计器支持所需的方法 - 不要 / 使用代码编辑器修改此方法的内容。 private void InitializeComponent() this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.rbSongti

9、 = new System.Windows.Forms.RadioButton(); this.rbLishu = new System.Windows.Forms.RadioButton(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.cbBold = new System.Windows.Forms.CheckBox(); this.cbItalic = new System.Windows.Forms.CheckBox(); this.cbUnderline = new System.Wind

10、ows.Forms.CheckBox(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); (System.ComponentModel.ISupportInitialize)(this.numericUpDown1).BeginInit(); this.SuspendLayout(); / groupBox1 this.groupB

11、ox1.Controls.Add(this.rbLishu); this.groupBox1.Controls.Add(this.rbSongti); this.groupBox1.Location = new System.Drawing.Point(3, 206); this.groupBox1.Name = groupBox1; this.groupBox1.Size = new System.Drawing.Size(208, 199); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox

12、1.Text = 字体; / groupBox2 this.groupBox2.Controls.Add(this.numericUpDown1); this.groupBox2.Location = new System.Drawing.Point(217, 206); this.groupBox2.Name = groupBox2; this.groupBox2.Size = new System.Drawing.Size(201, 199); this.groupBox2.TabIndex = 0; this.groupBox2.TabStop = false; this.groupBo

13、x2.Text = 大小; / groupBox3 this.groupBox3.Controls.Add(this.cbUnderline); this.groupBox3.Controls.Add(this.cbItalic); this.groupBox3.Controls.Add(this.cbBold); this.groupBox3.Location = new System.Drawing.Point(424, 206); this.groupBox3.Name = groupBox3; this.groupBox3.Size = new System.Drawing.Size(

14、216, 199); this.groupBox3.TabIndex = 0; this.groupBox3.TabStop = false; this.groupBox3.Text = 风格; / rbSongti this.rbSongti.AutoSize = true; this.rbSongti.Location = new System.Drawing.Point(27, 41); this.rbSongti.Name = rbSongti; this.rbSongti.Size = new System.Drawing.Size(47, 16); this.rbSongti.Ta

15、bIndex = 0; this.rbSongti.TabStop = true; this.rbSongti.Text = 宋体; this.rbSongti.UseVisualStyleBackColor = true; this.rbSongti.CheckedChanged += new System.EventHandler(this.rbSongti_CheckedChanged); / rbLishu this.rbLishu.AutoSize = true; this.rbLishu.Location = new System.Drawing.Point(27, 81); th

16、is.rbLishu.Name = rbLishu; this.rbLishu.Size = new System.Drawing.Size(47, 16); this.rbLishu.TabIndex = 1; this.rbLishu.TabStop = true; this.rbLishu.Text = 隶书; this.rbLishu.UseVisualStyleBackColor = true; this.rbLishu.CheckedChanged += new System.EventHandler(this.rbLishu_CheckedChanged); / numericU

17、pDown1 this.numericUpDown1.Location = new System.Drawing.Point(36, 52); this.numericUpDown1.Name = numericUpDown1; this.numericUpDown1.Size = new System.Drawing.Size(120, 21); this.numericUpDown1.TabIndex = 2; this.numericUpDown1.Value = new decimal(new int 10, 0,0, 0); this.numericUpDown1.ValueChan

18、ged += new System.EventHandler(this.numericUpDown1_ValueChanged); / cbBold this.cbBold.AutoSize = true; this.cbBold.Location = new System.Drawing.Point(50, 41); this.cbBold.Name = cbBold; this.cbBold.Size = new System.Drawing.Size(48, 16); this.cbBold.TabIndex = 3; this.cbBold.Text = 粗体; this.cbBold

19、.UseVisualStyleBackColor = true; this.cbBold.CheckedChanged += new System.EventHandler(this.cbBold_CheckedChanged); / cbItalic this.cbItalic.AutoSize = true; this.cbItalic.Location = new System.Drawing.Point(50, 81); this.cbItalic.Name = cbItalic; this.cbItalic.Size = new System.Drawing.Size(48, 16)

20、; this.cbItalic.TabIndex = 4; this.cbItalic.Text = 斜体; this.cbItalic.UseVisualStyleBackColor = true; this.cbItalic.CheckedChanged += new System.EventHandler(this.cbItalic_CheckedChanged); / cbUnderline this.cbUnderline.AutoSize = true; this.cbUnderline.Location = new System.Drawing.Point(50, 121); t

21、his.cbUnderline.Name = cbUnderline; this.cbUnderline.Size = new System.Drawing.Size(60, 16); this.cbUnderline.TabIndex = 5; this.cbUnderline.Text = 下划线; this.cbUnderline.UseVisualStyleBackColor = true; this.cbUnderline.CheckedChanged += new System.EventHandler(this.cbUnderline_CheckedChanged); / ric

22、hTextBox1 this.richTextBox1.Location = new System.Drawing.Point(0, 0); this.richTextBox1.Name = richTextBox1; this.richTextBox1.Size = new System.Drawing.Size(640, 200); this.richTextBox1.TabIndex = 1; this.richTextBox1.Text = ; / Form1 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); t

23、his.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(641, 404); this.Controls.Add(this.richTextBox1); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = Form1; this.Text = Form1; this.

24、groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); (System.ComponentModel.ISupportInitialize)(this.numericUpDown1).EndInit(); this.ResumeLayout(false); #endregion private System.Window

25、s.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.RadioButton rbLishu; private System.Windows.Forms.RadioButton rbSongti; private System.Windows.Forms.NumericUpDown numericUpDown1; private System

26、.Windows.Forms.CheckBox cbUnderline; private System.Windows.Forms.CheckBox cbItalic; private System.Windows.Forms.CheckBox cbBold; private System.Windows.Forms.RichTextBox richTextBox1; 实验二 图形图像编程实验目的1 掌握Graphics类。2 掌握基本的绘图方法。3 掌握图像的显示和处理方法。实验内容完成画板应用。在窗体的空白处绘图,并将图片保存起来。实验代码:using System;using Syste

27、m.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Windraw public partial class Form1 : Form Graphics dc; Bitmap bmp = new Bitmap(800, 800); Point p0; Point p1; bool isPress = false; public Form1() Initializ

28、eComponent(); dc = Graphics.FromImage(bmp); private void button1_Click(object sender, EventArgs e) this.saveFileDialog1.Filter = BMP图片|*.bmp; if (this.saveFileDialog1.ShowDialog() = DialogResult.OK) this.bmp.Save(this.saveFileDialog1.FileName); private void drawImage() if (isPress) dc.DrawLine(Pens.

29、Red, p0, p1); this.pictureBox1.Image = bmp; private void pictureBox1_MouseDown(object sender, MouseEventArgs e) p0 = e.Location; isPress = true; private void pictureBox1_MouseMove(object sender, MouseEventArgs e) p1 = e.Location; drawImage(); p0 = p1; private void pictureBox1_MouseUp(object sender,

30、MouseEventArgs e) p1 = e.Location; drawImage(); isPress = false; Program:using System;using System.Collections.Generic;using System.Windows.Forms;namespace Windraw static class Program / 应用程序的主入口点。 STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingD

31、efault(false); Application.Run(new Form1(); Forml .designernamespace Windraw partial class Form1 / 必需的设计器变量。 private System.ComponentModel.IContainer components = null; / 清理所有正在使用的资源。 / 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) if (disposing & (components != null) c

32、omponents.Dispose(); base.Dispose(disposing); #region Windows 窗体设计器生成的代码 / 设计器支持所需的方法 - 不要 / 使用代码编辑器修改此方法的内容。 private void InitializeComponent() this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.button1 = new System.Windows.Forms.Button(); this.saveFileDialog1 = new System.Windows.Forms

33、.SaveFileDialog(); (System.ComponentModel.ISupportInitialize)(this.pictureBox1).BeginInit(); this.SuspendLayout(); / pictureBox1 this.pictureBox1.BackColor = System.Drawing.Color.White; this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Name = pictureBox1; this.pictureBox1.

34、Size = new System.Drawing.Size(517, 361); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_M

35、ouseMove); this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp); / button1 this.button1.Location = new System.Drawing.Point(0, 367); this.button1.Name = button1; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = 保存; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); / Form1 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; th

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

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号