Jump to content

Create a grid using GUICtrlCreateGraphic


MyEarth
 Share

Go to solution Solved by UEZ,

Recommended Posts

Hello :D

Like title and math is my worst enemy. Pratically at the end i'd like a function with the parameters for single square size, like "create a grid of 10x10 pixel every squares" not the number of the total squares

A sort of example of a grid using GUICtrlCreateGraphic

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hWidth = 200
$hHeight = 200

$hGui = GUICreate("", $hWidth, $hHeight, -1, -1)

GUICtrlCreateGraphic(0, 0, $hWidth, $hHeight)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $hHeight / 3)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00000)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $hWidth, $hHeight / 3)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $hHeight * 2 / 3)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00000)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $hWidth, $hHeight * 2 / 3)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $hWidth / 3, 0)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00000)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $hWidth / 3, $hHeight)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $hWidth * 2 / 3, 0)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00000)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $hWidth * 2 / 3, $hHeight)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Thanks for the help

Link to comment
Share on other sites

  • Solution

Try this:

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$iWidth = 600
$iHeight = 400

$hGui = GUICreate("", $iWidth, $iHeight, -1, -1)
Create_GRID($iWidth, $iHeight)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Create_GRID($iWidth, $iHeight, $iGrid_w = 20, $iGrid_h = 20, $iColorW = 0x00000, $iColorH = 0x00000)
    Local $x, $y
    GUICtrlCreateGraphic(0, 0, $iWidth, $iHeight)

    For $x = 0 To $iWidth / $iGrid_w
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $x * $iGrid_w, 0)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $iColorW)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $x * $iGrid_w, $iHeight)
    Next

    For $y = 0 To $iHeight / $iGrid_h
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $y * $iGrid_h)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $iColorH)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWidth, $y * $iGrid_h)
    Next
EndFunc
 

 

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...