【问题标题】:AHK GUI DateTime default settingAHK GUI 日期时间默认设置
【发布时间】:2019-06-03 07:40:38
【问题描述】:

有没有办法在加载时将 dateTime 控件设置为空白?

我有

  class DateTime extends Tabs.Tab.Workspace.GenericControl
        {
            ControlType := "DateTime"
            DefaultOptions := "ChooseNone"
            New()
            {MsgBox, % this.GuiControlGet()
             }
            DateTimeChanged(_CtrlHwnd, _GuiEvent, _EventInfo, _ErrorLevel:="")
            {
             MsgBox, % this.GuiControlGet()
            }
            Clear()
            {
                this.GuiControl("", A_Now)
                this.GuiControl("", "")
                this.GuiControl("", "")
            }




        }

或者

          ControlType := "DateTime"
            DefaultOptions := "Choose20200202"

chooseNone 默认仍然显示今天的日期,这很好,除非将值传输到工作表时,即使控件中未选中该框,该值仍会传输。

将值传输到工作表的代码。

WorkbookPopulate(MyWorkbook, TabsObj) {
    for TabNumber, ThisTab in TabsObj.TabList {
        for ControlType, ThisControlType in ThisTab.Workspace.Controls {
            ; Special case: skip the TabOrder object TODO maybe this should be rethought? On
            ; the other hand, this simplifies adding controls to the TabOrder
            if (ControlType = "TabOrder")
                    continue
            for ControlName, ThisControl in ThisControlType {
                if (ThisControl.ExcelCell != "") {
                    MyValue := ThisControl.GuiControlGet()
                    ; Change MyValue as a special case for Checkboxes
                    if (ControlType = "Checkbox") {
                        ;~ MyValue := MyValue = 1 ? "a" : "c" ; Use "Marlett" font in template
                        MyValue := MyValue = 1 ? Chr(0x2713) : "" ;Chr(0x2610)
                                                ;Chr(0x2610) - BALLOT BOX
                                                ;Chr(0x2611) - BALLOT BOX WITH CHECK
                                                ;Chr(0x2612) - BALLOT BOX WITH X
                                                ;Chr(0x2713) - CHECK MARK
                                                ;Chr(0x2714) - HEAVY CHECK MARK
                    }
                    if (ControlType = "DateTime")
                    FormatTime, MyValue, %MyValue%, MMMM dd, yyyy
                    MyWorkbook.Sheets(ThisControl.ExcelSheet).Range(ThisControl.ExcelCell).Value
                        := MyValue
                }
            }
        }
    }
}

如果没有选择(选中)日期,只需将 MyValue 设置为“--”就好了。 我想做的另一个选择是默认为“---”

【问题讨论】:

    标签: javascript c++ autohotkey


    【解决方案1】:

    你可以在 AHK 中做这样的事情:

    checkbox=0 ;var to keep track of the checkbox status. 1 = checked / 0 = unchecked
    Gui, Add, DateTime, vDateTimeVar 2 ChooseNone gcheck, -- ;2 adds the checkbox. ChooseNone defaults it to unchecked
    Gui, Show
    return
    
    check:
    if (checkbox=1) ; if checked
    {
        GuiControl, Text, DateTimeVar, -- ;Changes to "--"
        checkbox=0
    }
    else
    {
        GuiControl, Text, DateTimeVar, M/d/yy HH:mm ;Changes the format to M/d/yy HH:mm
        Guicontrol,, DateTimeVar, %a_now% ;Set's current date
        checkbox=1
    }
    return
    

    您需要使用 GuiControl, Text 将格式更改为“--”,然后将其更改回所需的 DateTime 格式,然后将其值更改为所需的日期。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多