Page 2 of 10

Re: [Class] ImageButton

Posted: 25 Feb 2014, 20:45
by tmplinshi
@dangerdogL2121
Put Class_ImageButton.ahk and Sample.ahk in the same folder.

If you have moved Class_ImageButton.ahk to LIB folder, then you should use #Include <Class_ImageButton>

Re: [Class] ImageButton

Posted: 25 Feb 2014, 21:22
by dangerdogL2121
I put Class_ImageButton.ahk and Sample.ahk in the same folder, a folder named Image button and is empty except for the scripts. It still gives me the same error. Maybe my version AHK is out of date or something.
If you have moved Class_ImageButton.ahk to LIB folder, then you should use #Include <Class_ImageButton>
I didn't know that :P
thanks

Re: [Class] ImageButton

Posted: 26 Feb 2014, 15:13
by WeThotUWasAToad
Hello,

I got the same result as dangerdogL2121:

------------------------------------------------------------
1) Clicked the link in the first post of this thread [Download from GitHub and enjoy!] which took me to https://github.com/AHK-just-me/Class_ImageButton

2) Clicked [Download ZIP] button to download Class_ImageButton-master.zip

3) Moved zip file into new folder: C:\Users\Name\My Folders\AHK\ImageButton_2014-02-26

4) Extracted all which left me with two .ahk files:

C:\Users\Name\My Folders\AHK\ImageButton_2014-02-26\Class_ImageButton-master\Class_ImageButton-master\Sources\Sample.ahk
and
C:\Users\Name\My Folders\AHK\ImageButton_2014-02-26\Class_ImageButton-master\Class_ImageButton-master\Sources\Class_ImageButton.ahk
------------------------------------------------------------

That's as far as I got though:

a) Double-clicking either file does nothing
b) Searched both files for "_1_1" but came up empty
c) Moved main file to: C:\Program Files\AutoHotkey\Lib\Class_ImageButton.ahk
d) Then tried to run Sample file again and got the same error as dangerdogL2121:
dangerdogL2121 wrote:---------------------------
Error at line 3.

#Include file "Class_ImageButton.ahk" cannot be opened.

The program will exit.
---------------------------
I also tried the following three replacements:

#Include Class_ImageButton.ahk replaced with #Include <Class_ImageButton>
#Include Class_ImageButton.ahk replaced with #Include <Class_ImageButton>.ahk
#Include Class_ImageButton.ahk replaced with #Include <Class_ImageButton.ahk>

(Can you tell I don't know what the heck I'm doing? :roll: ) but continued getting errors each time.

dangerdogL2121, did you get it working yet?

Thanks :)

Re: [Class] ImageButton

Posted: 27 Feb 2014, 00:22
by dangerdogL2121
dangerdogL2121, did you get it working yet?
No, I haven't got it working yet.

Sorry hunter99, I didn't read your post until just now.
I downloaded the Sample.ahk and ImageButton.ahk after just me put out the fixed version, so the _1_1 in the #Include was not the problem.
2) Clicked [Download ZIP] button to download Class_ImageButton-master.zip
I didn't know you could download a zip from GitHub until you just said so! :P I always copy the code and paste it in a file named correctly. However, I didn't see any change in the error by using the zip version.

I tried changing the file Class_ImageButton.ahk to ImageButton.ahk and the #Include as well but that didn't help either.
I'm glad I'm not the only one having this problem.
thanks

Re: [Class] ImageButton

Posted: 27 Feb 2014, 00:46
by just me
Classes are not library compatible as yet. You always have to #Include them manually. If you've stored Class_ImageButton.ahk in one of the library directories, #Include <Class_ImageButton> should work; at least it does for me. If you've stored the class and the sample script in the same folder, you need #Include Class_ImageButton.ahk instead. I cannot reproduce the error here.

Re: [Class] ImageButton

Posted: 27 Feb 2014, 00:50
by hd0202
I added

Code: Select all

#include %a_scriptdir%
and it worked.

Hubert

Re: [Class] ImageButton

Posted: 27 Feb 2014, 01:24
by dangerdogL2121
I changed #Include Class_ImageButton.ahk to #Include <Class_ImageButton> and it appears to have worked.
Now I get a new error:




---------------------------
Sample.ahk
---------------------------
Error: Blank parameter

Specifically: [0, 0xCF0000, , "White", 22, , "Yellow", 2]

Line#
017: GuiColor := "Silver"
018: Gui,Margin,50,20
019: Gui,Font,s10
020: Gui,Color,%GuiColor%
021: ImageButton.SetGuiColor(GuiColor)
023: Gui,Add,Button,w200,Common Button
025: Gui,Add,Button,vBT1 w200 hwndHBT1,Button 1
Line 2
---> 026: Opt1 := [0, 0xCF0000, , "White", 22, , "Yellow", 2]
027: Opt2 := [ , "Red"]
028: Opt5 := [ , , ,"Gray"]
029: if !ImageButton.Create(HBT1, Opt1, Opt2, , , Opt5)
030: MsgBox,0,ImageButton Error Btn1,ImageButton.LastError
032: Gui,Add,Button,vBT2 w200 h30 hwndHBT2,Button 2
033: Opt1 := [1, 0xF0F0F0, 0xC0F0FF, "Black", , , "Lime", 1]
034: Opt2 := {2: 0xE0E0E0, 3: 0xB0E0FF, 4: "Black"}

The program will exit.
---------------------------
OK
---------------------------

What does this mean? I can see that there's a blank parameter, but if you don't have that problem, it probably has to do with the

Code: Select all

#Include
.
thanks

Re: [Class] ImageButton

Posted: 27 Feb 2014, 01:29
by just me
Recent Changes wrote: 1.1.12.00 - August 14, 2013
Optional parameters can be omitted by writing two consecutive commas, as in InStr(a, b,, 2). Unlike previous versions, this now works for objects (including COM objects) and built-in functions. [a,,b] can be used to create a sparse array.
?

Re: [Class] ImageButton

Posted: 27 Feb 2014, 02:07
by dangerdogL2121
A new installation of AHK and no more of the blank parameter problem! :P

Now, I getting the same problem that Guest 10 had the message box that says
---------------------------
ImageButton Error Btn4
---------------------------
Invalid value for StartColor in Options[1]!
---------------------------
OK
---------------------------

Except that I did copy PIC1.jpg and PIC2.jpg into the script folder like Guest 10 did and the error box still appears and the script still works except for that.
thanks and nice buttons

Re: [Class] ImageButton

Posted: 27 Feb 2014, 16:40
by WeThotUWasAToad
I also updated AHK (from v1.1.11.01 to v1.1.14.03) and it fixed the issue for me as well.

However, there are parts of the, "How to use" steps which I don't understand so my next hurdle is being able to actually apply Class_ImageButton to a GUI and its buttons.

It would help me a lot to see an actual script with modified buttons. So for example, could you show how you would assign different colors to each of the three buttons in the following simple GUI script?

Code: Select all

Gui, Destroy
Gui, +AlwaysOnTop
Gui, -Caption +LastFound 

Gui, Add, Button, x2 y2 w120 h24, Test1
Gui, Add, Button, x124 y2 w120 h24, Test2
Gui, Add, Button, x246 y2 w120 h24, Test3

Gui, Show, x500 y600 w368 h28, Noactivate
Return

ButtonTest1: 
MsgBox You clicked the Test1 button.
Return

ButtonTest2: 
MsgBox You clicked the Test2 button.
Return

ButtonTest3: 
MsgBox You clicked the Test3 button.
Return
By the way, as I mentioned earlier, my Class_ImageButton.ahk file is here:
C:\Users\Name\My Folders\AHK\ImageButton_2014-02-26\Class_ImageButton-master\Class_ImageButton-master\Sources\Class_ImageButton.ahk

Do I need to save the script containing the GUI in that same folder or can it be saved anywhere?

Thanks

Re: [Class] ImageButton

Posted: 28 Feb 2014, 05:23
by just me

Code: Select all

#NoEnv
#Include Class_ImageButton.ahk ; you have to include the class, it's expected to be in the script folder

Gui, Destroy
Gui, +AlwaysOnTop
Gui, -Caption +LastFound 

Gui, Add, Button, x2 y2 w120 h24 hwndHBTN1, Test1     ; added hwnd option
Gui, Add, Button, x124 y2 w120 h24 hwndHBTN2, Test2   ; added hwnd option
Gui, Add, Button, x246 y2 w120 h24 hwndHBTN3, Test3   ; added hwnd option

; Test1 button: unicolored = 0, - background color = "Lime", text color = "Maroon"
Opt1 := [0, "Lime", , "Maroon"]
ImageButton.Create(HBTN1, Opt1)
; Test2 button: unicolored = 0, - background color = "Yellow", text color = "Navy"
Opt1 := [0, "Yellow", , "Navy"]
ImageButton.Create(HBTN2, Opt1)
; Test3 button: unicolored = 0, - background color = "Red", text color = "Lime"
Opt1 := [0, "Red", , "Lime"]
ImageButton.Create(HBTN3, Opt1)


Gui, Show, x500 y600 w368 h28, Noactivate
Return

ButtonTest1: 
MsgBox You clicked the Test1 button.
Return

ButtonTest2: 
MsgBox You clicked the Test2 button.
Return

ButtonTest3: 
MsgBox You clicked the Test3 button.
Return

Re: [Class] ImageButton

Posted: 28 Feb 2014, 13:01
by just me
*released v 1.3.00.00*

Re: [Class] ImageButton

Posted: 02 Mar 2014, 08:30
by dangerdogL2121
Question: Is it possible to cut off or make transparent the area past the borders of buttons, the corners? I might have missed it in the How to Use page.

Question2: Why does the function need to use six arrays?

Also it is possible to keep overlapping button from flickering or taking the image from the button on top of the overlap? Is this possible with an attribute in Class_ImageButton.ahk?
thanks

Re: [Class] ImageButton

Posted: 03 Mar 2014, 00:14
by hunter99
Hi danger, you can take a look at this . Little add to just me's test script.

Code: Select all

#NoEnv
#Include <Class_ImageButton> ; you have to include the class, it's expected to be in the script folder

Gui, Destroy
Gui, +AlwaysOnTop
Gui, -Caption +LastFound 
Gui, Color, F0F0F0, F0F0F0			;added Mar 3,2014  hunter99 tranparent test. The F0F0F0 is the MSWindows default color 
WinSet, TransColor, F0F0F0			;added Mar 3,2014  hunter99 tranparent test 
Gui, Add, Button, x2 y2 w120 h24 hwndHBTN1, Test1     ; added hwnd option
Gui, Add, Button, x124 y2 w120 h24 hwndHBTN2, Test2   ; added hwnd option
Gui, Add, Button, x246 y2 w120 h24 hwndHBTN3, Test3   ; added hwnd option

; Test1 button: unicolored = 0, - background color = "Lime", text color = "Maroon"
Opt1 := [0, "Lime", , "Maroon", 22]			;test to make round corners, ", 22" added Mar 3,2014  hunter99
ImageButton.Create(HBTN1, Opt1)
; Test2 button: unicolored = 0, - background color = "Yellow", text color = "Navy"
Opt1 := [0, "Yellow", , "Navy", 22]			;test to make round corners, ", 22" added Mar 3,2014  hunter99
ImageButton.Create(HBTN2, Opt1)
; Test3 button: unicolored = 0, - background color = "Red", text color = "Lime"
Opt1 := [0, "Red", , "Lime", 22]			;test to make round corners, ", 22" added Mar 3,2014  hunter99
ImageButton.Create(HBTN3, Opt1)


Gui, Show, x500 y600 w368 h28, Noactivate
Return

ButtonTest1: 
MsgBox You clicked the Test1 button.
Return

ButtonTest2: 
MsgBox You clicked the Test2 button.
Return

ButtonTest3: 
MsgBox You clicked the Test3 button.
Return

GuiEscape:     ;added Mar 3,2014  hunter99
ExitApp
return
hunter

Re: [Class] ImageButton

Posted: 03 Mar 2014, 09:16
by just me
dangerdogL2121 wrote:Question: Is it possible to cut off or make transparent the area past the borders of buttons, the corners? I might have missed it in the How to Use page.
Has this been answered by the post of hunter99?
Question2: Why does the function need to use six arrays?
Because there are six button states.
Also it is possible to keep overlapping button from flickering or taking the image from the button on top of the overlap? Is this possible with an attribute in Class_ImageButton.ahk?
thanks
What do you want to achieve with overlapped buttons?

Re: [Class] ImageButton

Posted: 03 Mar 2014, 13:16
by dangerdogL2121
Question: Is it possible to cut off or make transparent the area past the borders of buttons, the corners? I might have missed it in the How to Use page.
Leave the 7th parameter blank or omitted. Thank you hunter99
Question2: Why does the function need to use six arrays?
Because there are six button states.
Ok.
Also it is possible to keep overlapping button from flickering or taking the image from the button on top of the overlap? Is this possible with an attribute in Class_ImageButton.ahk?
thanks
What do you want to achieve with overlapped buttons?
If a button is placed on top of another button with GuiControl, the pixels on the lower button might be changed to the pixels on the top button for a time even after the top button has been moved off the lower button.

Question: Is it possible to have a border around a button without setting its color in StartColor or TargetColor?
thanks

Re: [Class] ImageButton

Posted: 04 Mar 2014, 01:02
by just me
Leave the 7th parameter blank or omitted. Thank you hunter99
I'm not sure what you're talking about.
If a button is placed on top of another button with GuiControl, the pixels on the lower button might be changed to the pixels on the top button ...
That's caused by the order in which the system is drawing the controls. It might help to disable the lower button while the other is on top of it.
... for a time even after the top button has been moved off the lower button.
It might help to use GuiControl, MoveDraw, ....
Question: Is it possible to have a border around a button without setting its color in StartColor or TargetColor?
Currently not, because the whole button is represented by one image per state and the border is part of the image. It might be enabled by storing the last options in the instance and adding a Change() method. But I'll have to have a good reason to do it.

Re: [Class] ImageButton

Posted: 04 Mar 2014, 22:30
by dangerdogL2121
\
Leave the 7th parameter blank or omitted. Thank you hunter99
I'm not sure what you're talking about.
If you leave the seventh item(BorderColor) of the array empty then the background color of the border will be transparent.
Question: Is it possible to have a border around a button without setting its color in StartColor or TargetColor?
Currently not, because the whole button is represented by one image per state and the border is part of the image. It might be enabled by storing the last options in the instance and adding a Change() method. But I'll have to have a good reason to do it.
One reason would be if someone wanted to change the border color of a button without coloring the interior of the button.
thanks

Re: [Class] ImageButton

Posted: 05 Mar 2014, 04:51
by just me
If you leave the seventh item(BorderColor) of the array empty then the background color of the border will be transparent.
Still not sure. If you leave BorderColor empty, no border will be drawn at all. :roll:
One reason would be if someone wanted to change the border color of a button without color and interior or the button.
Well, for any change of any aspect of an image button all images as well as the image list have to be recreated. This will cost some time and CPU power, and may result in flickering.
I'll think about it.

Re: [Class] ImageButton

Posted: 05 Mar 2014, 11:14
by dangerdogL2121
Sorry, I wrote the wrong thing.
If GuiColor is blank, the border is transparent.

Also, I fixed a typo in my most recent post.
thanks