示例:
Gui,6:Destroy
Gui,6:+AlwaysOnTop
;如果ListBox控件加了AltSubmit属性,触发点击事件时v标签接收的只有行号非其内容。
;设置一个g标签GuiControl_Gui接收点击事件,v标签SetCB承载控件的内容与标识
Gui,6:Add,ComboBox, h150 w250 gGuiControl_Gui vSetCB HWNDhcb,item1|item2|item|item3|item4|item5
;Gui,6:Add,DropDownList, h150 w250 gGuiControl_Gui vSetCB HWNDhcb,item1|item2|item|item3|item4|item5
Gui,6:Add,Button,xm y+10 gGuiControl_Gui voption_0,展开
Gui,6:Add,Button,x+10 yp gGuiControl_Gui voption_1,选择[item]项
Gui,6:Add,Button,x+10 yp gGuiControl_Gui voption_2,追加一行
Gui,6:Add,Button,xm y+10 gGuiControl_Gui voption_3,修改第4行内容
Gui,6:Add,Button,x+10 yp gGuiControl_Gui voption_4,获取第5行内容
Gui,6:Add,Button,x+10 yp gGuiControl_Gui voption_5,第3行处插入1行
Gui,6:Add,Button,xm y+10 gGuiControl_Gui voption_6,获取[item5]在列表中行号
Gui,6:Add,Button,x+10 yp gGuiControl_Gui voption_7,获取高亮选中行行号
Gui,6:Add,Button,xm y+10 gGuiControl_Gui voption_8,获取列表总行数
Gui,6:Add,Button,x+10 yp gGuiControl_Gui voption_9,获取所有列表项内容
Gui,6:Add,Button,xm y+10 gGuiControl_Gui voption_10,删除第2行
Gui,6:Add,Button,x+10 yp gGuiControl_Gui voption_11,删除[item]项
Gui,6:Add,Button,x+10 yp gGuiControl_Gui voption_12,清空列表
Gui,6:Add,Button,xm y+10 gGuiControl_Gui voption_13,增加水印提示文字`n控件处于空选时显示
Gui,6:Show,AutoSize,ComboBox或DropDownList示例
Return
GuiControl_Gui:
Switch A_GuiControl
{
Case "option_0":
CB_DDL.Show(hcb,True)
Case "option_1":
Gui,+OwnDialogs
MsgBox % "选择[item]项,返回当前行号:`n" (Index:=CB_DDL.SelectString(hcb,"item"))
CB_DDL.Show(hcb,True),CB_DDL.SetCursel(hcb,Index)
Case "option_2":
Gui,+OwnDialogs
MsgBox % "追加一项到列表,返回总行数:`n" (Index:=CB_DDL.Add(hcb,"我是新增项"))
CB_DDL.Show(hcb,True)
Case "option_3":
Gui,+OwnDialogs
MsgBox % "修改第4行内容,返回1成功反之:`n" CB_DDL.Modify(hcb,4,"我是修改项")
CB_DDL.Show(hcb,True)
Case "option_4":
Gui,+OwnDialogs
MsgBox % "获取第五行内容:`n" CB_DDL.GetText(hcb,5)
CB_DDL.Show(hcb,True),CB_DDL.SetCursel(hcb,5)
Case "option_5":
Gui,+OwnDialogs
MsgBox % "在第三行处插入一项,返回行号成功反之:`n" CB_DDL.Insert(hcb,"我是插入项",3)
CB_DDL.Show(hcb,True)
Case "option_6":
Gui,+OwnDialogs
MsgBox % "获取字符[item5]项在列表中的行号:`n" (Index:=CB_DDL.GetItemPos(hcb, "item5"))
CB_DDL.Show(hcb,True),CB_DDL.SetCursel(hcb,Index)
Case "option_7":
Gui,+OwnDialogs
MsgBox % "获取高亮行行号:`n" CB_DDL.GetCurrentSel(hcb)
CB_DDL.Show(hcb,True)
Case "option_8":
Gui,+OwnDialogs
MsgBox % "获取列表总行数:`n" CB_DDL.GetCount(hcb)
CB_DDL.Show(hcb,True)
Case "option_9":
Gui,+OwnDialogs
MsgBox % "选择所有列表项内容以指定符号分隔:`n[ " CB_DDL.GetAllItem(hcb,",") " ]"
CB_DDL.Show(hcb,True)
Case "option_10":
Gui,+OwnDialogs
MsgBox % "删除第二行,返回1成功反之:`n" CB_DDL.Delete(hcb,2)
CB_DDL.Show(hcb,True)
Case "option_11":
Gui,+OwnDialogs
MsgBox % "删除[item]项,返回1成功反之:`n" CB_DDL.DeleteItem(hcb,"item")
CB_DDL.Show(hcb,True)
Case "option_12":
Gui,+OwnDialogs
MsgBox % "清空列表:`n" CB_DDL.DeleteAll(hcb)
CB_DDL.Show(hcb,True)
Case "option_13":
CB_DDL.SelectString(hcb, "")
CB_DDL.SetCuebanner(hcb, "CB或DDL下拉框")
Case "SetCB":
Gui,6:Submit,NoHide
/*
如果不加==>Gui,6:Submit,NoHide就需要在用GuiControlGet获取ComboBox或DropDownList选择项内容
GuiControlGet, SetCB ,, SetCB, Text
如果ComboBox或DropDownList控件加了AltSubmit属性,获取值就是选择项的行号
*/
Gui,+OwnDialogs
MsgBox % SetCB
}
Return
6GuiClose:
ExitApp
Return
基础控制函数:
如果有需要完善的地方大家可以接力完成,以此打造一个系列完整且有据可依的Gui控件操作扩展库。
打算出一个系列吗