找回密码
 加入
搜索
查看: 2281|回复: 9

关于多窗体如何实现移动后仍然重合的问题

[复制链接]
发表于 2008-8-1 16:35:37 | 显示全部楼层 |阅读模式
比如在设计向导式窗体时,打开第一个窗体后,用鼠标对窗体进行了移动,然后隐藏第一个窗体,打开第二个窗体,这时打开的第二个窗体在屏幕的位置是第一个窗体的初始位置,我的问题是如何让第二个窗体打开时与第一个窗体处在同一个位置,也就二个窗体实际是重合的。反之,第二个窗体移动后,打开第一个也与第二个窗体重合。

本问题在各位朋友特别是在顽固不化朋友的帮助下,问题已经解决。谢谢!

[ 本帖最后由 即即 于 2008-8-4 14:33 编辑 ]
发表于 2008-8-2 18:19:28 | 显示全部楼层
第二个窗口对应第一个窗口的大小和X,Y坐标即可。
 楼主| 发表于 2008-8-3 18:01:11 | 显示全部楼层

回复 2# sanhen 的帖子

老大,还没有理解这个问题,能否举个例子,谢谢。
发表于 2008-8-3 19:47:55 | 显示全部楼层
GUICreate("test GUISetTextColor", 100,100,第一个窗口X,第一个窗口Y)
发表于 2008-8-3 20:08:04 | 显示全部楼层
建议用单窗口
 楼主| 发表于 2008-8-4 10:53:51 | 显示全部楼层
quote]原帖由 顽固不化 于 2008-8-3 19:47 发表
GUICreate("test GUISetTextColor", 100,100,第一个窗口X,第一个窗口Y) [/quote]


       是否不能实现我说的情况,一旦移动了某个窗口,这个窗口的坐标就发生了改变,而另一个窗口仍然还是他原来的坐标,因而也就不能实现重合的状态。

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("第一个窗体", 440, 243, 193, 125)
$LabelA1 = GUICtrlCreateLabel("第一个窗体", 112, 64, 64, 17)
$ButtonA1 = GUICtrlCreateButton("打开2", 96, 160, 75, 25, 0)
$ButtonA2 = GUICtrlCreateButton("退出", 256, 160, 75, 25, 0)
$Form2 = GUICreate("第二个窗体", 440, 243, 193, 125)
$LabelB1 = GUICtrlCreateLabel("第二个窗体", 112, 64, 64, 17)
$ButtonB1 = GUICtrlCreateButton("返回1", 96, 160, 75, 25, 0)
$ButtonB2 = GUICtrlCreateButton("退出", 256, 160, 75, 25, 0)

GUISwitch($Form1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg(1)
        Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                        Switch $nMsg[1]
                                Case $Form1
                                        Exit
                                Case $Form2
                                        _Open_Close_Form($Form1, $Form2)
                        EndSwitch
                Case $ButtonA1
                        _Open_Close_Form($Form2, $Form1)
                Case $ButtonA2
                        Exit
                Case $ButtonB1
                        _Open_Close_Form($Form1, $Form2)
                Case $ButtonB2
                        _Open_Close_Form($Form1, $Form2)
        EndSwitch
WEnd

Func _Open_Close_Form($OForm, $CForm)
        GUISwitch($OForm)
        GUISetState(@SW_SHOW)
        GUISwitch($CForm)
        GUISetState(@SW_HIDE)
EndFunc   ;==>_Open_Close_Form

[ 本帖最后由 即即 于 2008-8-4 10:57 编辑 ]
 楼主| 发表于 2008-8-4 11:00:27 | 显示全部楼层

回复 5# pcbar 的帖子

建议用单窗口,是否是采用隐藏控件和打开控件的方法来实现。
发表于 2008-8-4 11:32:00 | 显示全部楼层
au3那么多函数,你就不会跟踪第一个窗口的坐标?下面是修改的,现在就是移动第2个窗口,第一个也能在第二个的位置打开。
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("第一个窗体", 440, 243, 193, 125)
$LabelA1 = GUICtrlCreateLabel("第一个窗体", 112, 64, 64, 17)
$ButtonA1 = GUICtrlCreateButton("打开2", 96, 160, 75, 25, 0)
$ButtonA2 = GUICtrlCreateButton("退出", 256, 160, 75, 25, 0)
$Form2 = GUICreate("第二个窗体", 440, 243, 193, 125)
$LabelB1 = GUICtrlCreateLabel("第二个窗体", 112, 64, 64, 17)
$ButtonB1 = GUICtrlCreateButton("返回1", 96, 160, 75, 25, 0)
$ButtonB2 = GUICtrlCreateButton("退出", 256, 160, 75, 25, 0)
GUISwitch($Form1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg(1)
        Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                        Switch $nMsg[1]
                                Case $Form1
                                        Exit
                                Case $Form2
                                        $XY = WinGetPos($Form1)
                                        $XY2 = WinGetPos($Form2)
                                        If $XY2[0] <> $XY[0] Or $XY2[1] <> $XY[1] Then
                                                WinMove($Form1, "", $XY2[0], $XY2[1])
                                        EndIf
                                        _Open_Close_Form($Form1, $Form2)
                        EndSwitch
                Case $ButtonA1
                        $XY = WinGetPos($Form1)
                        $XY2 = WinGetPos($Form2)
                        If $XY2[0] <> $XY[0] Or $XY2[1] <> $XY[1] Then
                                WinMove($Form2, "", $XY[0], $XY[1])
                        EndIf
                        _Open_Close_Form($Form2, $Form1)
                Case $ButtonA2
                        Exit
                Case $ButtonB1
                        $XY = WinGetPos($Form1)
                        $XY2 = WinGetPos($Form2)
                        If $XY2[0] <> $XY[0] Or $XY2[1] <> $XY[1] Then
                                WinMove($Form1, "", $XY2[0], $XY2[1])
                        EndIf
                        _Open_Close_Form($Form1, $Form2)
                Case $ButtonB2
                        $XY = WinGetPos($Form1)
                        $XY2 = WinGetPos($Form2)
                        If $XY2[0] <> $XY[0] Or $XY2[1] <> $XY[1] Then
                                WinMove($Form1, "", $XY2[0], $XY2[1])
                        EndIf
                        _Open_Close_Form($Form1, $Form2)
        EndSwitch
WEnd

Func _Open_Close_Form($OForm, $CForm)
        GUISwitch($OForm)
        GUISetState(@SW_SHOW)
        GUISwitch($CForm)
        GUISetState(@SW_HIDE)
EndFunc   ;==>_Open_Close_Form


[ 本帖最后由 顽固不化 于 2008-8-4 11:56 编辑 ]
发表于 2008-8-4 20:12:30 | 显示全部楼层

回复 7# 即即 的帖子

可以
做了个示例,希望对你有所启发
http://www.autoitx.com/forum.php ... &extra=page%3D1

[ 本帖最后由 pcbar 于 2008-8-4 22:48 编辑 ]
发表于 2010-12-12 13:26:52 | 显示全部楼层
我也想知道,希望高手说下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-2 20:29 , Processed in 0.073901 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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