找回密码
 加入
搜索
楼主: 邪恶海盗

[AU3基础] 一组单选框选中即执行命令,如何简单点写?

[复制链接]
发表于 2023-9-11 16:03:25 | 显示全部楼层
邪恶海盗 发表于 2023-9-11 15:58
好像这屎山代码还有很大的优化空间...

重复的比较多,可能可以精简掉80%...
 楼主| 发表于 2023-9-11 17:59:19 | 显示全部楼层
afan 发表于 2023-9-11 16:03
重复的比较多,可能可以精简掉80%...

不重要,能运行起来就行,以后再说...
 楼主| 发表于 2023-9-12 16:05:05 | 显示全部楼层
afan 发表于 2023-9-11 16:03
重复的比较多,可能可以精简掉80%...

想到一个精简办法,比如先把每个Radio的GroupID/RadioID/Text/Color/Value写到一个数组$Radios[$n]里,比如这样

GroupID RadioID Text Color Value
1 1 a b c
1 2 df e f
2 3 xz ui 99
4 1 wa jn 00
5 5 c5 ee 11

然后再用for to来循环创建Radio,关键是看了半天数组,多维的完全看不懂...
发表于 2023-9-12 19:14:44 | 显示全部楼层
邪恶海盗 发表于 2023-9-12 16:05
想到一个精简办法,比如先把每个Radio的GroupID/RadioID/Text/Color/Value写到一个数组$Radios[$n]里,比如 ...

感觉选色单选框控件太多了,估计你自己都觉得繁琐
只写一组颜色控件就行了,点击电阻图示的色环>选定颜色。就跟下拉框差不多,只不过选择颜色下拉框代码较复杂,没必要,就用Label或Radio更简单。
 楼主| 发表于 2023-9-12 19:59:30 | 显示全部楼层
afan 发表于 2023-9-12 19:14
感觉选色单选框控件太多了,估计你自己都觉得繁琐
只写一组颜色控件就行了,点击电阻图示的色环>选定颜 ...

数组捣鼓成功了,定义的时候要写太多,现在可以批量把Radio都创建完成,但用case $Radio[0][0] to $Radio[5][9]好像不对头???

慢慢来,抓到一点学一点先...
 楼主| 发表于 2023-9-13 22:43:26 | 显示全部楼层
afan 发表于 2023-9-12 19:14
感觉选色单选框控件太多了,估计你自己都觉得繁琐
只写一组颜色控件就行了,点击电阻图示的色环>选定颜 ...

"优化"了一点,代码行数降低了一部分,不过感觉创建Radio还可以再优化,奈何一次性把所有Radios添加进数组可以创建成功,但捕捉消息会有问题,明明只有54个Radio,捕捉到Case[0][0] to Case [5][10]的消息可以超过这个数量,估计是循环的时候创建Group占用了,不会玩又改回单个创建Group和Radio组了


另外还有一个问题,XP上Radio的颜色是正常的,Win7下Radio文字颜色没生效,啥情况???

#region AutoIt3Wrapper 预编译参数(常用参数)
#AutoIt3Wrapper_Icon=F:\AU3脚本\图标\hidao.ico  ;图标,支持EXE,DLL,ICO
#AutoIt3Wrapper_OutFile=R_Calc.exe   ;输出文件名
#AutoIt3Wrapper_OutFile_Type=exe   ;文件类型
#AutoIt3Wrapper_Compression=9  ;压缩等级
#AutoIt3Wrapper_UseUPX=y  ;使用压缩
#AutoIt3Wrapper_Res_Comment=R_Calc ;注释
#AutoIt3Wrapper_Res_Description=电阻计算器;详细信息
#AutoIt3Wrapper_Res_Fileversion=0.2.2023.913
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=;p    ;自动更新版本
#AutoIt3Wrapper_Res_LegalCopyright=邪恶海盗;版权
#endregion AutoIt3Wrapper 预编译参数(常用参数)
;#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
;#include <TabConstants.au3>
;#include <WindowsConstants.au3>
#NoTrayIcon
#region ### START Koda GUI section ### Form=f:\au3脚本\色环电阻.kxf

Dim $Radios0[10][5] = [[0, 0, '黑=0', 0x000000, 0],[0, 1, '棕=1', 0x800000, 1],[0, 2, '红=2', 0xFF0000, 2],[0, 3, '橙=3', 0xFFA500, 3],[0, 4, '黄=4', 0xFFFF00, 4], _
                [0, 5, '绿=5', 0x008000, 5],[0, 6, '蓝=6', 0x0000FF, 6],[0, 7, '紫=7', 0x800080, 7],[0, 8, '灰=8', 0x808080, 8],[0, 9, '白=9', 0xFFFFFF, 9]]
Dim $Radios1[10][5] = [[1, 0, '黑=0', 0x000000, 0],[1, 1, '棕=1', 0x800000, 1],[1, 2, '红=2', 0xFF0000, 2],[1, 3, '橙=3', 0xFFA500, 3],[1, 4, '黄=4', 0xFFFF00, 4], _
                [1, 5, '绿=5', 0x008000, 5],[1, 6, '蓝=6', 0x0000FF, 6],[1, 7, '紫=7', 0x800080, 7],[1, 8, '灰=8', 0x808080, 8],[1, 9, '白=9', 0xFFFFFF, 9]]
Dim $Radios2[10][5] = [[2, 0, '黑=0', 0x000000, 0],[2, 1, '棕=1', 0x800000, 1],[2, 2, '红=2', 0xFF0000, 2],[2, 3, '橙=3', 0xFFA500, 3],[2, 4, '黄=4', 0xFFFF00, 4], _
                [2, 5, '绿=5', 0x008000, 5],[2, 6, '蓝=6', 0x0000FF, 6],[2, 7, '紫=7', 0x800080, 7],[2, 8, '灰=8', 0x808080, 8],[2, 9, '白=9', 0xFFFFFF, 9]]
Dim $Radios3[10][5] = [[3, 0, '黑=0', 0x000000, 0],[3, 1, '棕=1', 0x800000, 1],[3, 2, '红=2', 0xFF0000, 2],[3, 3, '橙=3', 0xFFA500, 3],[3, 4, '黄=4', 0xFFFF00, 4], _
                [3, 5, '绿=5', 0x008000, 5],[3, 6, '蓝=6', 0x0000FF, 6],[3, 7, '紫=7', 0x800080, 7],[3, 8, '金=-1', 0xFFD700, -1],[3, 9, '银=-2', 0xC0C0C0, -2]]
Dim $Radios4[8][5] = [[4, 0, '棕=±1', 0x800000, '±1'],[4, 1, '红=±2', 0xFF0000, '±2'],[4, 2, '绿=±0.5', 0x008000, '±0.5'],[4, 3, '蓝=±0.25', 0x0000FF, '±0.25'],[4, 4, '紫=±0.1', 0x800080, '±0.1'], _
                [4, 5, '灰=±0.05', 0x808080, '±0.05'],[4, 6, '金=±5', 0xFFD700, '±5'],[4, 7, '银=±10', 0xC0C0C0, '±10']]
Dim $Radios5[6][5] = [[5, 0, '棕=100ppm', 0x800000, '100ppm/℃'],[5, 1, '红=50ppm', 0xFF0000, '50ppm/℃'],[5, 2, '橙=15ppm', 0xFFA500, '15ppm/℃'],[5, 3, '黄=25ppm', 0xFFFF00, '25ppm/℃'],[5, 4, '蓝=10ppm', 0x0000FF, '10ppm/℃'], _
                [5, 5, '紫=5ppm', 0x800080, '5ppm/℃']]
Dim $i1 = 0, $i2 = 0, $i3 = 0, $i4 = 0, $i5 = 0, $i6 = 0
Dim $RdoR[6][10]
Dim $Group1_6[6] = ['第1位', '第2位', '第3位', '倍率(10^n)', '误差(%)', '温度系数(/℃)']

$Form1_1 = GUICreate("电阻计算器 v0.2 20230913", 640, 375)
$oeminfo = GUICtrlCreateLabel('邪恶海盗 www.hidao.org', 480, 1, 160, 18, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10)
GUICtrlSetColor(-1, 0x0000FF)
;GUISetFont(14)

$Tab1 = GUICtrlCreateTab(0, 0, 640, 375)
$TabSheet1 = GUICtrlCreateTabItem("色环转阻值")

$Group0 = GUICtrlCreateGroup($Group1_6[0], 10 + 95 * 0, 85, 85, 275)
For $Rn1_6 = 0 To 9
        $RdoR[0][$Rn1_6] = GUICtrlCreateRadio($Radios0[$Rn1_6][2], 15 + 0 * 95, 105 + 25 * $Rn1_6, 75, 25)
        GUICtrlSetColor(-1, 0xFFFFFF)
        GUICtrlSetBkColor(-1, $Radios0[$Rn1_6][3])
Next
GUICtrlSetColor($RdoR[0][4], 0x000000)
GUICtrlSetColor($RdoR[0][9], 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group1 = GUICtrlCreateGroup($Group1_6[1], 10 + 95 * 1, 85, 85, 275)
For $Rn1_6 = 0 To 9
        $RdoR[1][$Rn1_6] = GUICtrlCreateRadio($Radios1[$Rn1_6][2], 15 + 1 * 95, 105 + 25 * $Rn1_6, 75, 25)
        GUICtrlSetColor(-1, 0xFFFFFF)
        GUICtrlSetBkColor(-1, $Radios1[$Rn1_6][3])
Next
GUICtrlSetColor($RdoR[1][4], 0x000000)
GUICtrlSetColor($RdoR[1][9], 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group2 = GUICtrlCreateGroup($Group1_6[2], 10 + 95 * 2, 85, 85, 275)
For $Rn1_6 = 0 To 9
        $RdoR[2][$Rn1_6] = GUICtrlCreateRadio($Radios2[$Rn1_6][2], 15 + 2 * 95, 105 + 25 * $Rn1_6, 75, 25)
        GUICtrlSetColor(-1, 0xFFFFFF)
        GUICtrlSetBkColor(-1, $Radios2[$Rn1_6][3])
Next
GUICtrlSetColor($RdoR[2][4], 0x000000)
GUICtrlSetColor($RdoR[2][9], 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group3 = GUICtrlCreateGroup($Group1_6[3], 10 + 95 * 3, 85, 85, 275)
For $Rn1_6 = 0 To 9
        $RdoR[3][$Rn1_6] = GUICtrlCreateRadio($Radios3[$Rn1_6][2], 15 + 3 * 95, 105 + 25 * $Rn1_6, 75, 25)
        GUICtrlSetColor(-1, 0xFFFFFF)
        GUICtrlSetBkColor(-1, $Radios3[$Rn1_6][3])
Next
GUICtrlSetColor($RdoR[3][4], 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group4 = GUICtrlCreateGroup($Group1_6[4], 10 + 95 * 4, 85, 115, 275)
For $Rn1_6 = 0 To 7
        $RdoR[4][$Rn1_6] = GUICtrlCreateRadio($Radios4[$Rn1_6][2], 15 + 4 * 95, 105 + 25 * $Rn1_6, 105, 25)
        GUICtrlSetColor(-1, 0xFFFFFF)
        GUICtrlSetBkColor(-1, $Radios4[$Rn1_6][3])
Next
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group5 = GUICtrlCreateGroup($Group1_6[5], 10 + 95 * 4 + 115 + 10, 85, 115, 275)
For $Rn1_6 = 0 To 5
        $RdoR[5][$Rn1_6] = GUICtrlCreateRadio($Radios5[$Rn1_6][2], 15 + 4 * 95 + 115 + 10, 105 + 25 * $Rn1_6, 105, 25)
        GUICtrlSetColor(-1, 0xFFFFFF)
        GUICtrlSetBkColor(-1, $Radios5[$Rn1_6][3])
Next
GUICtrlSetColor($RdoR[5][3], 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlSetState($Group2, $GUI_HIDE)
GUICtrlSetState($Group4, $GUI_HIDE)
GUICtrlSetState($Group5, $GUI_HIDE)
For $Ri = 0 To 9
        GUICtrlSetState($RdoR[2][$Ri], $GUI_HIDE)
        GUICtrlSetState($RdoR[4][$Ri], $GUI_HIDE)
        GUICtrlSetState($RdoR[5][$Ri], $GUI_HIDE)
Next

$Radio30 = GUICtrlCreateRadio("3环电阻", 10, 30, 90, 25)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio40 = GUICtrlCreateRadio("4环电阻", 10, 55, 90, 25)
$Radio50 = GUICtrlCreateRadio("5环电阻", 105, 30, 90, 25)
$Radio60 = GUICtrlCreateRadio("6环电阻", 105, 55, 90, 25)
GUICtrlCreateLabel(" ", 200, 54, 10, 2, $SS_ETCHEDHORZ)
GUICtrlCreateLabel(" ", 205, 35, 180, 40, $SS_GRAYFRAME)
GUICtrlCreateLabel(" ", 385, 54, 10, 2, $SS_ETCHEDHORZ)
$Label01 = GUICtrlCreateLabel(" ", 220, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios0[0][3])
$Label02 = GUICtrlCreateLabel(" ", 245, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios1[0][3])
$Label03 = GUICtrlCreateLabel(" ", 270, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios2[0][3])
$Label04 = GUICtrlCreateLabel(" ", 295, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios3[0][3])
$Label05 = GUICtrlCreateLabel(" ", 330, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios4[0][3])
$Label06 = GUICtrlCreateLabel(" ", 355, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios5[0][3])
GUICtrlSetState($Label03, $GUI_HIDE)
GUICtrlSetState($Label05, $GUI_HIDE)
GUICtrlSetState($Label06, $GUI_HIDE)

$Lab1 = GUICtrlCreateLabel("计算过程及结果", 400, 25, 230, 25, $SS_SUNKEN + $SS_CENTERIMAGE)
;GUICtrlSetFont(-1,10)
$Lab2 = GUICtrlCreateLabel("计算过程及结果", 400, 50, 230, 25, $SS_SUNKEN + $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 11)

$TabSheet4 = GUICtrlCreateTabItem("串并联阻值计算")
;GUICtrlSetState(-1, $GUI_SHOW)
$Group7 = GUICtrlCreateGroup("串联阻值计算", 10, 35, 620, 135)
$InputR11 = GUICtrlCreateInput("", 24, 55, 80, 25, $SS_CENTER)
$Combo11 = GUICtrlCreateCombo("", 104, 55, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$InputR12 = GUICtrlCreateInput("", 174, 55, 80, 25, $SS_CENTER)
$Combo12 = GUICtrlCreateCombo("", 254, 55, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
GUICtrlCreateLabel("=", 314, 55, 25, 25, $SS_CENTER + $SS_CENTERIMAGE)
$InputR13 = GUICtrlCreateInput("?", 354, 55, 130, 25, $SS_CENTER)
GUICtrlSetState(-1, $GUI_DISABLE)
$ButtonR1 = GUICtrlCreateButton("计算", 500, 54, 65, 25)

$InputR21 = GUICtrlCreateInput("", 24, 95, 80, 25, $SS_CENTER)
$Combo21 = GUICtrlCreateCombo("", 104, 95, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$InputR22 = GUICtrlCreateInput("?", 174, 95, 130, 25, $SS_CENTER)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel("=", 314, 97, 25, 25, $SS_CENTER + $SS_CENTERIMAGE)
$InputR23 = GUICtrlCreateInput("", 354, 95, 80, 25, $SS_CENTER )
$Combo23 = GUICtrlCreateCombo("", 434, 95, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$ButtonR2 = GUICtrlCreateButton("计算", 500, 94, 65, 25)
GUICtrlCreateLabel('原理: R1 + R2 = R3', 30, 140, 200, 25)
GUICtrlSetFont(-1, 12)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group8 = GUICtrlCreateGroup("并联阻值计算", 10, 180, 620, 135)
$InputR31 = GUICtrlCreateInput("", 24, 200, 80, 25, $SS_CENTER )
$Combo31 = GUICtrlCreateCombo("", 104, 200, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$InputR32 = GUICtrlCreateInput("", 174, 200, 80, 25, $SS_CENTER )
$Combo32 = GUICtrlCreateCombo("", 254, 200, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
GUICtrlCreateLabel("=", 314, 200, 25, 25, $SS_CENTER + $SS_CENTERIMAGE)
$InputR33 = GUICtrlCreateInput("?", 354, 200, 130, 25, $SS_CENTER )
GUICtrlSetState(-1, $GUI_DISABLE)
$ButtonR3 = GUICtrlCreateButton("计算", 500, 200, 65, 25)

$InputR41 = GUICtrlCreateInput("", 24, 240, 80, 25, $SS_CENTER )
$Combo41 = GUICtrlCreateCombo(" ", 104, 240, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$InputR42 = GUICtrlCreateInput("?", 174, 240, 130, 25, $SS_CENTER )
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel("=", 314, 240, 25, 25, $SS_CENTER + $SS_CENTERIMAGE)
$InputR43 = GUICtrlCreateInput("", 354, 240, 80, 25, $SS_CENTER )
$Combo43 = GUICtrlCreateCombo("", 434, 240, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$ButtonR4 = GUICtrlCreateButton("计算", 500, 240, 65, 25)
GUICtrlCreateLabel('原理: 1/R1 + 1/R2 = 1/R3', 30, 285, 200, 25)
GUICtrlSetFont(-1, 12)
GUICtrlCreateTabItem("")

GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $oeminfo
                        ShellExecute('www.hidao.org')
                Case $Radio30
                        GUICtrlSetState($Label03, $GUI_HIDE)
                        GUICtrlSetState($Label05, $GUI_HIDE)
                        GUICtrlSetState($Label06, $GUI_HIDE)
                        GUICtrlSetState($Group2, $GUI_HIDE)
                        GUICtrlSetState($Group4, $GUI_HIDE)
                        GUICtrlSetState($Group5, $GUI_HIDE)
                        For $Ri = 0 To 9
                                GUICtrlSetState($RdoR[2][$Ri], $GUI_HIDE)
                                GUICtrlSetState($RdoR[4][$Ri], $GUI_HIDE)
                                GUICtrlSetState($RdoR[5][$Ri], $GUI_HIDE)
                        Next
                        _Calc()
                Case $Radio40
                        GUICtrlSetState($Label03, $GUI_HIDE)
                        GUICtrlSetState($Label05, $GUI_SHOW)
                        GUICtrlSetState($Label06, $GUI_HIDE)
                        GUICtrlSetState($Group2, $GUI_HIDE)
                        GUICtrlSetState($Group4, $GUI_SHOW)
                        GUICtrlSetState($Group5, $GUI_HIDE)
                        For $Ri = 0 To 9
                                GUICtrlSetState($RdoR[2][$Ri], $GUI_HIDE)
                        Next
                        For $Ri = 0 To 7
                                GUICtrlSetState($RdoR[4][$Ri], $GUI_SHOW)
                        Next
                        For $Ri = 0 To 5
                                GUICtrlSetState($RdoR[5][$Ri], $GUI_HIDE)
                        Next
                        _Calc()
                Case $Radio50
                        GUICtrlSetState($Label03, $GUI_SHOW)
                        GUICtrlSetState($Label05, $GUI_SHOW)
                        GUICtrlSetState($Label06, $GUI_HIDE)
                        GUICtrlSetState($Group2, $GUI_SHOW)
                        GUICtrlSetState($Group4, $GUI_SHOW)
                        GUICtrlSetState($Group5, $GUI_HIDE)
                        For $Ri = 0 To 9
                                GUICtrlSetState($RdoR[2][$Ri], $GUI_SHOW)
                                GUICtrlSetState($RdoR[4][$Ri], $GUI_SHOW)
                        Next
                        For $Ri = 0 To 5
                                GUICtrlSetState($RdoR[5][$Ri], $GUI_HIDE)
                        Next
                        _Calc()
                Case $Radio60
                        GUICtrlSetState($Label03, $GUI_SHOW)
                        GUICtrlSetState($Label05, $GUI_SHOW)
                        GUICtrlSetState($Label06, $GUI_SHOW)
                        GUICtrlSetState($Group2, $GUI_SHOW)
                        GUICtrlSetState($Group4, $GUI_SHOW)
                        GUICtrlSetState($Group5, $GUI_SHOW)
                        For $Ri = 0 To 9
                                GUICtrlSetState($RdoR[2][$Ri], $GUI_SHOW)
                                GUICtrlSetState($RdoR[4][$Ri], $GUI_SHOW)
                        Next
                        For $Ri = 0 To 5
                                GUICtrlSetState($RdoR[5][$Ri], $GUI_SHOW)
                        Next
                        _Calc()
                Case $RdoR[0][0] To $RdoR[0][9]
                        $i1 = $nMsg - $RdoR[0][0]
                        ;MsgBox(0,'',$Radios0[$i1][3])
                        _Calc()
                Case $RdoR[1][0] To $RdoR[1][9]
                        $i2 = $nMsg - $RdoR[1][0]
                        ;MsgBox(0,'',$Radios1[$i2][4])
                        _Calc()
                Case $RdoR[2][0] To $RdoR[2][9]
                        $i3 = $nMsg - $RdoR[2][0]
                        _Calc()
                Case $RdoR[3][0] To $RdoR[3][9]
                        $i4 = $nMsg - $RdoR[3][0]
                        _Calc()
                Case $RdoR[4][0] To $RdoR[4][7]
                        $i5 = $nMsg - $RdoR[4][0]
                        _Calc()
                Case $RdoR[5][0] To $RdoR[5][5]
                        $i6 = $nMsg - $RdoR[5][0]
                        _Calc()

                Case $ButtonR1
                        $R11 = GUICtrlRead($InputR11) * _Rx(GUICtrlRead($Combo11))
                        $R12 = GUICtrlRead($InputR12) * _Rx(GUICtrlRead($Combo12))
                        GUICtrlSetData($InputR13, _R2R($R11 + $R12))
                Case $ButtonR2
                        $R21 = GUICtrlRead($InputR21) * _Rx(GUICtrlRead($Combo21))
                        $R23 = GUICtrlRead($InputR23) * _Rx(GUICtrlRead($Combo23))
                        GUICtrlSetData($InputR22, _R2R($R23 - $R21))
                Case $ButtonR3
                        $R31 = GUICtrlRead($InputR31) * _Rx(GUICtrlRead($Combo31))
                        $R32 = GUICtrlRead($InputR32) * _Rx(GUICtrlRead($Combo32))
                        GUICtrlSetData($InputR33, _R2R(($R31 * $R32) / ($R31 + $R32)))
                Case $ButtonR4
                        $R41 = GUICtrlRead($InputR41) * _Rx(GUICtrlRead($Combo41))
                        $R43 = GUICtrlRead($InputR43) * _Rx(GUICtrlRead($Combo43))
                        GUICtrlSetData($InputR42, _R2R(($R41 * $R43) / ($R41 - $R43)))
        EndSwitch
WEnd

Func _Calc()
        GUICtrlSetBkColor($Label01, $Radios0[$i1][3])
        GUICtrlSetBkColor($Label02, $Radios1[$i2][3])
        GUICtrlSetBkColor($Label03, $Radios2[$i3][3])
        GUICtrlSetBkColor($Label04, $Radios3[$i4][3])
        GUICtrlSetBkColor($Label05, $Radios4[$i5][3])
        GUICtrlSetBkColor($Label06, $Radios5[$i6][3])
        If GUICtrlRead($Radio30) = $GUI_CHECKED Then
                $Var1 = ' ' & $Radios0[$i1][4] & ' ' & $Radios1[$i2][4] & ' ×10^' & $Radios3[$i4][4] & " = "
                $Var2 = ($Radios0[$i1][4] & $Radios1[$i2][4]) * 10 ^ $Radios3[$i4][4]
                $Var3 = '(误差:' & '±20' & '%)'
                ;GUICtrlSetData($Label1, ' ' & $i1 & ' ' & $i2 & ' ×10^' & $i4 & " = " & ($i1 & $i2) * 10 ^ $i4 & " Ω" & ' (误差:' & '20%' & ')')
        EndIf
        If GUICtrlRead($Radio40) = $GUI_CHECKED Then
                $Var1 = ' ' & $Radios0[$i1][4] & ' ' & $Radios1[$i2][4] & ' ×10^' & $Radios3[$i4][4] & " = "
                $Var2 = ($Radios0[$i1][4] & $Radios1[$i2][4]) * 10 ^ $Radios3[$i4][4]
                $Var3 = '(误差:' & $Radios4[$i5][4] & '%)'
                ;GUICtrlSetData($Label1, ' ' & $i1 & ' ' & $i2 & ' ×10^' & $i4 & " = " & ($i1 & $i2) * 10 ^ $i4 & " Ω" & ' (误差:' & $i5 & ')')
        EndIf
        If GUICtrlRead($Radio50) = $GUI_CHECKED Then
                $Var1 = ' ' & $Radios0[$i1][4] & ' ' & $Radios1[$i2][4] & ' ' & $Radios2[$i3][4] & ' ×10^' & $Radios3[$i4][4] & " = "
                $Var2 = ($Radios0[$i1][4] & $Radios1[$i2][4] & $Radios2[$i3][4]) * 10 ^ $Radios3[$i4][4]
                $Var3 = '(误差:' & $Radios4[$i5][4] & '%)'
                ;GUICtrlSetData($Label1, ' ' & $i1 & ' ' & $i2 & ' ' & $i3 & ' ×10^' & $i4 & " = " & ($i1 & $i2 & $i3) * 10 ^ $i4 & " Ω" & ' (误差:' & $i5 & ')')
        EndIf
        If GUICtrlRead($Radio60) = $GUI_CHECKED Then
                $Var1 = ' ' & $Radios0[$i1][4] & ' ' & $Radios1[$i2][4] & ' ' & $Radios2[$i3][4] & ' ×10^' & $Radios3[$i4][4] & " = "
                $Var2 = ($Radios0[$i1][4] & $Radios1[$i2][4] & $Radios2[$i3][4]) * 10 ^ $Radios3[$i4][4]
                $Var3 = '(误差:' & $Radios4[$i5][4] & '% 温度系数:' & $Radios5[$i6][4] & ')'
                ;GUICtrlSetData($Label1, ' ' & $i1 & ' ' & $i2 & ' ' & $i3 & ' ×10^' & $i4 & " = " & ($i1 & $i2 & $i3) * 10 ^ $i4 & " Ω" & ' (误差:±' & $i5 & ',温度:)' & $i6)
        EndIf
        
        GUICtrlSetData($Lab1, $Var1 & _R2R($Var2))
        GUICtrlSetData($Lab2, $Var3)
EndFunc   ;==>_Calc

Func _R2R($R2R)
        Switch $R2R
                Case $R2R < 999
                        Return Round($R2R, 2) & ' Ω'
                Case 1000 To 999999
                        Return Round($R2R / 1000, 2) & " KΩ"
                Case Else
                        Return Round($R2R / 1000000, 2) & " MΩ"
        EndSwitch
EndFunc   ;==>_R2R

Func _Rx($Rx)
        Switch $Rx
                Case 'Ω'
                        Return 1
                Case 'KΩ'
                        Return 1000
                Case 'MΩ'
                        Return 1000000
        EndSwitch
EndFunc   ;==>_Rx

本帖子中包含更多资源

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

×
发表于 2023-9-13 23:12:23 | 显示全部楼层
本帖最后由 afan 于 2023-9-13 23:23 编辑
邪恶海盗 发表于 2023-9-13 22:43
"优化"了一点,代码行数降低了一部分,不过感觉创建Radio还可以再优化,奈何一次性把所有Radios添加进数组可 ...

你的XP是经典主题,没有高级样式,才能设置文本颜色,否则也不行。当然也可以调用 uxtheme.dll 的 SetThemeAppProperties 函数设置窗口主题,只是控件较多,创建顺序要安排好,否则不一定好看或不符合预期。
Case[0][0] to Case [5][10] 估计你是没理解数组的定义,你要设计好具体的维数意义,一般不会这样跨行列to...
 楼主| 发表于 2023-9-14 00:25:51 | 显示全部楼层
本帖最后由 邪恶海盗 于 2023-9-14 00:27 编辑
afan 发表于 2023-9-13 23:12
你的XP是经典主题,没有高级样式,才能设置文本颜色,否则也不行。当然也可以调用 uxtheme.dll 的 SetThe ...


dim $Radios[10][5]=[GroupID,RadioID,Text,Color,Value]
dim $Radio[5][10]
for $Group = 0 to  5
guictrlctreategroup($Group)

if $Radios[$Group][0]=$Group then


for $Radion = 0 to 53
$Radio[$Group][$Radion]=guictrlcreateradio($Radio[$Radion][2])或者$Radio[$Radion]=
guictrlsetbkcolor(-1,$Radios[$Radion][3]
endif
guictrlctreategroup('')

case $Radio[0][0] to $Radio[5][10]或者case $Radio[0] to $Radio[53]
这两种好像都不对,捕捉到的消息值都大于54...


发表于 2023-9-14 09:35:49 | 显示全部楼层
邪恶海盗 发表于 2023-9-14 00:25
dim $Radios[10][5]=[GroupID,RadioID,Text,Color,Value]
dim $Radio[5][10]
for $Group = 0 to  5

你这已经进入死胡同了,帮你改或解释会很费时费力。主题问题早已解决,结贴吧,剩下的自己慢慢研究。
 楼主| 发表于 2023-9-14 11:18:04 | 显示全部楼层
afan 发表于 2023-9-14 09:35
你这已经进入死胡同了,帮你改或解释会很费时费力。主题问题早已解决,结贴吧,剩下的自己慢慢研究。

 楼主| 发表于 2023-9-14 22:28:25 | 显示全部楼层
afan 发表于 2023-9-14 09:35
你这已经进入死胡同了,帮你改或解释会很费时费力。主题问题早已解决,结贴吧,剩下的自己慢慢研究。

搞定了,原来是循环创建Group,然后在Group循环中创建Radio,这样导致Radio控件不是连续的所以消息ID不连续,现在改成了先循环创建Group,完成后再循环创建Radio并且隐藏分区,这样Radio就是连续的了...

#region AutoIt3Wrapper 预编译参数(常用参数)
#AutoIt3Wrapper_Icon=F:\AU3脚本\图标\hidao.ico  ;图标,支持EXE,DLL,ICO
#AutoIt3Wrapper_OutFile=R_Calc.exe   ;输出文件名
#AutoIt3Wrapper_OutFile_Type=exe   ;文件类型
#AutoIt3Wrapper_Compression=9  ;压缩等级
#AutoIt3Wrapper_UseUPX=y  ;使用压缩
#AutoIt3Wrapper_Res_Comment=R_Calc ;注释
#AutoIt3Wrapper_Res_Description=电阻计算器;详细信息
#AutoIt3Wrapper_Res_Fileversion=0.3.2023.914
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=;p    ;自动更新版本
#AutoIt3Wrapper_Res_LegalCopyright=邪恶海盗;版权
#endregion AutoIt3Wrapper 预编译参数(常用参数)
;#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
;#include <TabConstants.au3>
;#include <WindowsConstants.au3>
#NoTrayIcon
#region ### START Koda GUI section ### Form=f:\au3脚本\色环电阻.kxf

Dim $Radios[54][5] = [[0, 0, '黑=0', 0x000000, 0],[0, 1, '棕=1', 0x800000, 1],[0, 2, '红=2', 0xFF0000, 2],[0, 3, '橙=3', 0xFFA500, 3],[0, 4, '黄=4', 0xFFFF00, 4], _
                [0, 5, '绿=5', 0x008000, 5],[0, 6, '蓝=6', 0x0000FF, 6],[0, 7, '紫=7', 0x800080, 7],[0, 8, '灰=8', 0x808080, 8],[0, 9, '白=9', 0xFFFFFF, 9], _
                [1, 0, '黑=0', 0x000000, 0],[1, 1, '棕=1', 0x800000, 1],[1, 2, '红=2', 0xFF0000, 2],[1, 3, '橙=3', 0xFFA500, 3],[1, 4, '黄=4', 0xFFFF00, 4], _
                [1, 5, '绿=5', 0x008000, 5],[1, 6, '蓝=6', 0x0000FF, 6],[1, 7, '紫=7', 0x800080, 7],[1, 8, '灰=8', 0x808080, 8],[1, 9, '白=9', 0xFFFFFF, 9], _
                [2, 0, '黑=0', 0x000000, 0],[2, 1, '棕=1', 0x800000, 1],[2, 2, '红=2', 0xFF0000, 2],[2, 3, '橙=3', 0xFFA500, 3],[2, 4, '黄=4', 0xFFFF00, 4], _
                [2, 5, '绿=5', 0x008000, 5],[2, 6, '蓝=6', 0x0000FF, 6],[2, 7, '紫=7', 0x800080, 7],[2, 8, '灰=8', 0x808080, 8],[2, 9, '白=9', 0xFFFFFF, 9], _
                [3, 0, '黑=0', 0x000000, 0],[3, 1, '棕=1', 0x800000, 1],[3, 2, '红=2', 0xFF0000, 2],[3, 3, '橙=3', 0xFFA500, 3],[3, 4, '黄=4', 0xFFFF00, 4], _
                [3, 5, '绿=5', 0x008000, 5],[3, 6, '蓝=6', 0x0000FF, 6],[3, 7, '紫=7', 0x800080, 7],[3, 8, '金=-1', 0xFFD700, -1],[3, 9, '银=-2', 0xC0C0C0, -2], _
                [4, 0, '棕=±1', 0x800000, '±1'],[4, 1, '红=±2', 0xFF0000, '±2'],[4, 2, '绿=±0.5', 0x008000, '±0.5'],[4, 3, '蓝=±0.25', 0x0000FF, '±0.25'],[4, 4, '紫=±0.1', 0x800080, '±0.1'], _
                [4, 5, '灰=±0.05', 0x808080, '±0.05'],[4, 6, '金=±5', 0xFFD700, '±5'],[4, 7, '银=±10', 0xC0C0C0, '±10'], _
                [5, 0, '棕=100ppm', 0x800000, '100ppm/℃'],[5, 1, '红=50ppm', 0xFF0000, '50ppm/℃'],[5, 2, '橙=15ppm', 0xFFA500, '15ppm/℃'],[5, 3, '黄=25ppm', 0xFFFF00, '25ppm/℃'],[5, 4, '蓝=10ppm', 0x0000FF, '10ppm/℃'], _
                [5, 5, '紫=5ppm', 0x800080, '5ppm/℃']]
Dim $i = 0, $i1 = 0, $i2 = 0, $i3 = 0, $i4 = 0, $i5 = 0, $i6 = 0
Dim $RdoR[54]
Dim $Group1_6[6] = ['第1位', '第2位', '第3位', '倍率(10^n)', '误差(%)', '温度系数(/℃)']
Dim $Group[6]
Dim $left, $width

$Form1_1 = GUICreate("电阻计算器 v0.2 20230913", 640, 375)
$oeminfo = GUICtrlCreateLabel('邪恶海盗 www.hidao.org', 480, 1, 160, 18, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10)
GUICtrlSetColor(-1, 0x0000FF)
;GUISetFont(14)

$Tab1 = GUICtrlCreateTab(0, 0, 640, 375)
$TabSheet1 = GUICtrlCreateTabItem("色环转阻值")

$Radio30 = GUICtrlCreateRadio("3环电阻", 10, 30, 90, 25)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio40 = GUICtrlCreateRadio("4环电阻", 10, 55, 90, 25)
$Radio50 = GUICtrlCreateRadio("5环电阻", 105, 30, 90, 25)
$Radio60 = GUICtrlCreateRadio("6环电阻", 105, 55, 90, 25)
GUICtrlCreateLabel(" ", 200, 54, 10, 2, $SS_ETCHEDHORZ)
GUICtrlCreateLabel(" ", 205, 35, 180, 40, $SS_GRAYFRAME)
GUICtrlCreateLabel(" ", 385, 54, 10, 2, $SS_ETCHEDHORZ)
$Label01 = GUICtrlCreateLabel(" ", 220, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios[0][3])
$Label02 = GUICtrlCreateLabel(" ", 245, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios[0][3])
$Label03 = GUICtrlCreateLabel(" ", 270, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios[0][3])
$Label04 = GUICtrlCreateLabel(" ", 295, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios[0][3])
$Label05 = GUICtrlCreateLabel(" ", 330, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios[0][3])
$Label06 = GUICtrlCreateLabel(" ", 355, 34, 15, 42, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Radios[0][3])
GUICtrlSetState($Label03, $GUI_HIDE)
GUICtrlSetState($Label05, $GUI_HIDE)
GUICtrlSetState($Label06, $GUI_HIDE)

$Lab1 = GUICtrlCreateLabel("计算过程及结果", 400, 25, 230, 25, $SS_SUNKEN + $SS_CENTERIMAGE)
;GUICtrlSetFont(-1,10)
$Lab2 = GUICtrlCreateLabel("计算过程及结果", 400, 50, 230, 25, $SS_SUNKEN + $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 11)

For $GpID = 0 To 5
        _Left_Width()
        $Group[$GpID] = GUICtrlCreateGroup($Group1_6[$GpID], 10 + $left, 85, $width + 10, 275);创建所有Group
        ;GUICtrlCreateGroup("", -99, -99, 1, 1)
Next

For $GpID = 0 To 5
        _Left_Width()
        GUIStartGroup()
        For $R_ID = 0 To 53
                If $GpID = $Radios[$R_ID][0] Then
                        $RdoR[$R_ID] = GUICtrlCreateRadio($Radios[$R_ID][2], 15 + $left, 105 + 25 * $Radios[$R_ID][1], $width, 25);创建所有Radio
                        If $Radios[$R_ID][1] = 0 Then GUICtrlSetState(-1, $GUI_CHECKED)
                        GUICtrlSetColor(-1, 0xFFFFFF)
                        GUICtrlSetBkColor(-1, $Radios[$R_ID][3])
                EndIf
        Next
        GUIStartGroup()
        ;GUICtrlCreateGroup("", -99, -99, 1, 1)
Next
_GroupAndRadio_Control($GUI_HIDE, $GUI_HIDE, $GUI_HIDE)

$TabSheet4 = GUICtrlCreateTabItem("串并联阻值计算")
;GUICtrlSetState(-1, $GUI_SHOW)
$Group7 = GUICtrlCreateGroup("串联阻值计算", 10, 35, 620, 135)
$InputR11 = GUICtrlCreateInput("", 24, 55, 80, 25, $SS_CENTER)
$Combo11 = GUICtrlCreateCombo("", 104, 55, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$InputR12 = GUICtrlCreateInput("", 174, 55, 80, 25, $SS_CENTER)
$Combo12 = GUICtrlCreateCombo("", 254, 55, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
GUICtrlCreateLabel("=", 314, 55, 25, 25, $SS_CENTER + $SS_CENTERIMAGE)
$InputR13 = GUICtrlCreateInput("?", 354, 55, 130, 25, $SS_CENTER)
GUICtrlSetState(-1, $GUI_DISABLE)
$ButtonR1 = GUICtrlCreateButton("计算", 500, 54, 65, 25)

$InputR21 = GUICtrlCreateInput("", 24, 95, 80, 25, $SS_CENTER)
$Combo21 = GUICtrlCreateCombo("", 104, 95, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$InputR22 = GUICtrlCreateInput("?", 174, 95, 130, 25, $SS_CENTER)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel("=", 314, 97, 25, 25, $SS_CENTER + $SS_CENTERIMAGE)
$InputR23 = GUICtrlCreateInput("", 354, 95, 80, 25, $SS_CENTER)
$Combo23 = GUICtrlCreateCombo("", 434, 95, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$ButtonR2 = GUICtrlCreateButton("计算", 500, 94, 65, 25)
GUICtrlCreateLabel('原理: R1 + R2 = R3', 30, 140, 200, 25)
GUICtrlSetFont(-1, 12)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group8 = GUICtrlCreateGroup("并联阻值计算", 10, 180, 620, 135)
$InputR31 = GUICtrlCreateInput("", 24, 200, 80, 25, $SS_CENTER)
$Combo31 = GUICtrlCreateCombo("", 104, 200, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$InputR32 = GUICtrlCreateInput("", 174, 200, 80, 25, $SS_CENTER)
$Combo32 = GUICtrlCreateCombo("", 254, 200, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
GUICtrlCreateLabel("=", 314, 200, 25, 25, $SS_CENTER + $SS_CENTERIMAGE)
$InputR33 = GUICtrlCreateInput("?", 354, 200, 130, 25, $SS_CENTER)
GUICtrlSetState(-1, $GUI_DISABLE)
$ButtonR3 = GUICtrlCreateButton("计算", 500, 200, 65, 25)

$InputR41 = GUICtrlCreateInput("", 24, 240, 80, 25, $SS_CENTER)
$Combo41 = GUICtrlCreateCombo(" ", 104, 240, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$InputR42 = GUICtrlCreateInput("?", 174, 240, 130, 25, $SS_CENTER)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel("=", 314, 240, 25, 25, $SS_CENTER + $SS_CENTERIMAGE)
$InputR43 = GUICtrlCreateInput("", 354, 240, 80, 25, $SS_CENTER)
$Combo43 = GUICtrlCreateCombo("", 434, 240, 50, 25)
GUICtrlSetData(-1, "Ω|KΩ|MΩ", 'Ω')
$ButtonR4 = GUICtrlCreateButton("计算", 500, 240, 65, 25)
GUICtrlCreateLabel('原理: 1/R1 + 1/R2 = 1/R3', 30, 285, 200, 25)
GUICtrlSetFont(-1, 12)
GUICtrlCreateTabItem("")

GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $oeminfo
                        ShellExecute('www.hidao.org')
                Case $Radio30
                        _GroupAndRadio_Control($GUI_HIDE, $GUI_HIDE, $GUI_HIDE)
                        _Calc()
                Case $Radio40
                        _GroupAndRadio_Control($GUI_HIDE, $GUI_SHOW, $GUI_HIDE)
                        _Calc()
                Case $Radio50
                        _GroupAndRadio_Control($GUI_SHOW, $GUI_SHOW, $GUI_HIDE)
                        _Calc()
                Case $Radio60
                        _GroupAndRadio_Control($GUI_SHOW, $GUI_SHOW, $GUI_SHOW)
                        _Calc()
                Case $RdoR[0] To $RdoR[53]
                        ;MsgBox(0, '', $nMsg - $RdoR[0])
                        _Calc()
                Case $ButtonR1
                        $R11 = GUICtrlRead($InputR11) * _Rx(GUICtrlRead($Combo11))
                        $R12 = GUICtrlRead($InputR12) * _Rx(GUICtrlRead($Combo12))
                        GUICtrlSetData($InputR13, _R2R($R11 + $R12))
                Case $ButtonR2
                        $R21 = GUICtrlRead($InputR21) * _Rx(GUICtrlRead($Combo21))
                        $R23 = GUICtrlRead($InputR23) * _Rx(GUICtrlRead($Combo23))
                        GUICtrlSetData($InputR22, _R2R($R23 - $R21))
                Case $ButtonR3
                        $R31 = GUICtrlRead($InputR31) * _Rx(GUICtrlRead($Combo31))
                        $R32 = GUICtrlRead($InputR32) * _Rx(GUICtrlRead($Combo32))
                        GUICtrlSetData($InputR33, _R2R(($R31 * $R32) / ($R31 + $R32)))
                Case $ButtonR4
                        $R41 = GUICtrlRead($InputR41) * _Rx(GUICtrlRead($Combo41))
                        $R43 = GUICtrlRead($InputR43) * _Rx(GUICtrlRead($Combo43))
                        GUICtrlSetData($InputR42, _R2R(($R41 * $R43) / ($R41 - $R43)))
        EndSwitch
WEnd

Func _Calc()
        For $i = 0 To 9
                If GUICtrlRead($RdoR[$i]) = $GUI_CHECKED Then
                        GUICtrlSetBkColor($Label01, $Radios[$i][3])
                        $i1 = $Radios[$i][4]
                EndIf
        Next
        For $i = 10 To 19
                If GUICtrlRead($RdoR[$i]) = $GUI_CHECKED Then
                        GUICtrlSetBkColor($Label02, $Radios[$i][3])
                        $i2 = $Radios[$i][4]
                EndIf
        Next
        For $i = 20 To 29
                If GUICtrlRead($RdoR[$i]) = $GUI_CHECKED Then
                        GUICtrlSetBkColor($Label03, $Radios[$i][3])
                        $i3 = $Radios[$i][4]
                EndIf
        Next
        For $i = 30 To 39
                If GUICtrlRead($RdoR[$i]) = $GUI_CHECKED Then
                        GUICtrlSetBkColor($Label04, $Radios[$i][3])
                        $i4 = $Radios[$i][4]
                EndIf
        Next
        For $i = 40 To 47
                If GUICtrlRead($RdoR[$i]) = $GUI_CHECKED Then
                        GUICtrlSetBkColor($Label05, $Radios[$i][3])
                        $i5 = $Radios[$i][4]
                EndIf
        Next
        For $i = 48 To 53
                If GUICtrlRead($RdoR[$i]) = $GUI_CHECKED Then
                        GUICtrlSetBkColor($Label06, $Radios[$i][3])
                        $i6 = $Radios[$i][4]
                EndIf
        Next

        If GUICtrlRead($Radio30) = $GUI_CHECKED Then
                $Var1 = ' ' & $i1 & ' ' & $i2 & ' ×10^' & $i4 & " = "
                $Var2 = ($i1 & $i2) * (10 ^ $i4)
                $Var3 = '(误差:' & '±20' & '%)'
        EndIf
        If GUICtrlRead($Radio40) = $GUI_CHECKED Then
                $Var1 = ' ' & $i1 & ' ' & $i2 & ' ×10^' & $i4 & " = "
                $Var2 = $i1 & $i2 * (10 ^ $i4)
                $Var3 = '(误差:' & $i5 & '%)'
        EndIf
        If GUICtrlRead($Radio50) = $GUI_CHECKED Then
                $Var1 = ' ' & $i1 & ' ' & $i2 & ' ' & $i3 & ' ×10^' & $i4 & " = "
                $Var2 = ($i1 & $i2 & $i3) * (10 ^ $i4)
                $Var3 = '(误差:' & $i5 & '%)'
        EndIf
        If GUICtrlRead($Radio60) = $GUI_CHECKED Then
                $Var1 = ' ' & $i1 & ' ' & $i2 & ' ' & $i3 & ' ×10^' & $i4 & " = "
                $Var2 = ($i1 & $i2 & $i3) * (10 ^ $i4)
                $Var3 = '(误差:' & $i5 & '% 温度系数:' & $i6 & ')'
        EndIf

        GUICtrlSetData($Lab1, $Var1 & _R2R($Var2))
        GUICtrlSetData($Lab2, $Var3)

EndFunc   ;==>_Calc

Func _R2R($R2R)
        Switch $R2R
                Case $R2R < 999
                        Return Round($R2R, 2) & ' Ω'
                Case 1000 To 999999
                        Return Round($R2R / 1000, 2) & " KΩ"
                Case Else
                        Return Round($R2R / 1000000, 2) & " MΩ"
        EndSwitch
EndFunc   ;==>_R2R

Func _Rx($Rx)
        Switch $Rx
                Case 'Ω'
                        Return 1
                Case 'KΩ'
                        Return 1000
                Case 'MΩ'
                        Return 1000000
        EndSwitch
EndFunc   ;==>_Rx

Func _Left_Width()
        If $GpID < 4 Then
                $left = 85 * $GpID
                $width = 85 - 10
        Else
                $left = 85 * 4 + 115 * ($GpID - 4)
                $width = 115 - 10
        EndIf
EndFunc   ;==>_Left_Width

Func _GroupAndRadio_Control($GR2, $GR4, $GR5)
        GUICtrlSetState($Label03, $GR2)
        GUICtrlSetState($Label05, $GR4)
        GUICtrlSetState($Label06, $GR5)
        GUICtrlSetState($Group[2], $GR2)
        GUICtrlSetState($Group[4], $GR4)
        GUICtrlSetState($Group[5], $GR5)
        For $Ri = 20 To 29
                GUICtrlSetState($RdoR[$Ri], $GR2)
        Next
        For $Ri = 40 To 47
                GUICtrlSetState($RdoR[$Ri], $GR4)
        Next
        For $Ri = 48 To 53
                GUICtrlSetState($RdoR[$Ri], $GR5)
        Next
EndFunc   ;==>_GroupAndRadio_Control

发表于 2023-9-15 20:15:25 | 显示全部楼层
; 导入必要的库文件
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; 创建GUI窗口和组件
$Form1 = GUICreate("Form1", 432, 145, 192, 114)
$Input1 = GUICtrlCreateInput("", 56, 112, 97, 21)

; 定义数组
Local $aRadioLabels[4] = ["Radio1", "Radio2", "Radio3", "Radio4"]
Local $aRadioValues[4] = ["a", "b", "c", "d"]
Local $aRadio[4]

For $i = 0 To 3
    $aRadio[$i] = GUICtrlCreateRadio($aRadioLabels[$i], 40 + $i * 89, 32, 81, 25)
Next

GUISetState(@SW_SHOW)

; 主循环,监听GUI事件
While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    For $i = 0 To 3
        If $nMsg = $aRadio[$i] Then GUICtrlSetData($Input1, $aRadioValues[$i])
    Next
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-23 08:03 , Processed in 0.235796 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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