Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Arduino Code Printing

0.00/5 (No votes)
15 Nov 2015 1  
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

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

   '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.

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.

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".

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here