2014年8月28日

[C#]列舉(enum)的使用

Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } enum Shape : int { Circle=0, Line=1, Arc=2 } private void Draw(int vType) { Graphics g; Pen p = new Pen(Color.Red); g = this.CreateGraphics(); g.Clear(Color.White); switch (vType) { case 0: g.DrawEllipse(p, 90, 30, 90, 90); break; case 1: g.DrawLine(p, 90, 50, 180, 100); break; case 2: g.DrawArc(p, 90, 30, 90, 90, 0, 250); break; default: MessageBox.Show("沒這個喔"); break; } } private void Draw(Shape vType) { Graphics g; Pen p = new Pen(Color.Red); g = this.CreateGraphics(); g.Clear(Color.White); switch (vType) { case Shape.Circle: g.DrawEllipse(p, 60, 30, 90, 90); break; case Shape.Line: g.DrawLine(p, 60, 50, 180, 100); break; case Shape.Arc: g.DrawArc(p, 60, 30, 90, 90, 0, 250); break; default: MessageBox.Show("沒這個喔"); break; } } private void BTN_Circle_Click(object sender, EventArgs e) { //Draw(0); Draw(Shape.Circle); } private void BTN_LINE_Click(object sender, EventArgs e) { //Draw(1); Draw(Shape.Line); } private void BTN_Arc_Click(object sender, EventArgs e) { //Draw(2); Draw(Shape.Arc); } } }

沒有留言:

張貼留言