除了a以外,其他窗口打开下级窗口时会将自己隐藏,就是说到e窗口被打开时,屏幕上只显示a和e两个窗口。
现在要在e窗口中按下按钮,关闭除了a以外的所有窗口(b-d都是隐藏的)。
怎么个思路呢?谢谢!
10 个解决方案
#1
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class
Public Class Form2
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form3.Show()
Me.Hide()
End Sub
End Class
Public Class Form3
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form4.Show()
Me.Hide()
End Sub
End Class
Public Class Form4
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form5.Show()
Me.Hide()
End Sub
Private Sub Form4_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
MsgBox("CLOSED") ' 加入这个MsgBox可以看到Form4确实关闭了
End Sub
End Class
Public Class Form5
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Close()
Form3.Close()
Form4.Close()
End Sub
End Class
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class
Public Class Form2
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form3.Show()
Me.Hide()
End Sub
End Class
Public Class Form3
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form4.Show()
Me.Hide()
End Sub
End Class
Public Class Form4
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form5.Show()
Me.Hide()
End Sub
Private Sub Form4_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
MsgBox("CLOSED") ' 加入这个MsgBox可以看到Form4确实关闭了
End Sub
End Class
Public Class Form5
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Close()
Form3.Close()
Form4.Close()
End Sub
End Class
#2
我用的是2005。呵呵,其实很容易。
#3
这样写我是明白的,但是问题在于实际程序中多级窗口很复杂:
a1-b1-c1-d1
a1-b2-c1-d1
a1-b2-c2-d2
...
...
其实我要解决的是在每级的任意一个窗口,如果判断其上级的所有窗口,并进行关闭的一个思路。
类似
Form2.Close()
Form3.Close()
Form4.Close()
这样的写法,貌似很烦琐的说
a1-b1-c1-d1
a1-b2-c1-d1
a1-b2-c2-d2
...
...
其实我要解决的是在每级的任意一个窗口,如果判断其上级的所有窗口,并进行关闭的一个思路。
类似
Form2.Close()
Form3.Close()
Form4.Close()
这样的写法,貌似很烦琐的说
#4
可以这样
通过循环判断窗体的owner的Handler 是否等于 Process.Current.MainWindowHandler确定是否为主窗体.
通过循环判断窗体的owner的Handler 是否等于 Process.Current.MainWindowHandler确定是否为主窗体.
#5
这里涉及到一个问题:父窗口都是隐藏的,就是说内存中都有这些父窗体的实例存在。
如何得到这些实例呢?
能不能给个例子,谢谢。
如何得到这些实例呢?
能不能给个例子,谢谢。
#6
那就在启动窗体时只允许一个实例存在。在每个窗体中添加如下属性,比如你有个窗体名为frmChaZhang。则在它的窗体类代码中加入:
private shared m_frmChaZhang as frmChaZhang
Public Shared Property DefInstance() As frmChaZhang
Get
If m_frmChaZhang Is Nothing OrElse m_frmChaZhang.IsDisposed Then
m_frmChaZhang = New frmChaZhang
End If
Return m_frmChaZhang
End Get
Set(ByVal value As frmChaZhang)
m_frmChaZhang = value
End Set
End Property
如果在form2的某个事件中启动它就用代码:frmchazhang.definstance.show
关闭的话就用:frmchazhang.definstance.close
-----------------------
CSDN 论坛助手
http://china-csdn.cn
private shared m_frmChaZhang as frmChaZhang
Public Shared Property DefInstance() As frmChaZhang
Get
If m_frmChaZhang Is Nothing OrElse m_frmChaZhang.IsDisposed Then
m_frmChaZhang = New frmChaZhang
End If
Return m_frmChaZhang
End Get
Set(ByVal value As frmChaZhang)
m_frmChaZhang = value
End Set
End Property
如果在form2的某个事件中启动它就用代码:frmchazhang.definstance.show
关闭的话就用:frmchazhang.definstance.close
-----------------------
CSDN 论坛助手
http://china-csdn.cn
#7
用一些变量来存储上一级窗体名好不好,比如,a级窗体把名字传递到b级窗体,b级窗体把上一级传下来的a级窗体名和本身窗体名传给c级窗体,……,一级一级传下去,到e级就会有a、b、c、d各级父窗体的名字,然后b、c、d各级窗体关闭。菜鸟之见,上面见笑了。呵呵
#8
已经搞定,用的方法是:
父窗口打开子窗口的时候,将自己传递给子窗口,子窗口在load事件中通过me.owner.close将父窗口关闭。
测试有效,哈哈!
父窗口打开子窗口的时候,将自己传递给子窗口,子窗口在load事件中通过me.owner.close将父窗口关闭。
测试有效,哈哈!
#9
貌似上面的方法有问题~~~~
me.owner.close()关闭主窗体时并不触发主窗体的form_closing事件,why?
或者说根本就没有关闭掉。
但是语句运行时又没有报错,怎么回事啊?
救急一下,谢谢!
me.owner.close()关闭主窗体时并不触发主窗体的form_closing事件,why?
或者说根本就没有关闭掉。
但是语句运行时又没有报错,怎么回事啊?
救急一下,谢谢!
#10
b显示c时
dim c as new from1
c.owner=me
c.cshow
c显示d时,
dim d as new form2
d.owne=me
d.show
......
在再在b~e的closing事件中调用me.owner.close
a显示b时不要指定b的onwer,这样就不会关掉主窗体
dim c as new from1
c.owner=me
c.cshow
c显示d时,
dim d as new form2
d.owne=me
d.show
......
在再在b~e的closing事件中调用me.owner.close
a显示b时不要指定b的onwer,这样就不会关掉主窗体
#1
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class
Public Class Form2
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form3.Show()
Me.Hide()
End Sub
End Class
Public Class Form3
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form4.Show()
Me.Hide()
End Sub
End Class
Public Class Form4
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form5.Show()
Me.Hide()
End Sub
Private Sub Form4_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
MsgBox("CLOSED") ' 加入这个MsgBox可以看到Form4确实关闭了
End Sub
End Class
Public Class Form5
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Close()
Form3.Close()
Form4.Close()
End Sub
End Class
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class
Public Class Form2
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form3.Show()
Me.Hide()
End Sub
End Class
Public Class Form3
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form4.Show()
Me.Hide()
End Sub
End Class
Public Class Form4
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form5.Show()
Me.Hide()
End Sub
Private Sub Form4_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
MsgBox("CLOSED") ' 加入这个MsgBox可以看到Form4确实关闭了
End Sub
End Class
Public Class Form5
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Close()
Form3.Close()
Form4.Close()
End Sub
End Class
#2
我用的是2005。呵呵,其实很容易。
#3
这样写我是明白的,但是问题在于实际程序中多级窗口很复杂:
a1-b1-c1-d1
a1-b2-c1-d1
a1-b2-c2-d2
...
...
其实我要解决的是在每级的任意一个窗口,如果判断其上级的所有窗口,并进行关闭的一个思路。
类似
Form2.Close()
Form3.Close()
Form4.Close()
这样的写法,貌似很烦琐的说
a1-b1-c1-d1
a1-b2-c1-d1
a1-b2-c2-d2
...
...
其实我要解决的是在每级的任意一个窗口,如果判断其上级的所有窗口,并进行关闭的一个思路。
类似
Form2.Close()
Form3.Close()
Form4.Close()
这样的写法,貌似很烦琐的说
#4
可以这样
通过循环判断窗体的owner的Handler 是否等于 Process.Current.MainWindowHandler确定是否为主窗体.
通过循环判断窗体的owner的Handler 是否等于 Process.Current.MainWindowHandler确定是否为主窗体.
#5
这里涉及到一个问题:父窗口都是隐藏的,就是说内存中都有这些父窗体的实例存在。
如何得到这些实例呢?
能不能给个例子,谢谢。
如何得到这些实例呢?
能不能给个例子,谢谢。
#6
那就在启动窗体时只允许一个实例存在。在每个窗体中添加如下属性,比如你有个窗体名为frmChaZhang。则在它的窗体类代码中加入:
private shared m_frmChaZhang as frmChaZhang
Public Shared Property DefInstance() As frmChaZhang
Get
If m_frmChaZhang Is Nothing OrElse m_frmChaZhang.IsDisposed Then
m_frmChaZhang = New frmChaZhang
End If
Return m_frmChaZhang
End Get
Set(ByVal value As frmChaZhang)
m_frmChaZhang = value
End Set
End Property
如果在form2的某个事件中启动它就用代码:frmchazhang.definstance.show
关闭的话就用:frmchazhang.definstance.close
-----------------------
CSDN 论坛助手
http://china-csdn.cn
private shared m_frmChaZhang as frmChaZhang
Public Shared Property DefInstance() As frmChaZhang
Get
If m_frmChaZhang Is Nothing OrElse m_frmChaZhang.IsDisposed Then
m_frmChaZhang = New frmChaZhang
End If
Return m_frmChaZhang
End Get
Set(ByVal value As frmChaZhang)
m_frmChaZhang = value
End Set
End Property
如果在form2的某个事件中启动它就用代码:frmchazhang.definstance.show
关闭的话就用:frmchazhang.definstance.close
-----------------------
CSDN 论坛助手
http://china-csdn.cn
#7
用一些变量来存储上一级窗体名好不好,比如,a级窗体把名字传递到b级窗体,b级窗体把上一级传下来的a级窗体名和本身窗体名传给c级窗体,……,一级一级传下去,到e级就会有a、b、c、d各级父窗体的名字,然后b、c、d各级窗体关闭。菜鸟之见,上面见笑了。呵呵
#8
已经搞定,用的方法是:
父窗口打开子窗口的时候,将自己传递给子窗口,子窗口在load事件中通过me.owner.close将父窗口关闭。
测试有效,哈哈!
父窗口打开子窗口的时候,将自己传递给子窗口,子窗口在load事件中通过me.owner.close将父窗口关闭。
测试有效,哈哈!
#9
貌似上面的方法有问题~~~~
me.owner.close()关闭主窗体时并不触发主窗体的form_closing事件,why?
或者说根本就没有关闭掉。
但是语句运行时又没有报错,怎么回事啊?
救急一下,谢谢!
me.owner.close()关闭主窗体时并不触发主窗体的form_closing事件,why?
或者说根本就没有关闭掉。
但是语句运行时又没有报错,怎么回事啊?
救急一下,谢谢!
#10
b显示c时
dim c as new from1
c.owner=me
c.cshow
c显示d时,
dim d as new form2
d.owne=me
d.show
......
在再在b~e的closing事件中调用me.owner.close
a显示b时不要指定b的onwer,这样就不会关掉主窗体
dim c as new from1
c.owner=me
c.cshow
c显示d时,
dim d as new form2
d.owne=me
d.show
......
在再在b~e的closing事件中调用me.owner.close
a显示b时不要指定b的onwer,这样就不会关掉主窗体