walk.MsgBox
- 消息窗
func MsgBox(owner Form, title, message string, style MsgBoxStyle) int
owner Form 父窗体句柄
title 消息窗的标题
message 消息内容
style 消息窗的样式
walk.MsgBox(
mw,
"Title",
"Message",
walk.MsgBoxServiceNotification)
参数style 取值比较多可参照 walk 包下面的 messagebox.go 中定义的
-
消息按钮事件的触发
walk.MsgBox 方法的返回值是int ,这个返回值就是点击消息窗按钮时返回的,返回用户点击的具体的按钮的Id,可以通过判断这个来触发点击回调。具体实现如下,部分关键代码:
OnClicked: func() {
cmd=walk.MsgBox(
mw,
"Title",
"Message",
walk.MsgBoxYesNoCancel)
switch cmd {
case walk.DlgCmdYes:
le.SetText("click 是")
case walk.DlgCmdCancel:
le.SetText("click 取消")
case walk.DlgCmdNo:
le.SetText("click 否")
}
},
完整代码
package main
import (
"fmt"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var(
pb PushButton
_pb *walk.PushButton
mw *walk.MainWindow
le *walk.LineEdit
cmd int
)
pb=PushButton{
AssignTo:&_pb,
Text:"btn",
MaxSize:Size{150,30},
OnClicked: func() {
cmd=walk.MsgBox(
mw,
"Title",
"Message",
walk.MsgBoxYesNoCancel)
switch cmd {
case walk.DlgCmdYes:
le.SetText("click 是")
case walk.DlgCmdCancel:
le.SetText("click 取消")
case walk.DlgCmdNo:
le.SetText("click 否")
}
},
}
if _,err:=(MainWindow{
Title:"layout_flow_demo",
AssignTo:&mw,
Layout:VBox{MarginsZero:true},
Size:Size{300,50},
Children: []Widget{
HSplitter{
Children: []Widget{
LineEdit{
AssignTo:&le,
MaxSize:Size{150,30},
},
pb,
HSpacer{},
},
},
VSpacer{},
},
}.Run());err!=nil{
fmt.Println(err)
}
}