C#相关程序设计.docx
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《C#相关程序设计.docx》由会员分享,可在线阅读,更多相关《C#相关程序设计.docx(92页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、相关程序设计、实现个Window窗体应用程序,可以实现画圆、计算、画五环与填充颜色的功能代码部分创建一个新类,名叫DrawPic.csusing System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Text;namespace CaseOlclass DrawPic(#region 属性字段坐标值private int x;public int X(get return x;set if (value = 300)x = 150;elsex = value;)pr
2、ivate int y;public int Y(get return y;set(if (value 130)y = 100;elsey = value;)字段宽高private int p_width;public int P_widthget return p_wi出h;setif (value = 380)p_width - 200;elsep_width = value;)private int p_height;public int P_height(get return p_height;set(if (value = 160)p_height = 200;elsep_heigh
3、t = value;)/结构颜色Color c_color;const double pi = 3.14F;#endregion#region构造函数public DrawPic()()III /指定坐标和寛高/ III x 坐标值III y 坐标值III 宽度III 咼度 public DrawPic(string X,string Y,string P_width,stringP_height)(this.X = int.Parse(X);this.Y = int.Parse(Y);this.P_width = int.Parse(P_width);this.P_height = int.
4、Parse(P_height);)III Ill指定坐标和宽高构造函数重载III / x 坐标值/ y 坐标值/ 宽度III 咼度 / 颜色 public DrawPic(string X, string Y, string P_width, stringP_height, Color colors)(this.X = int.Parse(X);this.Y = int.Parse(Y);this.P_width = int.Parse(P_width);this.P_height = int.Parse(P_height);this.c_color = colors;)#endregionI
5、II III实现画圆III III 所需画圆的窗体public void DrawCircle(System.Windows.Forms.Form f)在窗体上绘制个画图图面(画布) Graphics g = f.CreateGraphics();创造个画笔指定画笔颜色及画笔宽度Pen pen = new Pen(Color.Black, 3);/指定画出的图形质量使用消除锯齿 g.SmoothingModeSystem.Drawing. Drawing2D.SmoothingMode. AntiAlias;/使用画笔画圆g.DrawEllipse(pen,newRectangle(x,y,p
6、_width,p_height);/释放画布 g.Dispose();/释放画笔 pen.Dispose();)public void FillColor(System.Windows.Forms.Form f) (Graphics g = f.CreateGraphics();Pen pen = new Pen(Color.Black, 3);g.SmoothingModeSystem.Drawing. Drawing2D.SmoothingMode. AntiAlias;g.lnterpolationMode System.Drawing. Drawing2D.lnterpolationM
7、ode. High;定义个使用颜色的填充对象Brush b = new SolidBrush(c_color);/填充一个形状在固定的坐标上g.FillEllipse(b, x + 1.5F, y + 1.5F, p_height - 3, p_wi出h - 3);g.Dispose();pen.Dispose();)public string getResult( int d)(double c = pi * d;double s = pi * (d / 2) * (d / 2);return string.Format(当前圆的周长是0:F2,面积是 1:F2!, c, s);)二、关于属
8、性的使用创建一Window窗体应用程序例子:学生年龄输入合法性的判断(成功实现)1、关于Form1.cs查看代码可得:using System;using System.Collections.Generic;using System.ComponentModel;using Sy stem. Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Case02(public partial class Forml : Form(public Forml
9、 ()(lnitializeComponent();)private void btnMsg_Click(object sender, EventArgs e)(student myStudent = new student();myStudent.Age = int.Parse(txtAge.Text.Trim();MessageBox.Show(stri ng. Format(年龄是:0,myStudent.Age.ToString(),显示年龄,MessageBoxButtons.OK, MessageBoxIcon. Information);/myStudent.Name = zan
10、e;/string grade = myStudent.Grade;private void btnNo_Click(object sender, EventArgs e)MessageBox.Show(该用户的今年、t + txtAge.Text + T岁,显示年龄, MessageBoxButtons.OK,MessageBoxIcon. Information);)2、添加类 student.esusing System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Case0
11、2 (class studentprivate int age;public int Ageget return age;set(if (value 0 & value 110)(age = value;)elseage = 18;)private string name;III III只读/ public string Nameget return name;)private string grade;III III只写III public string Grade(set grade = value;)三、参数的值传递(使用ref与。ut进行)自定义计算税后资事例:资计税的方法为:低于等于
12、3500不计税,超出3500的部分按10%缴税查看form.cs的代码加以编写using System;using System.Collections.Generic;using System.ComponentModel;using Sy stem. Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Case03(public partial class Forml : Form(public Forml ()(lnitializeCompon
13、ent();private void btnAccount_Click(object sender, EventArgs e) (int pay = int.Parse(txtPay.Text.Trim();double result = 0.00F;getResult(ref pay, out result);MessageBox.Show(string.Format(您的工资总额是:0n超出起征点1 :F2元n应缴纳2:F2元个人所得税 ,txtPay.Text.Trim(),pay,result),税 率 计 算,MessageBoxButtons.OK, MessageBoxIcon.
14、Information);private void getResult(ref int pay, out double result)pay -= 3500;if (pay = 1500 & pay = 4500 & pay = 9000 & pay = 35000 & pay = 55000 & pay 80000)(result = pay * 0.35F;)else(result = pay * 0.45F;)四、构造函数的使用应先添加Window窗体,代码如下:using System;using System.Collections.Generic;using System.Comp
15、onentModel;using Sy stem. Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Case04public partial class MainForm : Form(public MainForm()lnitializeComponent();)private void btnExit_Click(object sender, EventArgs e)(this.Close();)private void btnTestStudentClass_Click(ob
16、ject sender, EventArgs e)(/Student zhang = new Student();/zhang.Name =张靓靓;/zhang. Age = 20;/zhang. Hobby =唱歌歌;Student scofield = new Student(Scofield, 28,越狱狱)Student zhang = new Student(张靓靓、 20,唱歌歌);Student jay = new Student(周杰杰,21,耍双节棍棍 );/Student scofield = new Student(Scofield);scofield.SayHi();z
17、hang.SayHi();jay.SayHi();)事例:学生的自我介绍,代码如下:Student.cs 代码using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;namespace Case04class Studentpublic Student() public Student(string name)(this.Name = name;)public Student(string name, int age, string hobby)(this.Name =
18、 name;this.Age = age;this.Hobby = hobby;)/ III姓名III private string name;public string Nameget return name;set name = value;Ill /年龄/ private int age;public int Ageget return age;set(属性是聪明的字段if (value 0 & value 100)(age = value;)else(age = 18;)/ /Z爱好Ill private string hobby;public string Hobby(get ret
19、urn hobby;set hobby = value;)public void SayHi()(string message;message = string.Format(大家好,我是0同学,今年1岁了,我喜欢2 ,name, this.age, this.hobby);MessageBox.Show(message);)五、应先添加Windows图体(MainForm.es査看代码并进行编辑)使用构造函数实例化1、StriictStudent.cs 的代码如下using System;using System.Collections.Generic;using System.Text;u
20、sing System.Windows.Forms;namespace CaseStructpublic enum Genders(Male, Female)结构版Studentstruct StructStudent(public string Name;public Genders Gender;public int Age;public string Hobby;public int Popularity;public StructStudent(string name, Genders gender, int age, string hobby): this(name, gender,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 相关 程序设计
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内