# Make graph paper images

## Recommended Posts

I actually made this for my Calculus teacher because she's pretty cool. In her tests she cuts out graph paper from a notebook and glues it on the test paper and then photocopies it... so I decided I would make this to see if it can make her job easier.

The one bug I was talking about is when you have a 10x10 (which is default) grid and you click export. The Y axis is a pixel too thin. Also, if the grid is 10x10 and you move the Y axis over to the left you will have blank spot in the picture when it is exported.

I realize this won't be useful to... hmm.. probably anybody, but it could help people learn.

```#include <GuiConstants.au3>
#include <A3LGDIPlus.au3>
#include <A3LScreenCap.au3>

Opt('GUIOnEventMode', 1)

\$lengthX = 150
\$lengthY = 150

\$xAxis = 5
\$yAxis = 5

\$lblXAxis = -1
\$lblYAxis = -1
\$cmbComboX = -1
\$cmbComboY = -1

_CreateGUI()

While 1
Sleep(1000)
WEnd

Func _CreateGUI()
GuiCreate('Graph Paper', \$lengthX + 65, \$lengthY + 150)
GuiSetOnEvent(\$GUI_EVENT_CLOSE, '_Exit')

GuiCtrlCreateLabel('', 10, 10, \$lengthX, \$lengthY)
GuiCtrlSetState(-1, \$GUI_DISABLE)
GuiCtrlSetBkColor(-1, 0xFFFFFF)

For \$index = 10 to \$lengthX Step 15
GuiCtrlCreateLabel('', \$index, 10, 1, \$lengthY)
GuiCtrlSetBkColor(-1, 0xBABCCC)
Next

For \$index = 10 to \$lengthY Step 15
GuiCtrlCreateLabel('', 10, \$index, \$lengthX, 1)
GuiCtrlSetBkColor(-1, 0xBABCCC)
Next

\$lblXAxis = GuiCtrlCreateLabel('', \$xAxis * 15 + 10, 10, 2, \$lengthY)
GuiCtrlSetBkColor(-1, 0)

\$lblYAxis = GuiCtrlCreateLabel('', 10, \$yAxis * 15 + 10, \$lengthX, 2)
GuiCtrlSetBkColor(-1, 0)

GuiCtrlCreateButton('<', \$lengthX + 15, 10, 20, \$lengthY)
If \$lengthX <= (15 * 7) then
GuiCtrlSetState(-1, \$GUI_DISABLE)
Else
GuiCtrlSetOnEvent(-1, '_RemoveX')
EndIf

GuiCtrlCreateButton('>', \$lengthX + 40, 10, 20, \$lengthY)

GuiCtrlCreateButton('Remove', 10, \$lengthY + 15, \$lengthX, 20)
If \$lengthY <= (15 * 7) then
GuiCtrlSetState(-1, \$GUI_DISABLE)
Else
GuiCtrlSetOnEvent(-1, '_RemoveY')
EndIf

GuiCtrlCreateButton('Add', 10, \$lengthY + 40, \$lengthX, 20)

GuiCtrlCreateLabel('X axis:', 10, \$lengthY + 68, 50, 20)
\$cmbComboX = GuiCtrlCreateCombo('', 60, \$lengthY + 65, 100, 20, \$CBS_DROPDOWNLIST)
\$data = ''

For \$index = 0 to (\$lengthX - Mod(\$lengthX, 15)) / 15
\$data &= \$index & '|'
Next
\$data = StringTrimRight(\$data, 1)

GuiCtrlSetData(\$cmbComboX, \$data, \$xAxis)

GuiCtrlCreateLabel('Y axis:', 10, \$lengthY + 98, 50, 20)
\$cmbComboY = GuiCtrlCreateCombo('', 60, \$lengthY + 95, 100, 20, \$CBS_DROPDOWNLIST)
\$data = ''

For \$index = 0 to (\$lengthY - Mod(\$lengthY, 15)) / 15
\$data &= \$index & '|'
Next
\$data = StringTrimRight(\$data, 1)

GuiCtrlSetData(\$cmbComboY, \$data, \$yAxis)

GuiCtrlCreateButton('Export', 10, \$lengthY + 122, \$lengthX, 22)
GuiCtrlSetOnEvent(-1, '_Export')

GUIRegisterMsg(\$WM_COMMAND, 'MY_WM_COMMAND')
GuiSetState()
EndFunc

Func _Export()
\$title = 'Graph ' & (\$lengthX - Mod(\$lengthX, 15)) / 15 & 'x' & (\$lengthY - Mod(\$lengthY, 15)) / 15

If FileExists(\$title & '.jpg') then
\$count = 0

Do
\$count += 1
\$title = 'Graph (' & \$count & ') ' & (\$lengthX - Mod(\$lengthX, 15)) / 15 & 'x' & (\$lengthY - Mod(\$lengthY, 15)) / 15
Until Not FileExists(\$title & '.jpg')
EndIf

WinSetState('Graph Paper', '', @SW_SHOW)
_ScreenCap_CaptureWnd(\$title & '.jpg', WinGetHandle('Graph Paper'), 13, 34, \$lengthX + 14, \$lengthY + 35)

EndFunc

\$lengthX += 15

GuiDelete()

_CreateGUI()
EndFunc

\$lengthY += 15

GuiDelete()

_CreateGUI()
EndFunc

Func _RemoveX()
\$lengthX -= 15

GuiDelete()

_CreateGUI()
EndFunc

Func _RemoveY()
\$lengthY -= 15

GuiDelete()

_CreateGUI()
EndFunc

Func _Exit()
Exit
EndFunc

Func MY_WM_COMMAND(\$hWnd, \$Msg, \$wParam, \$lParam)
\$nID = BitAnd(\$wParam, 0x0000FFFF)

If \$nID = \$cmbComboX then
If GuiCtrlRead(\$cmbComboX) <> \$xAxis then
GuiCtrlDelete(\$lblXAxis)

\$lblXAxis = GuiCtrlCreateLabel('', \$xAxis * 15 + 10, 10, 2, \$lengthY)
GuiCtrlSetBkColor(-1, 0)
EndIf

Return 0
ElseIf \$nID = \$cmbComboY then
If GuiCtrlRead(\$cmbComboY) <> \$yAxis then
GuiCtrlDelete(\$lblYAxis)

\$lblYAxis = GuiCtrlCreateLabel('', 10, \$yAxis * 15 + 10, \$lengthX, 2)
GuiCtrlSetBkColor(-1, 0)
EndIf

Return 0
EndIf

Return \$GUI_RUNDEFMSG
EndFunc```

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...