{"id":7248,"date":"2015-10-11T22:02:34","date_gmt":"2015-10-11T14:02:34","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=7248"},"modified":"2018-06-22T22:17:04","modified_gmt":"2018-06-22T14:17:04","slug":"visual-basic-2015-lesson-29-drawing-text","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-29-drawing-text\/","title":{"rendered":"Visual Basic 2015 Lesson 29: Drawing Text"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-28-creating-ellipses-circles\/\">[Lesson 28]<\/a> &lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents] <\/a>&gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-30-drawing-polygons-pies\/\">[Lesson 30]<\/a><\/h4>\n<p>We have learned how to draw rectangle, ellipse, and circle in visual basic 2015 in the preceding lessons, now we shall learn how to draw text on the screen. Yes, instead of using the Print command, you can also draw text on the screen.<\/p>\n<h3><strong>29.1 Drawing Text<\/strong><\/h3>\n<p>To draw text on the screen, we can use the DrawString method. The syntax is as follows:<\/p>\n<pre style=\"font-size: 110%;\">myGraphics.DrawString(myText, myFont, mybrush, X , Y)<\/pre>\n<p>*myGraphics is the Graphics object, myText is the text you wish to display on the screen, myFont is the font object created by you, myBrush is the brush style created by you and X, Y are the coordinates of the upper left corner of the Text.<\/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=\"4768455349\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\nYou can create the Font object in visual basic 2015 using the following statement:<\/p>\n<pre style=\"font-size: 110%;\">myFont = New System.Drawing.Font(\u201cVerdana\u201d, 20)<\/pre>\n<p>Where the first argument of the font is the font typeface, and the second argument is the font size. You can add a third argument as font style, either bold, italic, underline.<\/p>\n<p>Here are the examples:<\/p>\n<pre style=\"font-size: 110%;\">myFont = New System.Drawing.Font(\u201cVerdana\u201d, 20, FontStyle.Bold)myFont = New System.Drawing.Font(\u201cVerdana\u201d, 20, FontStyle.Underline)\r\nmyFont = New System.Drawing.Font(\u201cVerdana\u201d, 20, FontStyle.Italic)\r\nmyFont = New System.Drawing.Font(\u201cVerdana\u201d, 20, FontStyle.Regular)\r\n<\/pre>\n<p>To create your Brush object, you can use the following statement:<\/p>\n<pre style=\"font-size: 110%;\">Dim myBrush As Brush\r\nmyBrush = New Drawing.SolidBrush(Color.BrushColor)\r\n<\/pre>\n<p>Besides the seven colors, some of the common Brush Colors are AliceBlue, AquaMarine Beige, DarkMagenta, DrarkOliveGreen, SkyBlue and more. You don\u2019t have to remember the names of all the colors, the IntelliSense will let you browse through the colors in a drop-down menu once you type the dot after the word Color.<\/p>\n<p>Now we shall proceed to draw the font using the sample code below:<\/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=\"4768455349\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 29.1<\/h4>\n<pre style=\"font-size: 110%;\">Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click\r\nDim myGraphics As Graphics = Me.CreateGraphics\r\nDim myFont As Font\r\nDim myBrush As Brush\r\n myBrush = New Drawing.SolidBrush(Color.DarkOrchid)\r\n myFont = New System.Drawing.Font(\"Verdana\", 20, FontStyle.Underline)\r\n myGraphics.DrawString(\"Visual Basic 2015\", myFont, myBrush, 10, 10)\r\nEnd Sub\r\n<\/pre>\n<p>The runtime interface is as shown in Figure 29.1<br \/>\n<a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7253 aligncenter\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg\" alt=\"vb2015_fig29.1\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg 300w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1-150x150.jpg 150w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1-144x144.jpg 144w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">\u00a0<strong>Figure 29.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=\"4768455349\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\nThe preceding example can be modified if you don\u2019t want to create the Font and the Brush objects. You can use the font of an existing object such as the Form and the System Colors. Replace the last line in the preceding example with this line(you need to delete the lines that create the Brush and the Font objects as well)<\/p>\n<p>myGraphics.DrawString(\u201cVisual Basic 2015\u2033, me.Font, System.Drawing.Brushes.DarkOrchid, 10, 10)<\/p>\n<p>You can also add an InputBox which let the user enter his or her message then display the message on the screen.<\/p>\n<p>This is shown in Example 29.2<\/p>\n<p><strong>Example 29.2<\/strong><\/p>\n<pre style=\"font-size: 110%;\">Dim myGraphics As Graphics = Me.CreateGraphics\r\nDim myFont As Font\r\nDim myBrush As Brush\r\nDim userMsg As String\r\n userMsg = InputBox(\u201cWhat is your message?\u201d, \u201cMessage Entry Form\u201d, \u201cEnter your message here\u201d, 100, 200)\r\n myBrush = New Drawing.SolidBrush(Color.DarkOrchid)\r\n myFont = New System.Drawing.Font(\u201cVerdana\u201d, 20, FontStyle.Underline)\r\n myGraphics.DrawString(userMsg, myFont, myBrush, 10, 10)\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"5090773108\"><\/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-2015-lesson-28-creating-ellipses-circles\/\">[Lesson 28]<\/a>\u00a0&lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]\u00a0<\/a>&gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-30-drawing-polygons-pies\/\">[Lesson 30]<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 28] &lt;&lt; [Contents] &gt;&gt; [Lesson 30] We have learned how to draw rectangle, ellipse, and circle in visual basic 2015 in the preceding lessons, now we shall learn how to draw text on the screen. Yes, instead of using the Print command, you can also draw text on the screen. 29.1 Drawing Text To &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-29-drawing-text\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2015 Lesson 29: Drawing Text<\/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-7248","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 2015 Lesson 29: Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This article illustrates how to draw text on the form in visual basic 2015\" \/>\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\/vb2015\/vb2015_lesson29.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2015 Lesson 29: Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This article illustrates how to draw text on the form in visual basic 2015\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.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-22T14:17:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.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-2015-lesson-29-drawing-text\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html\",\"name\":\"Visual Basic 2015 Lesson 29: Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg\",\"datePublished\":\"2015-10-11T14:02:34+00:00\",\"dateModified\":\"2018-06-22T14:17:04+00:00\",\"description\":\"This article illustrates how to draw text on the form in visual basic 2015\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2015 Lesson 29: Drawing Text\"}]},{\"@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 2015 Lesson 29: Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This article illustrates how to draw text on the form in visual basic 2015","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\/vb2015\/vb2015_lesson29.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2015 Lesson 29: Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This article illustrates how to draw text on the form in visual basic 2015","og_url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.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-22T14:17:04+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.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-2015-lesson-29-drawing-text\/","url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html","name":"Visual Basic 2015 Lesson 29: Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg","datePublished":"2015-10-11T14:02:34+00:00","dateModified":"2018-06-22T14:17:04+00:00","description":"This article illustrates how to draw text on the form in visual basic 2015","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/10\/vb2015_fig29.1.jpg","width":300,"height":300},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson29.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2015 Lesson 29: Drawing Text"}]},{"@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\/7248","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=7248"}],"version-history":[{"count":30,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/7248\/revisions"}],"predecessor-version":[{"id":13045,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/7248\/revisions\/13045"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=7248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=7248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=7248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}