日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

实验五 图形设计

發布時間:2023/12/1 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 实验五 图形设计 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

每復制一個方法都要綁定Paint事件

一、創建Windows窗體應用程序,要求如下:(源代碼+運行界面,缺少任一項為0分,源代碼只需粘貼繪制圖形代碼所在的方法,不用粘貼太多)

例如:

(1)添加一個窗體Form1,繪制兩個矩形,一個為藍色邊框,另一個為紅色邊框,如下圖所示。

using System; using System.Windows.Forms; using System.Drawing; private void Form1_Paint(object sender,PaintEventArgs e){/*Graphics obj = this.CreateGraphics();int x, y, w, h;x = 10; y = 10; w = 150; h = 150;obj.DrawLine(Pens.Blue, x, y, x+w, y);obj.DrawLine(Pens.Blue, x, y, x, y+h);obj.DrawLine(Pens.Blue, x + w, y, x + w, y + h);obj.DrawLine(Pens.Blue, x, y + h, x + w, y + h);Graphics obj1 = this.CreateGraphics();int x1, y1, w1, h1;x1 = 50; y1 = 50; w1 = 150; h1 = 150;obj.DrawLine(Pens.Red, x1, y1, x1 + w1, y1);obj.DrawLine(Pens.Red, x1, y1, x1, y1 + h1);obj.DrawLine(Pens.Red, x1 + w1, y1, x1 + w1, y1 + h1);obj.DrawLine(Pens.Red, x1, y1 + h1, x1 + w1, y1 + h1);*/Graphics gobj = this.CreateGraphics();Pen bluePen = new Pen(Color.Blue, 5);Pen redPen = new Pen(Color.Red, 5);Rectangle myRectangle = new Rectangle(50, 50, 100, 80);gobj.DrawRectangle(bluePen, 30, 20, 100, 80);gobj.DrawRectangle(redPen, myRectangle);}
(2)添加一個窗體Form2,繪制兩個填充餅形構成一個橢圓,如下圖所示。

using System; using System.Drawing; using System.Windows.Forms; private void Form2_Paint(object sender,PaintEventArgs s) {/*Graphics obj = this.CreateGraphics();Rectangle rec1 = new Rectangle(20, 20, 150, 90);obj.FillPie(Brushes.Red, rec1, 300, 60);//1點方向順時針60°Rectangle rec2 = new Rectangle(20, 20, 150, 90);obj.FillPie(Brushes.Blue,rec2,0,300);//3點方向順時針300°*/Graphics gobj = this.CreateGraphics();gobj.FillPie(Brushes.Blue, 30, 30, 130, 80, 0, 300);gobj.FillPie(Brushes.Red, 30, 30, 130, 80, 0, -60);}
(3)添加一個窗體Form3,繪制一個帶邊的填充橢圓,如下圖所示。

using System; using System.Drawing; using System.Windows.Forms; using System.Drawing.Drawing2D; private void Form3_Paint(object sender, PaintEventArgs e) {Graphics gobj = this.CreateGraphics();HatchBrush myBrush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Blue, Color.Green);Pen myPen = new Pen(Color.Red, 8);gobj.DrawEllipse(myPen, 20, 20, 150, 100);gobj.FillEllipse(myBrush, 20, 20, 150, 100); }
(4)添加一個窗體Form4,用不同的大小字體繪制3個文本,如下圖所示。

using System; using System.Drawing; using System.Windows.Forms; private void Form4_Paint(object sender, PaintEventArgs s)//加引用using System.Drawing.Drawing2D;{/*Graphics obj = this.CreateGraphics();StringFormat sf1 = new StringFormat();//StringFormat sf2 = new StringFormat();Font f1 = new Font("隸書",20,FontStyle.Bold);Font f2 = new Font("隸書", 5, FontStyle.Bold);HatchBrush obj1 = new HatchBrush(HatchStyle.Vertical,Color.Blue,Color.Green);SolidBrush obj2 = new SolidBrush(Color.Red);sf1.Alignment = StringAlignment.Far;//sf2.FormatFlags = StringFormatFlags.DirectionVertical;//豎直obj.DrawString("中華人民共和國",f1,obj1,220,15,sf1);obj.DrawString("中華人民共和國", f2, obj1, 300, 100, sf1);//obj.DrawString("中華人民共和國", f, obj2, 100, 5, sf1);*/int i;StringFormat strFormat;Font strFont;SolidBrush strBrush;Graphics gobj = this.CreateGraphics();for (i = 10; i <= 24; i += 6){strFormat = new StringFormat();strFont = new System.Drawing.Font("隸書", i);strBrush = new SolidBrush(Color.Red);gobj.DrawString("中華人民共和國", strFont, strBrush, 2 * i, 3 * i, strFormat);}}

二、創建Windows窗體應用程序,添加一個窗體Form1,添加3個命令按鈕,單擊時分別在窗體上畫一條直線、一個形狀和一個文本,如下圖所示。(源代碼+運行界面,缺少一項為0分,源代碼只需粘貼繪制圖形代碼所在的方法,不用粘貼太多)

private void button1_Click(object sender, EventArgs e) {Pen myPen = new Pen(System.Drawing.Color.Blue);Graphics gobj = this.CreateGraphics();gobj.DrawLine(myPen, 30, 30, 120, 120); }private void button2_Click(object sender, EventArgs e) {Pen myPen = new Pen(System.Drawing.Color.Blue);Graphics gobj = this.CreateGraphics();gobj.DrawEllipse(myPen, new Rectangle(30, 30, 100, 100)); }private void button3_Click(object sender, EventArgs e) {Graphics gobj = this.CreateGraphics();string drawString = "使用DrawString方法";Font myFont = new Font("黑體", 16);Brush b = new SolidBrush(System.Drawing.Color.Blue);float x = 30.0F;float y = 30.0F;StringFormat myFormat = new StringFormat();gobj.DrawString(drawString, myFont, b, x, y, myFormat); }

總結

以上是生活随笔為你收集整理的实验五 图形设计的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。