{"id":10162,"date":"2017-04-10T20:42:52","date_gmt":"2017-04-10T12:42:52","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=10162"},"modified":"2018-06-22T14:44:01","modified_gmt":"2018-06-22T06:44:01","slug":"visual-basic-2017-lesson-30-drawing-polygons-pies","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-30-drawing-polygons-pies\/","title":{"rendered":"Visual Basic 2017 Lesson 30: Drawing Polygons and Pies"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-29-drawing-text\/\">[Lesson 29] <\/a>&lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-tutorial\/\">[Contents]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-31-filling-shapes-color\/\">[Lesson 31]<\/a><\/h4>\n<p>We have learned how to create the Graphics and the Pen objects to draw rectangle, ellipse ,circle and text in the preceding lessons, now we shall learn how to draw polygons and pie in Visual basic 2017.<\/p>\n<h3>30.1: Drawing Polygons<\/h3>\n<p>Polygon is a closed plane figure bounded by three or more straight sides. In order to draw a polygon on the screen, we need to define the coordinates of all the points (also known as vertices) that joined up to form the polygon. The syntax to define the points of a polygon with vertices A1,A2,A3,A4\u2026\u2026.An is as follows;<\/p>\n<pre style=\"font-size: 100%;\">Dim A1 As New Point(X1,Y1)Dim A2 As New Point(X2,Y2)Dim A3 As New Point(X3,Y3)\r\nDim A4 As New Point(X4,Y4)\r\n.\r\n.\r\nDim An as New Point(Xn,Yn)\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"3393818013\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\nAfter declaring the points, we need to define a point structure that group all the points together using the following syntax:<\/p>\n<pre style=\"font-size: 110%;\">Dim myPoints As Point() = {A1, A2, A3,\u2026.,An} \r\n<\/pre>\n<p>Finally, create the graphics object and use the DrawPolygon method to draw the polygon using the following syntax:<\/p>\n<pre style=\"font-size: 100%;\">Dim myGraphics As Graphics = Me.CreateGraphics\r\nmyGraphics.DrawPolygon(myPen, myPoints)\r\n\r\n* myPen is the Pen object created using the following syntax:\r\n\r\nmyPen = New Pen(Drawing.Color.Blue, 5)\r\n<\/pre>\n<h4>Example 30.1 : Drawing a Triangle<\/h4>\n<p>A triangle is a polygon with three vertices. Here is the code:<\/p>\n<pre style=\"font-size: 110%;\">Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click\r\n\r\nDim myPen As Pen\r\nDim A As New Point(10, 10)\r\nDim B As New Point(100, 50)\r\nDim C As New Point(60, 150)\r\nDim myPoints As Point() = {A, B, C}\r\nmyPen = New Pen(Drawing.Color.Blue, 5)\r\nDim myGraphics As Graphics = Me.CreateGraphics\r\nmyGraphics.DrawPolygon(myPen, myPoints)\r\n\r\nEnd Sub\r\n<\/pre>\n<p>Running the program produces the image as shown in Figure 30.1<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg\" alt=\"\" width=\"50%\" height=\"auto\" \/><\/p>\n<p><strong>Figure 30.1<\/strong><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"3393818013\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 30.2: Drawing a Quadrilateral<\/h4>\n<p>A quadrilateral is a polygon consists of four sides,so you need to define four vertices. The code is as follows:<\/p>\n<pre style=\"font-size: 110%;\">Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click\r\n\r\nDim myPen As Pen Dim A As New Point(10, 10)\r\nDim B As New Point(100, 50)\r\nDim C As New Point(120, 150)\r\nDim D As New Point(60, 200)\r\nDim myPoints As Point() = {A, B, C, D}\r\nmyPen = New Pen(Drawing.Color.Blue, 5)\r\nDim myGraphics As Graphics = Me.CreateGraphics\r\nmyGraphics.DrawPolygon(myPen, myPoints)\r\n\r\nEnd Sub\r\n<\/pre>\n<p>The output image is as shown in Figure 29.2<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_2.jpg\" alt=\"\" width=\"50%\" height=\"auto\" \/><\/p>\n<h4 style=\"text-align: center;\">Figure 30.2<\/h4>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"3393818013\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3><strong>30.2: Drawing a Pie<\/strong><\/h3>\n<p>In order to draw a pie, you can use the DrawPie method of the graphics object. As usual, you need to create the Graphics and the Pen objects. The syntax for drawing a pie is:<\/p>\n<pre style=\"font-size: 100%;\">myGraphics.DrawPie(myPen, X, Y, width,height, StartAngle, SweepAngle)\r\n<\/pre>\n<p>Where X and Y are the coordinates the bounding rectangle, other arguments are self-explanatory. Both StartAngle and SweepAngle are measured in degree. SweepAngle can take possible or negative values. If the value is positive, it sweep through clockwise direction while negative means it sweep through anticlockwise direction.<\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-format=\"autorelaxed\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9961025909\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 30.3: Drawing a pie that starts with 0 degree and sweep clockwise through 60 degree.<\/h4>\n<pre style=\"font-size: 100%;\">Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click\r\n\r\nDim myPen As Pen myPen = New Pen(Drawing.Color.Blue, 5)\r\nDim myGraphics As Graphics = Me.CreateGraphics\r\nmyGraphics.DrawPie(myPen, 50,50, 150,150,0,60)\r\n\r\nEnd Sub\r\n<\/pre>\n<p>The output image is as shown in Figure 30.3<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_3.jpg\" alt=\"\" width=\"50%\" height=\"auto\" \/><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-format=\"autorelaxed\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9961025909\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-29-drawing-text\/\">[Lesson 29]\u00a0<\/a>&lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-tutorial\/\">[Contents]<\/a>\u00a0&gt;&gt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-31-filling-shapes-color\/\">[Lesson 31]<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 29] &lt;&lt; [Contents] &gt;&gt; [Lesson 31] We have learned how to create the Graphics and the Pen objects to draw rectangle, ellipse ,circle and text in the preceding lessons, now we shall learn how to draw polygons and pie in Visual basic 2017. 30.1: Drawing Polygons Polygon is a closed plane figure bounded by &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-30-drawing-polygons-pies\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2017 Lesson 30: Drawing Polygons and Pies<\/span><\/a><\/p>\n","protected":false},"author":23013,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-10162","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Visual Basic 2017 Lesson 30: Drawing Polygons and Pies - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"Learn how to draw polygons and pies in visual basic 2017\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2017 Lesson 30: Drawing Polygons and Pies - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"Learn how to draw polygons and pies in visual basic 2017\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html\" \/>\n<meta property=\"og:site_name\" content=\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Vbtutor\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-22T06:44:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@liewvk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-30-drawing-polygons-pies\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html\",\"name\":\"Visual Basic 2017 Lesson 30: Drawing Polygons and Pies - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg\",\"datePublished\":\"2017-04-10T12:42:52+00:00\",\"dateModified\":\"2018-06-22T06:44:01+00:00\",\"description\":\"Learn how to draw polygons and pies in visual basic 2017\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2017 Lesson 30: Drawing Polygons and Pies\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vbtutor.net\/#website\",\"url\":\"https:\/\/www.vbtutor.net\/\",\"name\":\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"description\":\"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Visual Basic 2017 Lesson 30: Drawing Polygons and Pies - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Learn how to draw polygons and pies in visual basic 2017","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2017 Lesson 30: Drawing Polygons and Pies - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"Learn how to draw polygons and pies in visual basic 2017","og_url":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html","og_site_name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","article_publisher":"https:\/\/www.facebook.com\/Vbtutor","article_modified_time":"2018-06-22T06:44:01+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-30-drawing-polygons-pies\/","url":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html","name":"Visual Basic 2017 Lesson 30: Drawing Polygons and Pies - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg","datePublished":"2017-04-10T12:42:52+00:00","dateModified":"2018-06-22T06:44:01+00:00","description":"Learn how to draw polygons and pies in visual basic 2017","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#primaryimage","url":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/lesson25_1.jpg"},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson30.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2017 Lesson 30: Drawing Polygons and Pies"}]},{"@type":"WebSite","@id":"https:\/\/www.vbtutor.net\/#website","url":"https:\/\/www.vbtutor.net\/","name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/10162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/users\/23013"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=10162"}],"version-history":[{"count":16,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/10162\/revisions"}],"predecessor-version":[{"id":13006,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/10162\/revisions\/13006"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=10162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=10162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=10162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}