使用C#怎么繪制一個(gè)象棋棋盤?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),南靖企業(yè)網(wǎng)站建設(shè),南靖品牌網(wǎng)站建設(shè),網(wǎng)站定制,南靖網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,南靖網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Chinese_chessboard { public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); } private void FrmMain_Paint(object sender, PaintEventArgs e) { if (!File.Exists(Application.StartupPath + @"\" + "bg.jpg")) { MessageBox.Show("請(qǐng)把素材中的bg.jpg圖片文件放到可執(zhí)行程序相同文件夾中,并重新啟動(dòng)程序!", "提示"); Application.Exit(); } Console.WriteLine("C#編程交流群:485532597"); Graphics g = e.Graphics; // 獲取一個(gè)Graphics對(duì)象 g.Clear(Color.Coral); //用珊瑚色清除窗體 Font font1 = new Font("黑體", 25, FontStyle.Regular); int s = (int)(font1.Size / 0.6); int s2 = (int)font1.Height; Image img = Image.FromFile("bg.jpg"); g.DrawImage(Image.FromFile(Application.StartupPath + @"\" + "bg.jpg"), 10, 10, 430, 480); //繪制背景圖 g.DrawRectangle(new Pen(Color.Black, 3), new Rectangle(new Point(20, 20), new Size(410, 460))); //繪制框圖 Pen pen = new Pen(Color.Black, 1); //繪制水平線 for (int i = 0; i < 10; i++) { g.DrawLine(pen, new Point(25, 25 + (i * 50)), new Point(425, 25 + (i * 50))); } //繪制垂直線 for (int i = 0; i < 9; i++) { g.DrawLine(pen, new Point(25 + (i * 50), 25), new Point(25 + (i * 50), 225)); g.DrawLine(pen, new Point(25 + (i * 50), 275), new Point(25 + (i * 50), 475)); } //return; //繪制將士位置斜線 g.DrawLine(pen, new Point(175, 25), new Point(275, 125)); g.DrawLine(pen, new Point(275, 25), new Point(175, 125)); g.DrawLine(pen, new Point(175, 375), new Point(275, 475)); g.DrawLine(pen, new Point(175, 475), new Point(275, 375)); //兵位(炮位)線,只畫一個(gè) g.DrawLine(pen, new Point(30, 160), new Point(30, 170)); g.DrawLine(pen, new Point(30, 170), new Point(40, 170)); g.DrawLine(pen, new Point(30, 180), new Point(30, 190)); g.DrawLine(pen, new Point(30, 180), new Point(40, 180)); g.DrawString("楚 河", new Font("黑體", 25), Brushes.Black, new Point(50, 235)); g.TranslateTransform(300, 235); //平移坐標(biāo)軸 g.RotateTransform(180); //進(jìn)行180度旋轉(zhuǎn) g.DrawString("漢 界", new Font("黑體", 25), Brushes.Black, new Point(-100, -35)); g.ResetTransform(); //坐標(biāo)軸復(fù)位 this.DrawAngle(g, pen, new Point(125, 175), "all"); this.DrawAngle(g, pen, new Point(425, 175), "left"); this.DrawAngle(g, pen, new Point(225, 175), "all"); this.DrawAngle(g, pen, new Point(425, 175), "left"); this.DrawAngle(g, pen, new Point(325, 175), "all"); this.DrawAngle(g, pen, new Point(425, 175), "left"); this.DrawAngle(g, pen, new Point(75, 125), "all"); this.DrawAngle(g, pen, new Point(375, 125), "all"); this.DrawAngle(g, pen, new Point(25, 325), "right"); this.DrawAngle(g, pen, new Point(125, 325), "all"); this.DrawAngle(g, pen, new Point(225, 325), "all"); this.DrawAngle(g, pen, new Point(325, 325), "all"); this.DrawAngle(g, pen, new Point(425, 325), "left"); this.DrawAngle(g, pen, new Point(75, 375), "all"); this.DrawAngle(g, pen, new Point(375, 375), "all"); g.Dispose(); //釋放對(duì)象 } private void DrawAngle(Graphics g,Pen pen, Point point,string str) { Point p1 = new Point(point.X + 5, point.Y + 5); Point p2= new Point(point.X - 5, point.Y + 5); Point p3= new Point(point.X -5, point.Y - 5); Point p4 = new Point(point.X +5, point.Y -5); if(str=="right"||str=="all") { //p1 p4 g.DrawLine(pen, p1, new Point(p1.X + 10, p1.Y)); g.DrawLine(pen, p1, new Point(p1.X, p1.Y+10)); g.DrawLine(pen, p4, new Point(p4.X + 10, p4.Y)); g.DrawLine(pen, p4, new Point(p4.X, p4.Y-10)); } if(str=="left" || str == "all") { //p2 p3 g.DrawLine(pen, p2, new Point(p2.X - 10, p2.Y)); g.DrawLine(pen, p2, new Point(p2.X, p2.Y+10)); g.DrawLine(pen, p3, new Point(p3.X - 10, p3.Y)); g.DrawLine(pen, p3, new Point(p3.X, p3.Y - 10)); } } } }
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。