明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 907|回复: 11

[建筑] 9个三行三列的radio_button,即只能有一个被选中

[复制链接]
发表于 2023-7-7 18:11 | 显示全部楼层 |阅读模式
我想做出9个三行三列的radio_button,即只能有一个被选中。图片不是我想要的效果。恳请热心的朋友指教!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2023-7-7 19:03 | 显示全部楼层
  1. (defun makedanxuandcl  (/ lst_str str file f)
  2.         (setq lst_str '(
  3.                                                                          "dx:dialog {"
  4.                                                                          "    label = \"单选\" ;"
  5.                                                                          "    :column {"
  6.                                                                          "        :row {"
  7.                                                                          "            :radio_button {"
  8.                                                                          "                key = \"r1\" ;"
  9.                                                                          "                label = \"单选1\" ;"
  10.                                                                          "            }"
  11.                                                                          "            :radio_button {"
  12.                                                                          "                key = \"r2\" ;"
  13.                                                                          "                label = \"单选2\" ;"
  14.                                                                          "            }"
  15.                                                                          "            :radio_button {"
  16.                                                                          "                key = \"r3\" ;"
  17.                                                                          "                label = \"单选3\" ;"
  18.                                                                          "            }"
  19.                                                                          "        }"
  20.                                                                          "        :row {"
  21.                                                                          "            :radio_button {"
  22.                                                                          "                key = \"r4\" ;"
  23.                                                                          "                label = \"单选4\" ;"
  24.                                                                          "            }"
  25.                                                                          "            :radio_button {"
  26.                                                                          "                key = \"r5\" ;"
  27.                                                                          "                label = \"单选5\" ;"
  28.                                                                          "            }"
  29.                                                                          "            :radio_button {"
  30.                                                                          "                key = \"r6\" ;"
  31.                                                                          "                label = \"单选6\" ;"
  32.                                                                          "            }"
  33.                                                                          "        }"
  34.                                                                          "        :row {"
  35.                                                                          "            :radio_button {"
  36.                                                                          "                key = \"r7\" ;"
  37.                                                                          "                label = \"单选7\" ;"
  38.                                                                          "            }"
  39.                                                                          "            :radio_button {"
  40.                                                                          "                key = \"r8\" ;"
  41.                                                                          "                label = \"单选8\" ;"
  42.                                                                          "            }"
  43.                                                                          "            :radio_button {"
  44.                                                                          "                key = \"r9\" ;"
  45.                                                                          "                label = \"单选9\" ;"
  46.                                                                          "            }"
  47.                                                                          "        }"
  48.                                                                          "    }"
  49.                                                                          "    ok_cancel;"
  50.                                                                          "}"
  51.                                                                          ""
  52.                                                                  )
  53.         )
  54.         (setq file (vl-filename-mktemp "DclTemp.dcl"))
  55.         (setq f (open file "w"))
  56.         (foreach str lst_str
  57.                 (princ "\n" f)
  58.                 (princ str f)
  59.         )
  60.         (close f)
  61.         file
  62. )
  63. (defun updata(va)
  64.         (foreach x '("r1" "r2" "r3" "r4" "r5" "r6" "r7" "r8" "r9")
  65.                 (set_tile x "0")
  66.         )
  67.         (set_tile (strcat "r" va) "1")
  68. )
  69. (setq danxuan_dia(makedanxuandcl))
  70. (setq dcl_id(load_dialog danxuan_dia))
  71. (new_dialog "dx" dcl_id)
  72. (set_tile "r1" "1")
  73. (action_tile "r1" "(updata \"1\")")
  74. (action_tile "r2" "(updata \"2\")")
  75. (action_tile "r3" "(updata \"3\")")
  76. (action_tile "r4" "(updata \"4\")")
  77. (action_tile "r5" "(updata \"5\")")
  78. (action_tile "r6" "(updata \"6\")")
  79. (action_tile "r7" "(updata \"7\")")
  80. (action_tile "r8" "(updata \"8\")")
  81. (action_tile "r9" "(updata \"9\")")
  82. (action_tile "cancel""(done_dialog 1)")
  83. (action_tile "accept""(done_dialog 1)")
  84. (setq idd(start_dialog))
  85. (unload_dialog dcl_id)
  86. (vl-file-delete danxuan_dia)
  87. (princ)       

评分

参与人数 1明经币 +1 收起 理由
lee50310 + 1 赞一个!

查看全部评分

发表于 2023-7-7 19:32 | 显示全部楼层
本帖最后由 vitalgg 于 2023-7-7 20:07 编辑
桃花源 发表于 2023-7-7 19:13
这就是我想要的效果,请问如何做到?谢谢!

另一贴,
重点关注回调函数 cb-rb

  1. (defun c:tt (/ dcl-fp rbn group-rb rb-value)
  2.   ;;;; Model
  3.   (setq rbn 0) ;; 用于记录无线按钮总数
  4.   (setq group-rb "slt") ;; 用于控制 rb 系列的组名
  5.   (setq rb-value nil) ;; 用于最后选中的 rb 号
  6.   ;;;; View
  7.   ;; 生成 DCL 对话框文件,你也可以用自己的方法生成。生成的 dcl 文件在 temp 文件夹下。
  8.   (dcl:dialog "buttons")
  9.   (dcl:begin-cluster "radio_row" "")
  10.   (repeat 3
  11.     (progn
  12.       (dcl:begin-cluster "column" "")
  13.       (repeat 3
  14.         (write-line
  15.           (strcat
  16.             ":radio_button{key=\""
  17.             group-rb
  18.             (itoa (setq rbn (1+ rbn)))
  19.             "\"; label=\""
  20.             "Select"
  21.             (itoa rbn)
  22.             "\";action=\"(cb-rb $key)\";}" )
  23.           dcl-fp))
  24.       (dcl:end-cluster)
  25.     ))
  26.   (dcl:end-cluster)
  27.   (dcl:end-dialog str-yes-no)
  28.   ;;;; Control
  29.   ;; 控制 多行多列无线按钮的选中与否
  30.   (defun cb-rb (key / i)
  31.     (print key)
  32.     (setq i 0)
  33.     (repeat rbn
  34.       (if (/= key (strcat group-rb (itoa (setq i (1+ i)))))
  35.         (set_tile (strcat group-rb (itoa i)) "0")
  36.         (set_tile (strcat group-rb (itoa i)) "1");;
  37.       ))
  38.     (setq rb-value key) ;; 最终选中的 rb
  39.   )
  40.   ;;;; New
  41.   (dcl:new "buttons")
  42.   ;;;; Init 该程序不需要
  43.   ;;;; Show
  44.   (dcl:show)
  45.   rb-value
  46. )

评分

参与人数 1明经币 +1 收起 理由
lee50310 + 1 赞一个!

查看全部评分

发表于 2023-7-7 20:10 | 显示全部楼层
本帖最后由 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
发表于 2023-7-7 18:41 | 显示全部楼层
用action_tile和set_tile处理
发表于 2023-7-7 19:03 | 显示全部楼层

 楼主| 发表于 2023-7-7 19:13 | 显示全部楼层

这就是我想要的效果,请问如何做到?谢谢!
 楼主| 发表于 2023-7-7 20:39 | 显示全部楼层
vitalgg 发表于 2023-7-7 20:10
MVCNIS方法:动态 DCL 编程 详见

https://gitee.com/atlisp/atlisp- ... lisp/dcl-mvcnis.org

非常感谢!好好研究研究下。
 楼主| 发表于 2023-7-7 20:46 | 显示全部楼层
发表于 2023-7-8 06:37 来自手机 | 显示全部楼层
用listbox好些
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-4 05:41 , Processed in 0.299703 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表