Войти

Показать полную графическую версию : [решено] Вызов одной формы из другой


eus_deus
08-09-2013, 13:03
Всем привет! Следующий вопрос - как вызвать одну форму из другой, чтобы обе формы взаимно видели элементы друг друга. Я думал, чтобы не загромождать код двумя формами, разделить его и вызывать по необходимости. Дошел только до #include одного скрипта в другой. Думал, будет как по аналогии с бейсиком - форма1.Поле1=Форма2.Поле1... ну как то так, давно это было... Или это не возможно в принципе?

Creat0R
08-09-2013, 21:55
как вызвать одну форму из другой, чтобы обе формы взаимно видели элементы друг друга »
Как то так:

#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <WindowsConstants.au3>

$hForm1 = GUICreate (http://autoit-script.ru/autoit3_docs/functions/GUICreate.htm)('Form1', 300, 200, 100, 100)
$hForm2 = GUICreate (http://autoit-script.ru/autoit3_docs/functions/GUICreate.htm)('Form2', 300, 200, 450, 100)

$aForm1_Elements = _FormElements($hForm1)
$aForm2_Elements = _FormElements($hForm2)

GUISetState (http://autoit-script.ru/autoit3_docs/functions/GUISetState.htm)(@SW_SHOW (http://autoit-script.ru/autoit3_docs/macros.htm#@sw_show), $hForm1)
GUISetState (http://autoit-script.ru/autoit3_docs/functions/GUISetState.htm)(@SW_SHOW (http://autoit-script.ru/autoit3_docs/macros.htm#@sw_show), $hForm2)

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$iMsg = GUIGetMsg (http://autoit-script.ru/autoit3_docs/functions/GUIGetMsg.htm)()

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $iMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $aForm1_Elements[1] To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aForm1_Elements[$aForm1_Elements[0]]
MsgBox (http://autoit-script.ru/autoit3_docs/functions/MsgBox.htm)(64, 'Event', 'Event from element (' & GUICtrlRead (http://autoit-script.ru/autoit3_docs/functions/GUICtrlRead.htm)($iMsg, 1) & ') in form 1', 0, $hForm1)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $aForm2_Elements[1] To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aForm2_Elements[$aForm2_Elements[0]]
MsgBox (http://autoit-script.ru/autoit3_docs/functions/MsgBox.htm)(64, 'Event', 'Event from element (' & GUICtrlRead (http://autoit-script.ru/autoit3_docs/functions/GUICtrlRead.htm)($iMsg, 1) & ') in form 2', 0, $hForm2)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _FormElements($hForm)
GUISwitch (http://autoit-script.ru/autoit3_docs/functions/GUISwitch.htm)($hForm)

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aRet[3] = [2]

$aRet[1] = GUICtrlCreateButton (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateButton.htm)('Button1', 20, 20, 60, 20)
$aRet[2] = GUICtrlCreateButton (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateButton.htm)('Button2', 20, 40, 60, 20)

Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $aRet
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

eus_deus
08-09-2013, 22:00
Creat0R, общую суть вроде уловил. попробую переделать код. надо, чтобы второе окно появлялось по необходимости при нажатии на кнопку

Creat0R
08-09-2013, 22:45
надо, чтобы второе окно появлялось по необходимости при нажатии на кнопку »
#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <WindowsConstants.au3>

$hForm1 = GUICreate (http://autoit-script.ru/autoit3_docs/functions/GUICreate.htm)('Form1', 300, 200, 100, 100)
$iShowForm2_Bttn = GUICtrlCreateButton (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateButton.htm)('Show Form2', 20, 170, 90, 20)
$aForm1_Elements = _FormElements($hForm1)

$hForm2 = GUICreate (http://autoit-script.ru/autoit3_docs/functions/GUICreate.htm)('Form2', 300, 200, 450, 100)
$aForm2_Elements = _FormElements($hForm2)

GUISetState (http://autoit-script.ru/autoit3_docs/functions/GUISetState.htm)(@SW_SHOW (http://autoit-script.ru/autoit3_docs/macros.htm#@sw_show), $hForm1)

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$aMsg = GUIGetMsg (http://autoit-script.ru/autoit3_docs/functions/GUIGetMsg.htm)(1)

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $aMsg[0]
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aMsg[1] = $hForm1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
ContinueCase (http://www.autoitscript.com/autoit3/docs/keywords.htm#ContinueCase) ;To trigger next state
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $iShowForm2_Bttn
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) GUICtrlRead (http://autoit-script.ru/autoit3_docs/functions/GUICtrlRead.htm)($iShowForm2_Bttn) = 'Show Form2' Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetData (http://autoit-script.ru/autoit3_docs/functions/GUICtrlSetData.htm)($iShowForm2_Bttn, 'Hide Form2')
GUISetState (http://autoit-script.ru/autoit3_docs/functions/GUISetState.htm)(@SW_SHOW (http://autoit-script.ru/autoit3_docs/macros.htm#@sw_show), $hForm2)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
GUICtrlSetData (http://autoit-script.ru/autoit3_docs/functions/GUICtrlSetData.htm)($iShowForm2_Bttn, 'Show Form2')
GUISetState (http://autoit-script.ru/autoit3_docs/functions/GUISetState.htm)(@SW_HIDE (http://autoit-script.ru/autoit3_docs/macros.htm#@sw_hide), $hForm2)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $aForm1_Elements[1] To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aForm1_Elements[$aForm1_Elements[0]]
MsgBox (http://autoit-script.ru/autoit3_docs/functions/MsgBox.htm)(64, 'Event', 'Event from element (' & GUICtrlRead (http://autoit-script.ru/autoit3_docs/functions/GUICtrlRead.htm)($aMsg[0], 1) & ') in form 1', 0, $hForm1)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $aForm2_Elements[1] To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aForm2_Elements[$aForm2_Elements[0]]
MsgBox (http://autoit-script.ru/autoit3_docs/functions/MsgBox.htm)(64, 'Event', 'Event from element (' & GUICtrlRead (http://autoit-script.ru/autoit3_docs/functions/GUICtrlRead.htm)($aMsg[0], 1) & ') in form 2', 0, $hForm2)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _FormElements($hForm)
GUISwitch (http://autoit-script.ru/autoit3_docs/functions/GUISwitch.htm)($hForm)

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aRet[3] = [2]

$aRet[1] = GUICtrlCreateButton (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateButton.htm)('Button1', 20, 20, 60, 20)
$aRet[2] = GUICtrlCreateButton (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateButton.htm)('Button2', 20, 40, 60, 20)

Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $aRet
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

eus_deus
08-09-2013, 22:52
Creat0R, ну ты прямо бог autoit'a. Добей меня уже тогда - а если нужны разные контролы на форме, то как их прописать в функцию Func _FormElements($hForm)? Назначение формы - форма настройки. Вроде не нужна на экране постоянно, но в то же время ее наличие необходимо

Creat0R
08-09-2013, 23:54
а если нужны разные контролы на форме »
То это уже другая тема.
Ты определись что тебе нужно, в первом сообщении спрашивается о синхронизации элементов в разных формах, теперь уже речь идёт о другом.

Может лучше опишешь задачу, чтобы был понятен конечный результат?

eus_deus
09-09-2013, 12:00
чтобы обе формы взаимно видели элементы друг друга »
это вроде не синхронизация... я подразумевал, что по действиям контролов первой формы что то изменится на контролах второй и наоборот. но контролы разные. прошу прощения за не внесение ясности в вопрос

eus_deus
09-09-2013, 12:17
в принципе вопрос решен. мне нужно было только понятие того, что весь код будет в одном модуле, а не в разных, как я это строил. помог код для кнопки
Case $iShowForm2_Bttn
If GUICtrlRead($iShowForm2_Bttn) = 'Show Form2' Then
GUICtrlSetData($iShowForm2_Bttn, 'Hide Form2')
GUISetState(@SW_SHOW, $hForm2)
Else
GUICtrlSetData($iShowForm2_Bttn, 'Show Form2')
GUISetState(@SW_HIDE, $hForm2)
EndIf
дело за малым - как при закрытии второй формы по крестику, не закрывать первую?

Creat0R
09-09-2013, 12:49
как при закрытии второй формы по крестику, не закрывать первую? »
За обработку закрытия отвечает Case $GUI_EVENT_CLOSE, в последнем примере как раз вторя форма прячется не закрывая весь скрипт.

eus_deus
09-09-2013, 13:09
Creat0R, вопросов нет. по крайней мере, не в этой теме. Здесь вопрос решен




© OSzone.net 2001-2012