Что нового

Создание и удаление элементов GUI с помощью CheckBox

joparezzz

Новичок
Сообщения
65
Репутация
0
Не корректно работает создание и удаление элемента GUI при нажатии на $nCheckbox1
Код:
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <UpdownConstants.au3>

Global $iInput1
Global $iInput2

$hGUI = GUICreate('Кабельные вводы', 980, 250, -1, -1, -1, $WS_CLIPCHILDREN)
$nInput1 = 	GUICtrlCreateInput('23', 10, 10, 50, 20)
			GUICtrlCreateUpdown(-1, $UDS_ALIGNLEFT) ; слева
			GUICtrlSetLimit(-1, 99, 1)
$nInput2 = 	GUICtrlCreateInput('33', 75, 10, 50, 20)
			GUICtrlCreateUpdown(-1, $UDS_ALIGNRIGHT) ; справа
			GUICtrlSetLimit(-1, 99, 1)
$nCheckbox1 = GUICtrlCreateCheckbox('', 130, 10, 20, 20)
$nOutput1 = GUICtrlCreateEdit('', 160, 10, 400, 100)
$nOutput2 = GUICtrlCreateEdit('', 570, 10, 400, 100)
$nOutput3 = GUICtrlCreateEdit('', 160, 130, 400, 100)
$nOutput4 = GUICtrlCreateEdit('', 570, 130, 400, 100)


GUISetState()

Dim $TCM = 	[["ТСМ 20/0+5-12", 5, 12], _
			["ТСМ 30/0+13-23", 13, 23], _
			["ТСМ 40/0+23-33", 23, 33], _
			["ТСМ 60/0+34-51", 34, 51], _
			["ТСМ 90/0+52-78", 52, 78], _
			["ТСМ 120/0+79-99", 79, 99]]

Dim $RM =   [["RM 20 (∅4-14,5)", 4, 14.5], _
            ["RM 30 (∅10-25)", 10, 25], _
            ["RM 40 (∅21,5-34,5)", 21.5, 34.5], _
            ["RM 60 (∅28-54)", 28, 54], _
            ["RM 90 (∅48-71)", 48, 71], _
            ["RM 120 (∅67,5-99)", 67.5, 99]]

Dim $RMe =  [["RM 20w40 (∅3,5-16,5)", 3.5, 16.5], _
            ["RM 40 10-32 (∅9,5-32,5)", 9.5, 32.5], _
            ["RM 60 24-54 (∅24-54)", 24, 54]]

While 1
	$dn = GUICtrlRead($nInput1)
	$dk = GUICtrlRead($nInput2)

    Select
		Case $dn <> $iInput1
            CabTCM()
			CabTCM_1()
			CabRM()
			CabRM_1()
            $iInput1 = $dn

        Case $dk <> $iInput2
            CabTCM()
			CabTCM_1()
			CabRM()
			CabRM_1()
            $iInput2 = $dk

		Case $nCheckbox1
                If BitAND(GUICtrlRead($nCheckbox1),$GUI_CHECKED) Then
                    ConsoleWrite('Нажато' & @CRLF)
					$nInput3 = 	GUICtrlCreateInput('', 10, 40, 50, 20)
								GUICtrlCreateUpdown(-1, $UDS_ALIGNLEFT) ; слева
								GUICtrlSetLimit(-1, 99, 1)
					$nInput4 = 	GUICtrlCreateInput('', 75, 40, 50, 20)
								GUICtrlCreateUpdown(-1, $UDS_ALIGNRIGHT) ; справа
								GUICtrlSetLimit(-1, 99, 1)
					$nCheckbox2 = GUICtrlCreateCheckbox('', 130, 40, 20, 20)
                Else
                    ConsoleWrite('Не нажато' & @CRLF)
					;GUICtrlDelete ( $nInput3 )
                EndIf

    EndSelect

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd



Func CabTCM()
  If Int($dn) > Int($dk) Or $dn < $TCM[0][1] Or $dk > $TCM[UBound($TCM) - 1][2] Then Return GUICtrlSetData($nOutput1, "Некорректный диапазон")
  GUICtrlSetData($nOutput1, '∅' & $dn & '–' & $dk & ':' & @TAB)
  For $i = 0 To UBound($TCM) - 1
    If $dn <= $TCM[$i][2] Then
	  ;$n = $i
      For $i = $i To UBound($TCM) - 1
        If $dk > $TCM[$i][2] Then
          ConsoleWrite($TCM[$i][0] & ', ')
		  GUICtrlSetData($nOutput1, $TCM[$i][0] & ', ', 1)
	    Else
		  ;$k = $i
          ConsoleWrite($TCM[$i][0] & @CRLF)
		  GUICtrlSetData($nOutput1, $TCM[$i][0], 1)
          ExitLoop 2
        EndIf
      Next
    EndIf
  Next
EndFunc

Func CabRM()
  If Number($dn) > Number($dk) Or $dn < $RMe[0][1] Or $dk > $RM[UBound($RM) - 1][2] Then Return GUICtrlSetData($nOutput2, "Некорректный диапазон")
  GUICtrlSetData($nOutput2, '∅' & $dn & '–' & $dk & ':' & @TAB)
  For $i = 0 To UBound($RM) - 1
    If $dn >= $RM[$i][1] And $dk <= $RM[$i][2] Then Return GUICtrlSetData($nOutput2, $RM[$i][0], 1)
  Next
  For $i = 0 To UBound($RMe) - 1
    If $dn >= $RMe[$i][1] And $dk <= $RMe[$i][2] Then Return GUICtrlSetData($nOutput2, $RMe[$i][0], 1)
  Next
  ;GUICtrlSetData($nOutput2, "Не найдено")
  Local $j = -1, $RMt = $RM
  For $i = 0 To UBound($RM) - 1
    If $dn >= $RMt[$i][1] And $dn <= $RMt[$i][2] Then $j = $i
  Next
  If $j = -1 Then
    $RMt[0][0] = $RMe[0][0]
    $RMt[0][1] = $RMe[0][1]
    $RMt[0][2] = $RMe[0][2]
    $j = 0
  EndIf
  For $i = $j To UBound($RMt) - 1
    GUICtrlSetData($nOutput2, $RMt[$i][0] & ", ", 1)
    If $dk >= $RMt[$i][1] And $dk <= $RMt[$i][2] Then Return
  Next
EndFunc


Func CabTCM_1()
  If Number($dn) > Number($dk) Or $dn < $TCM[0][1] Or $dk > $TCM[UBound($TCM) - 1][2] Then Return GUICtrlSetData($nOutput3, "Некорректный диапазон")
  GUICtrlSetData($nOutput3, '∅' & $dn & '–' & $dk & ':' & @TAB)
  For $i = 0 To UBound($TCM) - 1
    If $dk <= $TCM[$i][2] Then
	  For $i = $i To 0 Step -1
		  If $dn >= $TCM[$i][1] Then
			GUICtrlSetData($nOutput3, $TCM[$i][0], 1)
		    ExitLoop 2
		  Else
			GUICtrlSetData($nOutput3, $TCM[$i][0] & ', ', 1)
		  EndIf
	  Next
	  Else
	EndIf
  Next
EndFunc

Func CabRM_1()
  If Number($dn) > Number($dk) Or $dn < $RMe[0][1] Or $dk > $RM[UBound($RM) - 1][2] Then Return GUICtrlSetData($nOutput4, "Некорректный диапазон")
  GUICtrlSetData($nOutput4, '∅' & $dn & '–' & $dk & ':' & @TAB)
  For $i = 0 To UBound($RM) - 1
    If $dn >= $RM[$i][1] And $dk <= $RM[$i][2] Then Return GUICtrlSetData($nOutput4, $RM[$i][0], 1)
  Next
  For $i = 0 To UBound($RMe) - 1
    If $dn >= $RMe[$i][1] And $dk <= $RMe[$i][2] Then Return GUICtrlSetData($nOutput4, $RMe[$i][0], 1)
  Next
  For $i = 0 To UBound($RM) - 1
    If $dk <= $RM[$i][2] Then
	  For $i = $i To 0 Step -1
		  If $dn >= $RM[$i][1] Then
			GUICtrlSetData($nOutput4, $RM[$i][0], 1)
		    ExitLoop 2
		  Else
			GUICtrlSetData($nOutput4, $RM[$i][0] & ', ', 1)
		  EndIf
	  Next
	  Else
	EndIf
  Next
EndFunc
 

InnI

AutoIT Гуру
Сообщения
4,949
Репутация
1,443
Код:
...
While 1
    $dn = GUICtrlRead($nInput1)
    $dk = GUICtrlRead($nInput2)

    If $dn <> $iInput1 Or $dk <> $iInput2 Then
        CabTCM()
        CabTCM_1()
        CabRM()
        CabRM_1()
        $iInput1 = $dn
        $iInput2 = $dk
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nCheckbox1
            If BitAND(GUICtrlRead($nCheckbox1), $GUI_CHECKED) Then
                ConsoleWrite('Нажато' & @CRLF)
                $nInput3 =  GUICtrlCreateInput('', 10, 40, 50, 20)
                $nUD3    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNLEFT) ; слева
                            GUICtrlSetLimit(-1, 99, 1)
                $nInput4 =  GUICtrlCreateInput('', 75, 40, 50, 20)
                $nUD4    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNRIGHT) ; справа
                            GUICtrlSetLimit(-1, 99, 1)
                $nCheckbox2 = GUICtrlCreateCheckbox('', 130, 40, 20, 20)
            Else
                ConsoleWrite('Не нажато' & @CRLF)
                GUICtrlDelete($nInput3)
                GUICtrlDelete($nInput4)
                GUICtrlDelete($nCheckbox2)
                GUICtrlDelete($nUD3)
                GUICtrlDelete($nUD4)
            EndIf
    EndSwitch
WEnd
...
 
Автор
J

joparezzz

Новичок
Сообщения
65
Репутация
0
Попытался добавить создание и удаление элементов GUI в функцию, но работает не корректно.

Код:
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <UpdownConstants.au3>

Global $iInput1
Global $iInput2
Global $nCheckbox2, $nCheckbox3, $nInput3, $nInput4, $nInput5, $nInput6, $nUD3, $nUD4, $nUD5, $nUD6
Global $nCheckbox4, $nInput7, $nInput8, $nUD7, $nUD8

$hGUI = GUICreate('Кабельные вводы', 980, 250, -1, -1, -1, $WS_CLIPCHILDREN)
$nInput1 = 	GUICtrlCreateInput('23', 10, 10, 50, 20)
			GUICtrlCreateUpdown(-1, $UDS_ALIGNLEFT) ; слева
			GUICtrlSetLimit(-1, 99, 1)
$nInput2 = 	GUICtrlCreateInput('33', 75, 10, 50, 20)
			GUICtrlCreateUpdown(-1, $UDS_ALIGNRIGHT) ; справа
			GUICtrlSetLimit(-1, 99, 1)
$nCheckbox1 = GUICtrlCreateCheckbox('', 130, 10, 20, 20)
$nOutput1 = GUICtrlCreateEdit('', 160, 10, 400, 100)
$nOutput2 = GUICtrlCreateEdit('', 570, 10, 400, 100)
$nOutput3 = GUICtrlCreateEdit('', 160, 130, 400, 100)
$nOutput4 = GUICtrlCreateEdit('', 570, 130, 400, 100)


GUISetState()

Dim $TCM = 	[["ТСМ 20/0+5-12", 5, 12], _
			["ТСМ 30/0+13-23", 13, 23], _
			["ТСМ 40/0+23-33", 23, 33], _
			["ТСМ 60/0+34-51", 34, 51], _
			["ТСМ 90/0+52-78", 52, 78], _
			["ТСМ 120/0+79-99", 79, 99]]

Dim $RM =   [["RM 20 (∅4-14,5)", 4, 14.5], _
            ["RM 30 (∅10-25)", 10, 25], _
            ["RM 40 (∅21,5-34,5)", 21.5, 34.5], _
            ["RM 60 (∅28-54)", 28, 54], _
            ["RM 90 (∅48-71)", 48, 71], _
            ["RM 120 (∅67,5-99)", 67.5, 99]]

Dim $RMe =  [["RM 20w40 (∅3,5-16,5)", 3.5, 16.5], _
            ["RM 40 10-32 (∅9,5-32,5)", 9.5, 32.5], _
            ["RM 60 24-54 (∅24-54)", 24, 54]]

While 1
    $dn = GUICtrlRead($nInput1)
    $dk = GUICtrlRead($nInput2)

    If $dn <> $iInput1 Or $dk <> $iInput2 Then
        CabTCM()
        CabTCM_1()
        CabRM()
        CabRM_1()
        $iInput1 = $dn
        $iInput2 = $dk
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nCheckbox1
			;Check($nCheckbox1, $nInput3, $nInput4, $nUD3, $nUD4, $nCheckbox2)
			;#cs
            If BitAND(GUICtrlRead($nCheckbox1), $GUI_CHECKED) Then
                ConsoleWrite('Checkbox1 нажат' & @CRLF)
                $nInput3 =  GUICtrlCreateInput('', 10, 40, 50, 20)
                $nUD3    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNLEFT) ; слева
                            GUICtrlSetLimit(-1, 99, 1)
                $nInput4 =  GUICtrlCreateInput('', 75, 40, 50, 20)
                $nUD4    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNRIGHT) ; справа
                            GUICtrlSetLimit(-1, 99, 1)
                $nCheckbox2 = GUICtrlCreateCheckbox('', 130, 40, 20, 20)
            Else
                ConsoleWrite('Checkbox1 не нажат' & @CRLF)
                GUICtrlDelete($nInput3)
                GUICtrlDelete($nInput4)
                GUICtrlDelete($nCheckbox2)
                GUICtrlDelete($nUD3)
                GUICtrlDelete($nUD4)
            EndIf
			;#ce
		Case $nCheckbox2
            If BitAND(GUICtrlRead($nCheckbox2), $GUI_CHECKED) Then
                ConsoleWrite('Checkbox2 нажат' & @CRLF)
                $nInput5 =  GUICtrlCreateInput('', 10, 70, 50, 20)
                $nUD5    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNLEFT) ; слева
                            GUICtrlSetLimit(-1, 99, 1)
                $nInput6 =  GUICtrlCreateInput('', 75, 70, 50, 20)
                $nUD6    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNRIGHT) ; справа
                            GUICtrlSetLimit(-1, 99, 1)
                $nCheckbox3 = GUICtrlCreateCheckbox('', 130, 70, 20, 20)
				GUICtrlSetState ($nCheckbox1,  $GUI_DISABLE)
            Else
                ConsoleWrite('Checkbox2 не нажат' & @CRLF)
                GUICtrlDelete($nInput5)
                GUICtrlDelete($nInput6)
                GUICtrlDelete($nCheckbox3)
                GUICtrlDelete($nUD5)
                GUICtrlDelete($nUD6)
				GUICtrlSetState ($nCheckbox1,  $GUI_ENABLE)
            EndIf

		Case $nCheckbox3
            If BitAND(GUICtrlRead($nCheckbox3), $GUI_CHECKED) Then
                ConsoleWrite('Checkbox2 нажат' & @CRLF)
                $nInput7 =  GUICtrlCreateInput('', 10, 100, 50, 20)
                $nUD7    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNLEFT) ; слева
                            GUICtrlSetLimit(-1, 99, 1)
                $nInput8 =  GUICtrlCreateInput('', 75, 100, 50, 20)
                $nUD8    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNRIGHT) ; справа
                            GUICtrlSetLimit(-1, 99, 1)
                $nCheckbox4 = GUICtrlCreateCheckbox('', 130, 100, 20, 20)
				GUICtrlSetState ($nCheckbox2,  $GUI_DISABLE)
            Else
                ConsoleWrite('Checkbox2 не нажат' & @CRLF)
                GUICtrlDelete($nInput7)
                GUICtrlDelete($nInput8)
                GUICtrlDelete($nCheckbox4)
                GUICtrlDelete($nUD7)
                GUICtrlDelete($nUD8)
				GUICtrlSetState ($nCheckbox2,  $GUI_ENABLE)
            EndIf

    EndSwitch
WEnd



Func Check($pCheckbox1, $pInput3, $pInput4, $pUD3, $pUD4, $pCheckbox2)
            If BitAND(GUICtrlRead($pCheckbox1), $GUI_CHECKED) Then
                ConsoleWrite('Checkbox1 нажат' & @CRLF)
                $pInput3 =  GUICtrlCreateInput('', 10, 40, 50, 20)
                $pUD3    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNLEFT) ; слева
                            GUICtrlSetLimit(-1, 99, 1)
                $pInput4 =  GUICtrlCreateInput('', 75, 40, 50, 20)
                $pUD4    =  GUICtrlCreateUpdown(-1, $UDS_ALIGNRIGHT) ; справа
                            GUICtrlSetLimit(-1, 99, 1)
                $pCheckbox2 = GUICtrlCreateCheckbox('', 130, 40, 20, 20)
            Else
                ConsoleWrite('Checkbox1 не нажат' & @CRLF)
                GUICtrlDelete($pInput3)
                GUICtrlDelete($pInput4)
                GUICtrlDelete($pCheckbox2)
                GUICtrlDelete($pUD3)
                GUICtrlDelete($pUD4)
            EndIf
EndFunc


Func CabTCM()
  If Int($dn) > Int($dk) Or $dn < $TCM[0][1] Or $dk > $TCM[UBound($TCM) - 1][2] Then Return GUICtrlSetData($nOutput1, "Некорректный диапазон")
  GUICtrlSetData($nOutput1, '∅' & $dn & '–' & $dk & ':' & @TAB)
  For $i = 0 To UBound($TCM) - 1
    If $dn <= $TCM[$i][2] Then
	  ;$n = $i
      For $i = $i To UBound($TCM) - 1
        If $dk > $TCM[$i][2] Then
          ConsoleWrite($TCM[$i][0] & ', ')
		  GUICtrlSetData($nOutput1, $TCM[$i][0] & ', ', 1)
	    Else
		  ;$k = $i
          ConsoleWrite($TCM[$i][0] & @CRLF)
		  GUICtrlSetData($nOutput1, $TCM[$i][0], 1)
          ExitLoop 2
        EndIf
      Next
    EndIf
  Next
EndFunc

Func CabRM()
  If Number($dn) > Number($dk) Or $dn < $RMe[0][1] Or $dk > $RM[UBound($RM) - 1][2] Then Return GUICtrlSetData($nOutput2, "Некорректный диапазон")
  GUICtrlSetData($nOutput2, '∅' & $dn & '–' & $dk & ':' & @TAB)
  For $i = 0 To UBound($RM) - 1
    If $dn >= $RM[$i][1] And $dk <= $RM[$i][2] Then Return GUICtrlSetData($nOutput2, $RM[$i][0], 1)
  Next
  For $i = 0 To UBound($RMe) - 1
    If $dn >= $RMe[$i][1] And $dk <= $RMe[$i][2] Then Return GUICtrlSetData($nOutput2, $RMe[$i][0], 1)
  Next
  ;GUICtrlSetData($nOutput2, "Не найдено")
  Local $j = -1, $RMt = $RM
  For $i = 0 To UBound($RM) - 1
    If $dn >= $RMt[$i][1] And $dn <= $RMt[$i][2] Then $j = $i
  Next
  If $j = -1 Then
    $RMt[0][0] = $RMe[0][0]
    $RMt[0][1] = $RMe[0][1]
    $RMt[0][2] = $RMe[0][2]
    $j = 0
  EndIf
  For $i = $j To UBound($RMt) - 1
    GUICtrlSetData($nOutput2, $RMt[$i][0] & ", ", 1)
    If $dk >= $RMt[$i][1] And $dk <= $RMt[$i][2] Then Return
  Next
EndFunc


Func CabTCM_1()
  If Number($dn) > Number($dk) Or $dn < $TCM[0][1] Or $dk > $TCM[UBound($TCM) - 1][2] Then Return GUICtrlSetData($nOutput3, "Некорректный диапазон")
  GUICtrlSetData($nOutput3, '∅' & $dn & '–' & $dk & ':' & @TAB)
  For $i = 0 To UBound($TCM) - 1
    If $dk <= $TCM[$i][2] Then
	  For $i = $i To 0 Step -1
		  If $dn >= $TCM[$i][1] Then
			GUICtrlSetData($nOutput3, $TCM[$i][0], 1)
		    ExitLoop 2
		  Else
			GUICtrlSetData($nOutput3, $TCM[$i][0] & ', ', 1)
		  EndIf
	  Next
	  Else
	EndIf
  Next
EndFunc

Func CabRM_1()
  If Number($dn) > Number($dk) Or $dn < $RMe[0][1] Or $dk > $RM[UBound($RM) - 1][2] Then Return GUICtrlSetData($nOutput4, "Некорректный диапазон")
  GUICtrlSetData($nOutput4, '∅' & $dn & '–' & $dk & ':' & @TAB)
  For $i = 0 To UBound($RM) - 1
    If $dn >= $RM[$i][1] And $dk <= $RM[$i][2] Then Return GUICtrlSetData($nOutput4, $RM[$i][0], 1)
  Next
  For $i = 0 To UBound($RMe) - 1
    If $dn >= $RMe[$i][1] And $dk <= $RMe[$i][2] Then Return GUICtrlSetData($nOutput4, $RMe[$i][0], 1)
  Next
  For $i = 0 To UBound($RM) - 1
    If $dk <= $RM[$i][2] Then
	  For $i = $i To 0 Step -1
		  If $dn >= $RM[$i][1] Then
			GUICtrlSetData($nOutput4, $RM[$i][0], 1)
		    ExitLoop 2
		  Else
			GUICtrlSetData($nOutput4, $RM[$i][0] & ', ', 1)
		  EndIf
	  Next
	  Else
	EndIf
  Next
EndFunc
 
Верх