autoit 发表于 2008-5-3 14:20:00

GUI设计与制作入门(二)

<strong>二)按钮的控制与应用<br /></strong>按钮的控制与应用主要是用来完成一项任务或控制某一个部件的动作。<br />&nbsp;&nbsp;&nbsp; 1、控制的基本方法。一般按钮使用变量来设计与控制。即:<br /><span style="color: #f73809">$OK = GUICtrlCreateButton (&quot;按钮OK&quot;, 10,20,80,40)<br />$Cancel = GUICtrlCreateButton (&quot;按钮Cancel&quot;, 150,20,80,40)<br /></span>按钮的控制语句应放在循环判断语句当中。即:在下列循环判断语句当中&quot;...&quot;中加入控制语句。<br /><span style="color: #f70909">While 1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $msg = GUIGetMsg()<br />...<br />WEnd<br /></span>示例脚本如下:<br /><span style="color: #f73809">#i nclude &lt;GUIConstants.au3&gt;<br />GUICreate (&quot;我的图标按钮&quot;,400,200)<br />GUISetBkColor (0xE0FFFF)&nbsp; ; 设置自己喜欢的色彩<br />$OK = GUICtrlCreateButton (&quot;按钮OK&quot;, 10,20,80,40)<br />$Cancel = GUICtrlCreateButton (&quot;按钮Cancel&quot;, 150,20,80,40)<br />GUISetState(@SW_SHOW)<br />While 1<br />&nbsp; $msg = GUIGetMsg()<br />&nbsp; Select<br />&nbsp;&nbsp;&nbsp; Case $msg = $ok<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(0, &quot;按钮的控制&quot;, &quot;控制成功!&quot;)<br />&nbsp;&nbsp;&nbsp; Case $msg = $GUI_EVENT_CLOSE or $msg = $Cancel<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(0, &quot;按钮的控制&quot;, &quot;控制结束! 按确定或关闭窗口将自动退出程序...!&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExitLoop<br />&nbsp; EndSelect<br />WEnd<br /></span>&nbsp;&nbsp;&nbsp; 2、循环判断的设置。一般循环判断语句在While...Wend中通常用以下两种语句。即:Select...Case...EndSelect与If &lt;expression&gt; Then(或If...ElseIf...Else...EndIf)(详见帮助文件)。两种判断语句示例脚本:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第一种:<br /><span style="color: #ff0000">While 1<br />&nbsp; $msg = GUIGetMsg()<br />&nbsp; Select<br />&nbsp;&nbsp;&nbsp; Case $msg = $ok1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(0, &quot;按钮的控制1&quot;, &quot;控制1!&quot;)<br />&nbsp;&nbsp;&nbsp; Case $msg = $ok2<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(0, &quot;按钮的控制&quot;, &quot;控制2!&quot;)<br />&nbsp;&nbsp;&nbsp; Case $msg = $ok3<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(0, &quot;按钮的控制&quot;, &quot;控制3!&quot;)<br />&nbsp;&nbsp;&nbsp; Case $msg = $ok4<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(0, &quot;按钮的控制&quot;, &quot;控制4!&quot;)<br />... <br />&nbsp;&nbsp;&nbsp; Case $msg = $GUI_EVENT_CLOSE or $msg = $Cancel<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(0, &quot;按钮的控制&quot;, &quot;控制结束! &quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExitLoop<br />&nbsp; EndSelect<br />WEnd<br /></span>这一种判断语句可以设置无限的按钮,只要你的窗口能放下无限的按钮。每一个Case只能控制或完成一项任务,也就是一事一办。当然在Case里面还可以增加下一级或更多级的判断。如增加If &lt;expression&gt; Then语句,也可以增加Select...Case...EndSelect语句(这种情况较为复杂,新手不宜)。<br />&nbsp;&nbsp;&nbsp; 第二种:<br /><span style="color: #ff0000">While 1<br />$msg = GUIGetMsg()<br />&nbsp; if&nbsp; $msg = $exit&nbsp; Then <br />&nbsp;&nbsp;&nbsp;&nbsp;  MsgBox(0, &quot;退出&quot;, &quot;退出控制吗!&quot;) <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit<br />&nbsp;  EndIf<br />if&nbsp; $msg =&nbsp; $ok1&nbsp; Then<br />&nbsp;&nbsp;   $Box = MsgBox(0, &quot;按钮的控制1&quot;, &quot;控制1!&quot;)<br />&nbsp;&nbsp;&nbsp;     if&nbsp; $Box = 1&nbsp; Then&nbsp; RUN(&quot;Setup1.exe&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit<br />EndIf<br />if&nbsp; $msg =&nbsp; $ok2&nbsp; Then<br />&nbsp;&nbsp;   $Box2 = MsgBox(0, &quot;按钮的控制2&quot;, &quot;控制2!&quot;)<br />&nbsp;&nbsp;&nbsp;     if&nbsp; $Box2 = 1&nbsp; Then&nbsp; RUN(&quot;Setup2.exe&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit<br />EndIf<br />if&nbsp; $msg =&nbsp; $ok3&nbsp; Then<br />&nbsp;&nbsp;   $Box3 = MsgBox(0, &quot;按钮的控制3&quot;, &quot;控制3!&quot;)<br />&nbsp;&nbsp;&nbsp;     if&nbsp; $Box3 = 1&nbsp; Then&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RUN(&quot;Setup3.exe&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    EndIf<br />EndIf<br />... <br />WEnd<br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 从示例看,这一种判断语句也同样可以设置无限的按钮,只要你的窗口能放下无限的按钮。每一个If &lt;expression&gt; Then也同样只能控制或完成一项任务。在If &lt;expression&gt; Then里面也可以增加下一级的判断。如增加Select...Case...EndSelect。看示例:<br /><span style="color: #ff0000">While 1<br />$msg = GUIGetMsg()<br />&nbsp; if&nbsp; $msg = $exit&nbsp; Then <br />&nbsp;&nbsp;&nbsp;&nbsp;  MsgBox(0, &quot;退出&quot;, &quot;退出控制吗!&quot;) <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit<br />&nbsp;  EndIf<br />if&nbsp; $msg =&nbsp; $ok&nbsp; Then<br />&nbsp;&nbsp;   Select<br />&nbsp;&nbsp;&nbsp;    Case $msg = $ok1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     MsgBox(0, &quot;按钮的控制1&quot;, &quot;控制1!&quot;)<br />&nbsp;&nbsp;&nbsp;    Case $msg = $ok2<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     MsgBox(0, &quot;按钮的控制&quot;, &quot;控制2!&quot;)<br />&nbsp;&nbsp;&nbsp;    Case $msg = $ok3<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     MsgBox(0, &quot;按钮的控制&quot;, &quot;控制3!&quot;)<br />&nbsp;&nbsp;&nbsp;    Case $msg = $ok4<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     MsgBox(0, &quot;按钮的控制&quot;, &quot;控制4!&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... <br />&nbsp;&nbsp;     Case $msg = $GUI_EVENT_CLOSE&nbsp; or&nbsp; $msg = $Cancel<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     MsgBox(0, &quot;按钮的控制&quot;, &quot;控制结束! &quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     ExitLoop<br />&nbsp;    EndSelect<br />EndIf<br />WEnd<br /></span>&nbsp;&nbsp;&nbsp; 3、注意的事项。在运用判断语句时,无论是用Select...Case...EndSelect语句,还是用If &lt;expression&gt; Then语句时,都要注意:设计任务或动作的脚本最好是在判断语句中一次运行完。另外,关闭窗口和退出的语句都不要忘记加上。如($msg = $GUI_EVENT_CLOSE;$msg = $exit)。特别是在多级判断语句里,不要忘记退出循环的语句。如(ExitLoop;EndSelect;EndIf;WEnd)。<br />&nbsp;&nbsp;&nbsp; 关于GUI设计中的其他控件的制作与应用将在第三讲中详细解答。<br />

cxlswb 发表于 2008-5-7 17:57:39

等待底3讲 速度

kakinkgb 发表于 2008-5-7 22:20:57

请作者或autoit把第三部贴↑

botanycc 发表于 2008-5-7 22:32:40

又可以学习一下了

qq123140262 发表于 2008-5-7 23:02:54

顶下..学习中

蓓蕾 发表于 2008-6-30 18:36:33

请上第三讲,急等中

皓龙 发表于 2008-8-13 18:57:17

没有第三贴了么?:face (7):

amgloon 发表于 2008-9-1 10:03:27

第三贴呢??没找到。- -

飘渺风 发表于 2008-9-18 17:56:57

呵呵,谢谢分享,支持楼主!!!

飘渺风 发表于 2008-9-18 17:57:16

很强大,谢谢楼主分享!!!!!

czzqi 发表于 2008-10-26 00:32:10

盼望LZ有空出第三.

流氓兔 发表于 2009-5-17 22:54:50

没有第三帖了吗

bachelor66 发表于 2009-5-27 14:20:23

等待三帖……

maples 发表于 2009-5-29 01:26:57

LZ做得很好,对新手很有帮助

zcx880517 发表于 2009-12-9 20:49:00

好东西。。感谢分享
页: [1] 2
查看完整版本: GUI设计与制作入门(二)