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.
Private Sub Button5_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button5.Click
Form2.Show()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.ShowPrintDialog()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.ShowPrintPreviewDialog()
End Sub
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
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")