Jump to content

GUICtrlSetGraphic On button click


Recommended Posts

Example taken from Autoit help file
Working properly if put out of loop CreateChild()
but not working if try to plot on button click

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $h_GUI

Example()

Func Example()
Local $0A_MButton

$h_GUI = GUICreate ("------", 500, 400, 50, 80)
$0A_MButton = GUICtrlCreateButton("^", 210, 3, 30, 23)

;;CreateChild()         ;;<<======= Working properly

GUISetState(@SW_SHOW)

Local $idMsg
    ;----
    While 1
        $idMsg = GUIGetMsg()
        Select
            Case $idMsg = $GUI_EVENT_CLOSE
                ExitLoop
                
            Case $idMsg = $0A_MButton
                CreateChild();;<<======= not Working only showing broder
        EndSelect
    WEnd
    ;----
GUIDelete($h_GUI)

EndFunc   ;==>Example

Func CreateChild()
Local $g_aidGraphics[7]
    ;;=============
    $g_aidGraphics[1] = GUICtrlCreateGraphic(20, 50, 100, 100)
    GUICtrlSetBkColor($g_aidGraphics[1], 0xffffff)
    GUICtrlSetColor($g_aidGraphics[1], 0)
    GUICtrlSetGraphic($g_aidGraphics[1], $GUI_GR_COLOR, 0xff0000, 0xff0000)
    GUICtrlSetGraphic($g_aidGraphics[1], $GUI_GR_PIE, 50, 50, 40, 30, 270)
    GUICtrlSetGraphic($g_aidGraphics[1], $GUI_GR_COLOR, 0x00ff00, 0xffffff)
    GUICtrlSetGraphic($g_aidGraphics[1], $GUI_GR_PIE, 58, 50, 40, -60, 90)

    GUICtrlSetGraphic($g_aidGraphics[1], $GUI_GR_ELLIPSE, 100, 100, 50, 80)
    GUICtrlSetGraphic($g_aidGraphics[1], $GUI_GR_COLOR, 0x00ff00, 0xc0c0ff)
    GUICtrlSetGraphic($g_aidGraphics[1], $GUI_GR_RECT, 350, 200, 50, 80)

    ;;=============
    $g_aidGraphics[2] = GUICtrlCreateGraphic(220, 10, 100, 100)
    GUICtrlSetGraphic($g_aidGraphics[2], $GUI_GR_COLOR, 0, 0xff)
    GUICtrlSetGraphic($g_aidGraphics[2], $GUI_GR_PIE, 50, 50, 40, 30, 270)
    GUICtrlSetGraphic($g_aidGraphics[2], $GUI_GR_COLOR, 0x00ff00, 0xffffff)
    GUICtrlSetGraphic($g_aidGraphics[2], $GUI_GR_PIE, 58, 50, 40, -60, 90)
    ;;=============
    
    $g_aidGraphics[3] = GUICtrlCreateGraphic(220, 110, 100, 100)
    GUICtrlSetBkColor($g_aidGraphics[3], 0xf08080)
    GUICtrlSetColor($g_aidGraphics[3], 0xff)
    GUICtrlSetGraphic($g_aidGraphics[3], $GUI_GR_HINT, 1)

    GUICtrlSetGraphic($g_aidGraphics[3], $GUI_GR_COLOR, 0xff00)
    GUICtrlSetGraphic($g_aidGraphics[3], $GUI_GR_RECT, 50, 50, 80, 80)
    ;;=============

    $g_aidGraphics[4] = GUICtrlCreateGraphic(20, 200, 80, 80)
    GUICtrlSetBkColor($g_aidGraphics[4], 0xffffff)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_HINT, 1)

    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_MOVE, 10, 10)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_COLOR, 0xff)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_LINE, 30, 40)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_COLOR, 0xff00)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_LINE, 70, 70)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_COLOR, 0xff0000)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_LINE, 10, 50)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_COLOR, 0xffff00)
    GUICtrlSetGraphic($g_aidGraphics[4], $GUI_GR_LINE, 10, 10)
    ;;=============

    $g_aidGraphics[5] = GUICtrlCreateGraphic(150, 10, 50, 50)
    GUICtrlSetBkColor($g_aidGraphics[5], 0xa0ffa0)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_MOVE, 20, 20) ; start point
    ; it is better to draw line and after point
    ; to avoid to switch color at each drawing
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_COLOR, 0x0000ff)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_DOT, 30, 30)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_LINE, 20, 40)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_COLOR, 0xff0000)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_DOT, 25, 25)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_LINE, 40, 40)
    GUICtrlSetGraphic($g_aidGraphics[5], $GUI_GR_DOT, 30, 40)
    ;;=============

    $g_aidGraphics[6] = GUICtrlCreateGraphic(110, 260, 230, 130)
    GUICtrlSetColor($g_aidGraphics[6], 0) ; to display a black border line
    GUICtrlSetBkColor($g_aidGraphics[6], 0xc0c0ff)
    GUICtrlSetGraphic($g_aidGraphics[6], $GUI_GR_HINT, 3) ; to display control lines and end points

    GUICtrlSetGraphic($g_aidGraphics[6], $GUI_GR_COLOR, 0, 0xff); fill in blue
    GUICtrlSetGraphic($g_aidGraphics[6], $GUI_GR_MOVE, 120, 20) ; start point
    GUICtrlSetGraphic($g_aidGraphics[6], $GUI_GR_BEZIER, 120, 100, 200, 20, 200, 100)
    GUICtrlSetGraphic($g_aidGraphics[6], $GUI_GR_BEZIER + $GUI_GR_CLOSE, 100, 40, 40, 100, 40, 20)
    GUICtrlSetGraphic($g_aidGraphics[6], $GUI_GR_LINE, 60, 30) ; start point
    ;;=============
EndFunc   ;==>CreateChild

 

Link to post
Share on other sites

so have to use _WinAPI_InvalidateRect($h_GUI) or GUICtrlSetGraphic(.....,$GUI_GR_REFRESH)

Func Example()
..........
..........
..........
..........
GUISetState(@SW_SHOW)


While 1
    $Msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
                Exit

        Case $0A_MButton
        CreateChild()
        _WinAPI_InvalidateRect($h_GUI)
            
    EndSwitch
Wend
EndFunc

or

Func CreateChild()
Local $g_aidGraphics[7]
..........
..........
..........
..........
GUICtrlSetGraphic($g_aidGraphics[6], $GUI_GR_LINE, 60, 30) ; start point
GUICtrlSetGraphic($g_aidGraphics[6],$GUI_GR_REFRESH)
;;=============
EndFunc   ;==>CreateChild

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...