How to set the background color for the Picture control

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
AutoHot159357
Posts: 2
Joined: 31 Mar 2024, 06:54

How to set the background color for the Picture control

Post by AutoHot159357 » 31 Mar 2024, 07:21

Hello, everyone, How to set the background color for the Picture control.Please help me thanks

Code: Select all

MyGui := Gui(,"Gui测试")
MyGui.Opt("+Resize")
MyGui.BackColor := "ddc4b0"
MyGui.AddEdit("r9 vedtEdit w325 ReadOnly")
picColor0 := MyGui.AddPicture("xm w19 h19 vpicColor0")
edtXYColor0 := MyGui.AddEdit("r1 w300 vedtXYColor0 yp  ReadOnly")
MyGui.AddPicture("xm w19 h19 vpicColor1 BackgroundRed")
MyGui.AddEdit("r1 w300 vedtXYColor1 yp  ReadOnly")
MyGui.AddPicture("xm w19 h19 vpicColor2 BackgroundRed")
MyGui.AddEdit("r1 w300 vedtXYColor2 yp  ReadOnly")
MyGui.AddPicture("xm w19 h19 vpicColor3 BackgroundRed")
MyGui.AddEdit("r1 w300 vedtXYColor3 yp  ReadOnly")
MyGui.AddPicture("xm w19 h19 vpicColor4 BackgroundRed")
MyGui.AddEdit("r1 w300 vedtXYColor4 yp ReadOnly")
MyGui.AddPicture("xm w19 h19 vpicColor5 BackgroundRed")
MyGui.AddEdit("r1 w300 vedtXYColor5 yp ReadOnly")
MyGui.AddPicture("xm w19 h19 vpicColor6 BackgroundRed")
MyGui.AddEdit("r1 w300 vedtXYColor6 yp ReadOnly")
MyGui.Show("Center")

Xvk58_key(*){
    global MyGui, GetColor, mX, mY
    CoordMode "Pixel"
    MouseGetPos &mX, &mY
    GetColor := PixelGetColor(mX, mY, "Slow")
    setColor := SubStr(GetColor, 3, 6)
    ;ToolTip "X:" mX " Y:" mY "`nColor:" GetColor, mX, mY 
    ;How to write here
    picColor0
    edtXYColor0.Text := mX "x" mY ":" GetColor
    colorXY := mX "," mY ":" GetColor
    ClipSave := ClipboardAll()
    ClipSave := colorXY
    A_Clipboard := ClipSave
    
}

User avatar
boiler
Posts: 17334
Joined: 21 Dec 2014, 02:44

Re: How to set the background color for the Picture control

Post by boiler » 31 Mar 2024, 07:55

BackgroundRed is how you do it. And since you’re not specifying a picture file, you should just be getting a red square, which it apparently does. What is it doing that you are not expecting?

AutoHot159357
Posts: 2
Joined: 31 Mar 2024, 06:54

Re: How to set the background color for the Picture control

Post by AutoHot159357 » 31 Mar 2024, 08:10

@boiler
I want to press X key, Set the background color of the picture control. Don't know how to put setColor variables, Assign to picColor0

Code: Select all

Xvk58_key(*){
    global MyGui, GetColor, mX, mY
    CoordMode "Pixel"
    MouseGetPos &mX, &mY
    GetColor := PixelGetColor(mX, mY, "Slow")
    setColor := SubStr(GetColor, 3, 6)
    ;ToolTip "X:" mX " Y:" mY "`nColor:" GetColor, mX, mY 
    ;How to write here
    picColor0
    edtXYColor0.Text := mX "x" mY ":" GetColor
    colorXY := mX "," mY ":" GetColor
    ClipSave := ClipboardAll()
    ClipSave := colorXY
    A_Clipboard := ClipSave
    
}
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]

User avatar
boiler
Posts: 17334
Joined: 21 Dec 2014, 02:44

Re: How to set the background color for the Picture control

Post by boiler » 31 Mar 2024, 12:07

Some types of controls are more amenable to having their options changed. If you just want a square color that you can change, use a Progress control instead. Demo:

Code: Select all

#Requires AutoHotkey v2.0
MyGui := Gui()
MyGui.Backcolor := 'Red'
MyGui.Add('Progress', 'w100 h100 BackgroundBlue vMyPrg')
MyGui.Show
Sleep 3000
MyGui['MyPrg'].Opt('+BackgroundGreen')

just me
Posts: 9560
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to set the background color for the Picture control

Post by just me » 31 Mar 2024, 16:36

Code: Select all

#Requires AutoHotkey v2.0
MyGui := Gui(,"Gui测试")
MyGui.Opt("+Resize")
MyGui.BackColor := "ddc4b0"
MyGui.AddEdit("r9 vedtEdit w325 ReadOnly")
picColor0 := MyGui.AddPic("xm w19 h19 vpicColor0 BackgroundGreen")
edtXYColor0 := MyGui.AddEdit("r1 w300 vedtXYColor0 yp  ReadOnly")
MyGui.Show("Center")

^r:: {
   picColor0.Opt("+BackgroundRed")
   picColor0.Redraw() ; static controls aren't redrawn automatically after a color change
}
^g:: {
   picColor0.Opt("+BackgroundGreen")
   picColor0.Redraw()
}
^b:: {
   picColor0.Opt("+BackgroundBlue")
   picColor0.Redraw()
}

Post Reply

Return to “Ask for Help (v2)”