Tab control can't change background color after creation

Issue #10 closed
Matt Feemster repo owner created an issue

No description provided.

Comments (8)

  1. Winter Laite

    AHK 1 script (I’ll try to do a v2 version, might take a bit):

    TabColors_Tab1=FF0000
    TabColors_Tab2=00FF00
    TabColors_Tab3=0000FF
    
    Gui, +AlwaysOnTop +OwnDialogs -MinimizeBox
    Gui, Add, Tab, w100 x3 y+2 h100 w113 AltSubmit gTab vTab
        , Tab1|Tab2|Tab3
        Gosub, Tab
    Gui, Show, , Test Script
    return
    
    Tab:
    GuiControlGet, Tab
    Gui, Color, % TabColors_Tab%Tab%
    return
    
    GuiClose:
    ExitApp
    
    ^esc::exitapp
    

  2. Matt Feemster reporter

    Please do. Keysharp only supports V2.

    That script is overkill. Just a simple tab control that is set to some custom color, then a button click to change it to a different color.

  3. Winter Laite

    Okay, I’ll try that, but to paraphrase Mark Twain, if I’d had more time I’d have written something shorter. That v1 code was snipped from an ancient forum post.

    Effort so far:

    TabColors_Tab1 := "FF0000"
    TabColors_Tab2 := "00FF00"
    TabColors_Tab3 := "0000FF"
    
    MyGui := Gui("+AlwaysOnTop +OwnDialogs -MinimizeBox")
    MyTab := MyGui.Add("Tab3", "w100 x3 y+2 h100 w113 AltSubmit", ["First","Second","Third"])
    MyTab.OnEvent("Change", TabFunc)
    MyGui.Show()
    return
    
    !Esc::ExitApp
    
    TabFunc(*) {
        if (MyTab.Value == 1) {
        MyGui.BackColor := TabColors_Tab1
        }
        if (MyTab.Value == 2) {
        MyGui.BackColor := TabColors_Tab2
        }
        if (MyTab.Value == 3) {
        MyGui.BackColor := TabColors_Tab3
        }
    }
    

    That’s what I had when I opened the page just now. I’ll need to work on something shorter.

  4. Winter Laite

    Afraid it needs two tabs to make sense. If I don’t get a “Change” event nothing will happen, and if there’s only one tab it won’t change.

    NewColor := "FF0000"
    MyGui := Gui("+AlwaysOnTop +OwnDialogs -MinimizeBox")
    MyTab := MyGui.Add("Tab3", "w100 x3 y+2 h100 w113 AltSubmit", ["Test", "Retest"])
    MyTab.OnEvent("Change", TabFunc)
    MyGui.Show()
    return
    
    !Esc::ExitApp
    
    TabFunc(*) {
        MyGui.BackColor := NewColor
    }
    

  5. Matt Feemster reporter

    Update your source and verify this works:

    TabColors_Tab1 := "FF0000"
    TabColors_Tab2 := "00FF00"
    TabColors_Tab3 := "0000FF"
    
    MyGui := Gui()
    MyTab := MyGui.Add("Tab3", "w300 h300", ["First","Second","Third"])
    MyTab.OnEvent("Change", "TabFunc")
    MyGui.Show()
    
    TabFunc()
    {
    global
        if (MyTab.Value == 1) {
            MyGui.BackColor := TabColors_Tab1
            MyTab.Opt("Background" TabColors_Tab1)
        }
    
        if (MyTab.Value == 2) {
            MyGui.BackColor := TabColors_Tab2
            MyTab.Opt("Background" TabColors_Tab2)
        }
    
        if (MyTab.Value == 3) {
            MyGui.BackColor := TabColors_Tab3
            MyTab.Opt("Background" TabColors_Tab3)
        }
    }
    

  6. Log in to comment