'Add reference to below dlls

Public Function picText_Paint(text As String, sizeX As Integer, sizeY As Integer, resolution As Integer, LineSpacing As Single, ExtraParagraphSpacing As Single, font As System.Drawing.Font, TextMargin As System.Windows.Forms.Padding, colorBrush As System.Drawing.Brush) As Byte()
    'Create a temporary bitmap in memory to use as the drawing surface. Use provided size (in Px) taking difference between desired
    'resolution and default screen based resolution. This should provide a better quality image for printing without using all of the
    'machine's memory to render the image.
 
    'If an error occurs due to the image sizing and memory, a "can't load this image" x will appear in this image's place on report
 
    sizeX *= (resolution / 96)
    sizeY *= (resolution / 96)
 
    Dim bmp As New System.Drawing.Bitmap(sizeX, sizeY, Drawing.Imaging.PixelFormat.Format32bppArgb)
    bmp.SetResolution(resolution, resolution)
 
    'Create the graphics object for drawing from that temp bitmap and blank out the background.
    Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)
 
    'Set high quality rendering all around. If not smooth enough, try killing transparent background by clearing graphics with white.
    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
    g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
    g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
    g.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality
 
 
    ' Draw within a rectangle excluding the margins.
    Dim rect As New System.Drawing.RectangleF(TextMargin.Left, TextMargin.Top, sizeX - TextMargin.Left - TextMargin.Right, sizeY - TextMargin.Top - TextMargin.Bottom)
 
    'Draw the paragraphs of the provided text. This will split and loop using carriage return/line feed.
    rect = DrawParagraphs(g, rect, font, colorBrush, text, LineSpacing, 0, ExtraParagraphSpacing)
 
    'Use a memory stream to write the bitmap to an array of bytes
    Dim stream As System.IO.MemoryStream = New IO.MemoryStream
    Dim bitmapBytes As Byte()
 
    bmp.Save(stream, Drawing.Imaging.ImageFormat.Png)
    bitmapBytes = stream.ToArray
    stream.Dispose()
    bmp.Dispose()
    g.Dispose()
    Return bitmapBytes
 
End Function

Private Function DrawParagraphs(gr As System.Drawing.Graphics, rect As System.Drawing.RectangleF, font As System.Drawing.Font, brush As System.Drawing.Brush, text As String, line_spacing As Single, indent As Single, paragraph_spacing As Single) As System.Drawing.RectangleF
    ' Split the text into paragraphs.
    Dim paragraphs As String() = text.Split(ControlChars.Lf)
 
    ' Draw each paragraph.
    For Each paragraph As String In paragraphs
        ' Draw the paragraph keeping track of remaining space.
        rect = DrawParagraph(gr, rect, font, brush, paragraph,
        line_spacing, indent, paragraph_spacing)
 
        ' See if there's any room left.
        If rect.Height < gr.MeasureString("Hi", font).Height Then
            Exit For
        End If
    Next
 
    Return rect
End Function

Private Function DrawParagraph(gr As System.Drawing.Graphics, rect As System.Drawing.RectangleF, font As System.Drawing.Font, brush As System.Drawing.Brush, text As String, line_spacing As Single, indent As Single, extra_paragraph_spacing As Single) As System.Drawing.RectangleF
        ' Get the coordinates for the first line.
        Dim y As Single = rect.Top
 
        ' Break the text into words.
        Dim words As String() = text.Split(" "c)
        Dim start_word As Integer = 0
        Dim fh As Single
 
        ' Repeat until we run out of text or room.
        While True
            ' See how many words will fit.
            ' Start with just the next word.
            Dim line As String = words(start_word)
 
            ' Add more words until the line won't fit.
            Dim end_word As Integer = start_word + 1
            While end_word < words.Length
                ' See if the next word fits.
                Dim test_line As String = (line & Convert.ToString(" ")) + words(end_word)
                Dim line_size As System.Drawing.SizeF = gr.MeasureString(test_line, font)
                fh = line_size.Height
                If line_size.Width + indent > rect.Width Then
                    ' The line is too wide. Don't use the last word.
                    end_word -= 1
                    Exit While
                Else
                    ' The word fits. Save the test line.
                    line = test_line
                End If
 
                ' Try the next word.
                end_word += 1
            End While
 
            ' See if this is the last line in the paragraph.
            If (end_word = words.Length) Then
                ' This is the last line. Don't justify it.
                DrawLine(gr, line, font, brush, rect.Left + indent, y,
                rect.Width - indent, False)
            Else
                ' This is not the last line. Justify it.
                DrawLine(gr, line, font, brush, rect.Left + indent, y,
                rect.Width - indent, True)
            End If
 
            ' Move down to draw the next line.
            y += fh * line_spacing
 
            ' Make sure there's room for another line.
            If fh > rect.Height Then
                Exit While
            End If
 
            ' Start the next line at the next word.
            start_word = end_word + 1
            If start_word >= words.Length Then
                Exit While
            End If
 
            ' Don't indent subsequent lines in this paragraph.
            indent = 0
        End While
 
        ' Add a gap after the paragraph.
        y += fh * extra_paragraph_spacing
 
        ' Return a RectangleF representing any unused
        ' space in the original RectangleF.
        Dim height As Single = rect.Bottom - y
        If height < 0 Then
            height = 0
        End If
        Return New System.Drawing.RectangleF(rect.X, y, rect.Width, height)
    End Function

Private Sub DrawLine(gr As System.Drawing.Graphics, line As String, font As System.Drawing.Font, brush As System.Drawing.Brush, x As Single, y As Single,
width As Single, justification As Boolean)
    ' Make a rectangle to hold the text.
    Dim rect As New System.Drawing.RectangleF(x, y, width, gr.MeasureString(line, font).Height)
 
 
 
    ' See if we should use full justification.
    If justification Then
        ' Justify the text.
        Dim words As String() = line.Split(" "c)
 
        ' Add a space to each word and get their lengths.
        Dim word_width As Single() = New Single(words.Length - 1) {}
        Dim total_width As Single = 0
        For i As Integer = 0 To words.Length - 1
            ' See how wide this word is.
            Dim size As System.Drawing.SizeF = gr.MeasureString(words(i), font)
            word_width(i) = size.Width
            total_width += word_width(i)
        Next
 
        ' Get the additional spacing between words.
        Dim extra_space As Single = rect.Width - total_width
        Dim num_spaces As Integer = words.Length - 1
        If words.Length > 1 Then
            extra_space /= num_spaces
        End If
 
        ' Draw the words.
        Dim x1 As Single = rect.Left
        Dim y1 As Single = rect.Top
 
        For i As Integer = 0 To words.Length - 1
            ' Draw the word.
            gr.DrawString(words(i), font, brush, x1, y1)
 
            ' Move right to draw the next word.
            x1 += word_width(i) + extra_space
 
        Next
    Else
        ' Make a StringFormat to align the text.
        Using sf As New System.Drawing.StringFormat()
            ' Use the appropriate alignment.
            sf.Alignment = System.Drawing.StringAlignment.Near
            gr.DrawString(line, font, brush, rect, sf)
 
 
        End Using
    End If
End Sub 

Visual basic (VB.net) Online Compiler

Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net. OneCompiler also has reference programs, where you can look for the sample code to get started with.

Read input from STDIN in VB.net

OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.

Public Module Program
	Public Sub Main(args() As string)
	 Dim name as String = Console.ReadLine()    ' Reading input from STDIN
   Console.WriteLine("Hello " & name)           ' Writing output to STDOUT
	End Sub
End Module

About VB.net

Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.

Key Features

  • Beginner's friendly language.
  • Simple and object oriented programming language.
  • User friendly language and easy to develop GUI based applications.

Syntax help

Variables

Variable is a name given to the storage area in order to identify them in our programs.

Simple syntax of Variable declaration is as follows

Dim variableName [ As [ New ] dataType ] [ = initializer ]

Variable initialization

variableName = value

Conditional Statements

1. If

If condition-expression Then 
    'code
End If

2. If-else

If(conditional-expression)Then
   'code if the conditional-expression is true 
Else
  'code if the conditional-expression is false 
End If

3. If-else-if ladder

If(conditional-expression)Then
   'code if the above conditional-expression is true 
Else If(conditional-expression) Then
        'code if the above conditional-expression is true 
    Else
        'code if the above conditional-expression is false 
End If

4. Nested-If

If(conditional-expression)Then
   'code if the above conditional-expression is true
   If(conditional-expression)Then
         'code if the above conditional-expression is true 
   End If
End If

5. Select Case

Select [ Case ] expression
   [ Case expressionlist
      'code ]
   [ Case Else
      'code ]
End Select

Loops

1. For..Next

For counter [ As datatype ] = begin To end [ Step step ]
   'code
   [ Continue For ]
   'code
   [ Exit For ]
   'code
Next [ counter ]

2. For..Each

For Each element [ As datatype ] In group
   'code
   [ Continue For ]
   'code
   [ Exit For ]
   'code
Next [ element ]

3. While

While conditional-expression
   'Code 
   [ Continue While ]
   'Code
   [ Exit While ]
   'Code
End While

4. Do-while

Do { While | Until } conditional-expression
   'Code
   [ Continue Do ]
   'Code
   [ Exit Do ]
   'Code
Loop
Do
   'Code
   [ Continue Do ]
   'Code
   [ Exit Do ]
   'Code
Loop { While | Until } conditional-expression

Procedures

Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

Procedures are of two types.

1. Functions

Functions return a value when they are called.

[accessModifiers] Function functionName [(parameterList)] As returnType
   'code
End Function

2. Sub-Procedures

Sub-procedures are similar to functions but they don't return any value.

Sub ProcedureName (parameterList)
'Code
End Sub