VB.NET tutorial-VB.NET draw text


VB.NET drawing text

In VB, text and other shapes can be drawn on a form or on other controls. To draw text or shapes on a control, you can use the Graphics structure. It contains different kinds of shapes and other tools needed in drawing work.

For the first page about drawing in VB, you will learn to display English words on the form by sing DrawString(Text,Font,Brush,Point).

Example: drawing text on the form


Public Class Form1
   
    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       
      'Text to draw
        Dim st As String = "Drawing in VB!"
        Dim st1 As String = "Drawing is funny."
        'Create font object
        'Create brush object
        Dim f As New Font("Courier New", 30, FontStyle.Bold)
        Dim br As New SolidBrush(Color.Coral)
        'Create point objects
        Dim pt As New Point(100, 100)
        Dim pt1 As New Point(100, 150)
        'Ready to draw nice text
        e.Graphics.DrawString(st, f, br, pt)
        e.Graphics.DrawString(st1, f, br, pt1)
 
    End Sub
 
End Class

VB.NET example code to draw text




Comments

CAPTCHA image




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.