Click here to Skip to main content
15,890,336 members
Articles / Programming Languages / Visual Basic 10
Tip/Trick

Arduino Code Printing

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
15 Nov 2015CPOL1 min read 25.3K   524   5   5
A small application to pretty print Arduino code with syntax highlighting

Introduction

Sometimes, printing your code is a good thing, especially when starting out. The Arduino IDE does let you print your code but the formatting is lost, but the Arduino IDE also has a nice feature as in you can select all of your code as HTML. So using that, this application accepts the HTML code makes a temp HTML file and displays the code in a webbrowser control for easy printing.

I added a link at the top to the EXE file for those who don't have Visual Studio but wish to pretty print their code.

Let's Get Started

Make a new VS 2010 project and name it accordingly. Add a new winform to the project.

  • Form1: uses
  • webbrowser control
  • 4 buttons (in the screenshot, you will see more buttons, just ignore those)
  • Picturebox (optional for an Arduino image just to be fancy)
  • Form2: uses
  • Richtextbox
  • Button

Image 1

Most of the actual code is in Form2.vb but let's do Form1 first.

VB.NET
   'Show form 2
Private Sub Button5_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Button5.Click
        Form2.Show()

    End Sub

'Open the Print Dialog box
Private Sub Button4_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Button4.Click
        WebBrowser1.ShowPrintDialog()
    End Sub

'Open the printpreview Dialog box
Private Sub Button3_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Button3.Click
        WebBrowser1.ShowPrintPreviewDialog()
    End Sub

' Close form 1
Private Sub Button1_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub 

That's it for Form1, now Form2.

Form2 now uses import statements.

VB.NET
Imports System.IO

Dim sw as StreamWriter

'Form2 GO Button
 Private Sub Button1_Click(ByVal sender As System.Object, _
 	ByVal e As System.EventArgs) Handles Button1.Click
        If RichTextBox1.Text = "" Or RichTextBox1.Text = Nothing Then
            MsgBox("No Html Code Present!," & Environment.NewLine _
            & "in Arduino IDE Select 'Edit' _
            and 'Copy as Html'. ", MsgBoxStyle.OkOnly, "Information")
        Else
            sw = New StreamWriter(Application.StartupPath & "Temp.html")
            sw.Write(RichTextBox1.Text)
            sw.Close()
            MsgBox("Done!.", MsgBoxStyle.OkOnly, "")
            RichTextBox1.Clear()
            Me.Close()
            Form1.WebBrowser1.Navigate(Application.StartupPath & "Temp.html")

        End If

    End Sub

Using the Code

In the Arduino IDE, when you have finished your sketch, click Edit then Copy as HTML.

Paste this into our small application and press the GO button.

Image 2

Note

Use the PrintPreview button to check if you have the margins correct for any hole punching that may be required.

Additional Note

On line 18 of Form2, replace with this line notice the forward slash before "/Temp.html".

VB.NET
Form1.WebBrowser1.Navigate(Application.StartupPath & "/Temp.html")

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
United Kingdom United Kingdom
Giving something back to the community that helped me.

Comments and Discussions

 
QuestionExe file missing. Pin
Member 1477920121-Mar-20 10:46
Member 1477920121-Mar-20 10:46 
Questiondownloading the exe file Pin
Member 1226139612-Jan-16 23:26
Member 1226139612-Jan-16 23:26 
AnswerRe: downloading the exe file Pin
David Vanson21-Jan-16 15:04
David Vanson21-Jan-16 15:04 
GeneralRe: downloading the exe file Pin
Member 1226139621-Jan-16 21:45
Member 1226139621-Jan-16 21:45 
GeneralMessage Closed Pin
8-Dec-17 5:11
Member 135655448-Dec-17 5:11 
GeneralRe: downloading the exe file Pin
Member 135655448-Dec-17 5:28
Member 135655448-Dec-17 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.