9个三行三列的radio_button,即只能有一个被选中
我想做出9个三行三列的radio_button,即只能有一个被选中。图片不是我想要的效果。恳请热心的朋友指教!(defun makedanxuandcl(/ lst_str str file f)
(setq lst_str '(
"dx:dialog {"
" label = \"单选\" ;"
" :column {"
" :row {"
" :radio_button {"
" key = \"r1\" ;"
" label = \"单选1\" ;"
" }"
" :radio_button {"
" key = \"r2\" ;"
" label = \"单选2\" ;"
" }"
" :radio_button {"
" key = \"r3\" ;"
" label = \"单选3\" ;"
" }"
" }"
" :row {"
" :radio_button {"
" key = \"r4\" ;"
" label = \"单选4\" ;"
" }"
" :radio_button {"
" key = \"r5\" ;"
" label = \"单选5\" ;"
" }"
" :radio_button {"
" key = \"r6\" ;"
" label = \"单选6\" ;"
" }"
" }"
" :row {"
" :radio_button {"
" key = \"r7\" ;"
" label = \"单选7\" ;"
" }"
" :radio_button {"
" key = \"r8\" ;"
" label = \"单选8\" ;"
" }"
" :radio_button {"
" key = \"r9\" ;"
" label = \"单选9\" ;"
" }"
" }"
" }"
" ok_cancel;"
"}"
""
)
)
(setq file (vl-filename-mktemp "DclTemp.dcl"))
(setq f (open file "w"))
(foreach str lst_str
(princ "\n" f)
(princ str f)
)
(close f)
file
)
(defun updata(va)
(foreach x '("r1" "r2" "r3" "r4" "r5" "r6" "r7" "r8" "r9")
(set_tile x "0")
)
(set_tile (strcat "r" va) "1")
)
(setq danxuan_dia(makedanxuandcl))
(setq dcl_id(load_dialog danxuan_dia))
(new_dialog "dx" dcl_id)
(set_tile "r1" "1")
(action_tile "r1" "(updata \"1\")")
(action_tile "r2" "(updata \"2\")")
(action_tile "r3" "(updata \"3\")")
(action_tile "r4" "(updata \"4\")")
(action_tile "r5" "(updata \"5\")")
(action_tile "r6" "(updata \"6\")")
(action_tile "r7" "(updata \"7\")")
(action_tile "r8" "(updata \"8\")")
(action_tile "r9" "(updata \"9\")")
(action_tile "cancel""(done_dialog 1)")
(action_tile "accept""(done_dialog 1)")
(setq idd(start_dialog))
(unload_dialog dcl_id)
(vl-file-delete danxuan_dia)
(princ)
本帖最后由 vitalgg 于 2023-7-7 20:07 编辑
桃花源 发表于 2023-7-7 19:13
这就是我想要的效果,请问如何做到?谢谢!
另一贴,
重点关注回调函数 cb-rb
(defun c:tt (/ dcl-fp rbn group-rb rb-value)
;;;; Model
(setq rbn 0) ;; 用于记录无线按钮总数
(setq group-rb "slt") ;; 用于控制 rb 系列的组名
(setq rb-value nil) ;; 用于最后选中的 rb 号
;;;; View
;; 生成 DCL 对话框文件,你也可以用自己的方法生成。生成的 dcl 文件在 temp 文件夹下。
(dcl:dialog "buttons")
(dcl:begin-cluster "radio_row" "")
(repeat 3
(progn
(dcl:begin-cluster "column" "")
(repeat 3
(write-line
(strcat
":radio_button{key=\""
group-rb
(itoa (setq rbn (1+ rbn)))
"\"; label=\""
"Select"
(itoa rbn)
"\";action=\"(cb-rb $key)\";}" )
dcl-fp))
(dcl:end-cluster)
))
(dcl:end-cluster)
(dcl:end-dialog str-yes-no)
;;;; Control
;; 控制 多行多列无线按钮的选中与否
(defun cb-rb (key / i)
(print key)
(setq i 0)
(repeat rbn
(if (/= key (strcat group-rb (itoa (setq i (1+ i)))))
(set_tile (strcat group-rb (itoa i)) "0")
(set_tile (strcat group-rb (itoa i)) "1");;
))
(setq rb-value key) ;; 最终选中的 rb
)
;;;; New
(dcl:new "buttons")
;;;; Init 该程序不需要
;;;; Show
(dcl:show)
rb-value
) 本帖最后由 vitalgg 于 2023-7-7 20:20 编辑
MVCNIS方法:动态 DCL 编程 详见
https://gitee.com/atlisp/atlisp- ... lisp/dcl-mvcnis.org
更多示例:
https://gitee.com/atlisp/atlisp-lib/tree/main/src/example
用action_tile和set_tile处理 https://atlisp.cn/static/videos/multi-row-column-rb.mp4
vitalgg 发表于 2023-7-7 19:03
这就是我想要的效果,请问如何做到?谢谢! vitalgg 发表于 2023-7-7 20:10
MVCNIS方法:动态 DCL 编程 详见
https://gitee.com/atlisp/atlisp- ... lisp/dcl-mvcnis.org
非常感谢!好好研究研究下。:handshake 飞雪神光 发表于 2023-7-7 19:03
非常感谢!:handshake 用listbox好些
页:
[1]
2