Jump to content

Clear a loaded Jpg


Recommended Posts

I have buttons that add pictures to a GUI that contains ABC's as buttons. When each button is pressed it loads a picture related to it that is named according to the letter.

EX Pressing A opens A.jpg

Here's the problem. For a reason unknown to me, it must be pressed or called twice to pull the image. Works perfectly well the first time used once opened, But it must be pressed twice after that.

CODE
GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)

GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)

works to avoid the pressing twice but causes a flicker.

Is there a way to delete all images on a GUI?

ex

button press =

Delete all images or specific image

then

GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)

or some other idea to avoid the lack of update or flicker?

???? Thanks for the help!

Link to comment
Share on other sites

I have buttons that add pictures to a GUI that contains ABC's as buttons. When each button is pressed it loads a picture related to it that is named according to the letter.

EX Pressing A opens A.jpg

Here's the problem. For a reason unknown to me, it must be pressed or called twice to pull the image. Works perfectly well the first time used once opened, But it must be pressed twice after that.

CODE
GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)

GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)

works to avoid the pressing twice but causes a flicker.

Is there a way to delete all images on a GUI?

ex

button press =

Delete all images or specific image

then

GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)

or some other idea to avoid the lack of update or flicker?

???? Thanks for the help!

2 things

i think you should use:

GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)
GuiCtrlSetState(-1, $GUI_DISABLE)

and to delete use

GuiCtrlDelete()

Edited by c4nm7
Link to comment
Share on other sites

2 things

i think you should use:

c2--><!--R3VpQ3RybENyZWF0ZVBpYygmcXVvdDtDOiYjMDkyO0F1dG9JdEFCQyYjMzk7cyYjMDkyOyZxdW90OyAmYW1wOyBDaHIoNjUrJiMw
MzY7WCkgJmFtcDsgJnF1b3Q7LmpwZyZxdW90OywgMzUwLCAxMjAsIDEwNiwgNzUpCkd1aUN0cmxTZXRTdGF0ZSgtMSwgJiMwMzY7
R1VJX0RJU0FCTEUp--><!--eg

and to delete use

GuiCtrlDelete()

Your suggestion worked just as needed! Thanks a million!

Link to comment
Share on other sites

Your suggestion worked just as needed! Thanks a million!

Is there a way to use this for multiple pictures?

Say I add two pictures.

1. A.jpg

2. A2.jpg

Then delete both?

Also the code does work for one if a set a timer and delete while the script is still running. I was hoping to add the delete at the top so that it would delete only when another letter is pressed . . .

Any ideas?

Thanks for your help!

Link to comment
Share on other sites

Here's the problem. For a reason unknown to me, it must be pressed or called twice to pull the image. Works perfectly well the first time used once opened, But it must be pressed twice after that.

GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)
GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)

works to avoid the pressing twice but causes a flicker.

Is there a way to delete all images on a GUI?

ex

button press =

Delete all images or specific image

then

GuiCtrlCreatePic("C:\AutoItABC's\" & Chr(65+$X) & ".jpg", 350, 120, 106, 75)

Are you creating the Pic over and over again? That's not the idea. You only create the Pic control ONCE with GuiCtrlCreatePic(), and save the control ID to variable. Then to change the picuture you just use the control ID to set a new image with GuiCtrlSetImage().

Demo:

#include <guiconstants.au3>

Opt("GuiOnEventMode", 1)

$PicDir = FileSelectFolder("Select a directory with JPGs in it:", "", 4)
If @error Then Exit
$hSearch = FileFindFirstFile($PicDir & "\*.jpg")
If @error Or $hSearch = -1 Then
    MsgBox(16, "Error", "No .jpg file found: " & $PicDir)
    Exit
EndIf

GUICreate("Picture Test", 300, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$PicCtrl = GUICtrlCreatePic("", 10, 10, 280, 280)
$Label = GUICtrlCreateLabel("", 10, 300, 280, 20, $SS_CENTER)
GUICtrlCreateButton("NEXT", 120, 330, 60, 30)
GUICtrlSetOnEvent(-1, "_Next")
_Next()
GUISetState()

While 1
    Sleep(20)
WEnd

Func _Next()
    $PicFile = FileFindNextFile($hSearch)
    If @error Then
        MsgBox(64, "Done", "No more .jpg files.")
        Exit
    Else
        GUICtrlSetImage($PicCtrl, $PicDir & "\" & $PicFile)
    EndIf
EndFunc  ;==>_Next

Func _Quit()
    Exit
EndFunc  ;==>_Quit

:rolleyes:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...