{"id":2571,"date":"2013-02-15T10:29:43","date_gmt":"2013-02-15T02:29:43","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2018-06-24T18:18:17","modified_gmt":"2018-06-24T10:18:17","slug":"visual-basic-2012-lesson-24","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-24\/","title":{"rendered":"Visual Basic 2012 Lesson 24\u2013 Drawing Text"},"content":{"rendered":"<h4 style=\"text-align: center;\"><!-- table,th,td { vertical-align:top; } --><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-23\/\">[Lesson 23]<\/a> <\/strong>&lt;&lt;\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-25\/\"> [Lesson 25]<\/a><\/strong><\/h4>\n<h3>24.1 Drawing Text<\/h3>\n<p>In this lesson, let&#8217;s learn how to draw text on the screen. In order to draw text on the screen, we can use the DrawString method. The syntax is as follows:<\/p>\n<pre style=\"font-size: 110%; width: 80%;\">myGraphics.DrawString(myText, myFont, mybrush, X , Y)<\/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=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p>Where 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.You can create the Font object in visual basic 2012 using the following statement:<\/p>\n<pre style=\"font-size: 110%; width: 70%;\">myFont = New System.Drawing.Font(\"Verdana\", 20)\r\n<\/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. Here are the examples:<\/p>\n<pre style=\"font-size: 110%; width: 90%;\">myFont = New System.Drawing.Font(\"Verdana\", 20, FontStyle.Bold)\r\nmyFont = New System.Drawing.Font(\"Verdana\", 20, FontStyle.Underline)\r\nmyFont = New System.Drawing.Font(\"Verdana\", 20, FontStyle.Italic)\r\nmyFont = New System.Drawing.Font(\"Verdana\", 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%; width: 70%;\">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&#8217;t 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<h4>Example 24.1<\/h4>\n<pre style=\"font-size: 110%; width: 90%;\">Dim 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 2012\", myFont, myBrush, 10, 10)\r\n<\/pre>\n<p>Run the program above and you can see the following output:<br \/>\n<a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4996\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg\" alt=\"vb2012_figure24.1\" width=\"300\" height=\"300\" \/><\/a><br \/>\n<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=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p>The preceding can be modified if you don&#8217;t 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(&#8220;Visual Basic 2012&#8221;, 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 24.2<\/p>\n<h4>Example 24.2<\/h4>\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(\"What is your message?\", \"Message Entry Form\", \"Enter your message here\", 100, 200)\r\n myBrush = New Drawing.SolidBrush(Color.DarkOrchid)\r\n myFont = New System.Drawing.Font(\"Verdana\", 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\" style=\"display: block;\" data-ad-format=\"autorelaxed\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"6598395509\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><strong><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-23\/\">[Lesson 23]<\/a> <\/strong>&lt;&lt;\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-25\/\"> [Lesson 25]<\/a><\/strong><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 23] &lt;&lt;\u00a0[CONTENTS] &gt;&gt; [Lesson 25] 24.1 Drawing Text In this lesson, let&#8217;s learn how to draw text on the screen. In order to draw text on the screen, we can use the DrawString method. The syntax is as follows: myGraphics.DrawString(myText, myFont, mybrush, X , Y) Where myGraphics is the Graphics object, myText is the &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-24\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2012 Lesson 24\u2013 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-2571","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 2012 Lesson 24\u2013 Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This visual basic 2012 lesson shows user about drawing text in visual basic 2012\" \/>\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\/vb2012\/vb2012_lesson24.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2012 Lesson 24\u2013 Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This visual basic 2012 lesson shows user about drawing text in visual basic 2012\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.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-24T10:18:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.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=\"2 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-2012-lesson-24\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html\",\"name\":\"Visual Basic 2012 Lesson 24\u2013 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\/vb2012\/vb2012_lesson24.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg\",\"datePublished\":\"2013-02-15T02:29:43+00:00\",\"dateModified\":\"2018-06-24T10:18:17+00:00\",\"description\":\"This visual basic 2012 lesson shows user about drawing text in visual basic 2012\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2012 Lesson 24\u2013 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 2012 Lesson 24\u2013 Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This visual basic 2012 lesson shows user about drawing text in visual basic 2012","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\/vb2012\/vb2012_lesson24.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2012 Lesson 24\u2013 Drawing Text - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This visual basic 2012 lesson shows user about drawing text in visual basic 2012","og_url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.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-24T10:18:17+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-24\/","url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html","name":"Visual Basic 2012 Lesson 24\u2013 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\/vb2012\/vb2012_lesson24.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg","datePublished":"2013-02-15T02:29:43+00:00","dateModified":"2018-06-24T10:18:17+00:00","description":"This visual basic 2012 lesson shows user about drawing text in visual basic 2012","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012_figure24.1.jpg","width":300,"height":300},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson24.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2012 Lesson 24\u2013 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\/2571","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=2571"}],"version-history":[{"count":33,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2571\/revisions"}],"predecessor-version":[{"id":13116,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2571\/revisions\/13116"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=2571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=2571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=2571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}