WinForms(Mdi容器)中的前进,后退,向上导航? [英] Forward,Back,Up Navigation in WinForms(Mdi Container)?
本文介绍了WinForms(Mdi容器)中的前进,后退,向上导航?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想像Windows资源管理器的行为一样导航,
假设有1个Mdi和10个子窗体,
所以我想从一种形式向前,向后,向上导航..
让我知道是否有人有主意.
在此先感谢..
问候,
Pawan.
Hi
I want to navigate like how the windows explorer behaves,
Assume There is 1 Mdi and 10 Child Forms,
So i want to navigate forward,back,up from one form to other..
Let me know if anybody have an idea..
Thanks in Advance..
Regards,
Pawan.
推荐答案
C#中的答案
创建一个项目,添加一个MDI表单并创建两个名为cmdBack和cmdForward的按钮.
The answer in C#
Create a project, add an MDI form and create two buttons named cmdBack and cmdForward.
private void cmdBack_Click(object sender, EventArgs e)
{
try
{
Form PrevForm = null;
foreach (Form ChildForm in this.MdiChildren)
{
if (ChildForm.Equals(this.ActiveMdiChild))
{
if ((PrevForm != null))
{
this.ActivateMdiChild(PrevForm);
PrevForm.Focus();
break;
}
}
PrevForm = ChildForm;
}
PrevForm = null;
}
catch (Exception ex)
{
}
}
private void cmdForward_Click(object sender, EventArgs e)
{
try
{
Form NextForm = null;
foreach (Form ChildForm in this.MdiChildren.Reverse())
{
if (ChildForm.Equals(this.ActiveMdiChild))
{
if ((NextForm != null))
{
this.ActivateMdiChild(NextForm);
NextForm.Focus();
break;
}
}
NextForm = ChildForm;
}
NextForm = null;
}
catch (Exception ex)
{
}
}
当我发现您的问题时遇到了同样的问题,因此我放弃了搜索.我编写的代码为我解决了这个问题.
在您的项目中,创建两个名为cmdBack和cmdForward的按钮,然后尝试以下操作:
I had the same problem when I found your question, so I gave up searching. The code I wrote resolved the problem for me.
In your project, create two buttons named cmdBack and cmdForward and try the following:
Private Sub cmdBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdBack.Click
Try
Dim PrevForm As Form = Nothing
For Each ChildForm As Form In Me.MdiChildren
If ChildForm.Equals(Me.ActiveMdiChild) Then
If Not IsNothing(PrevForm) Then
Me.ActivateMdiChild(PrevForm)
PrevForm.Focus()
Exit For
End If
End If
PrevForm = ChildForm
Next
PrevForm = Nothing
Catch ex As Exception
End Try
End Sub
Private Sub cmdForward_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdForward.Click
Try
Dim NextForm As Form = Nothing
For Each ChildForm As Form In Me.MdiChildren.Reverse
If ChildForm.Equals(Me.ActiveMdiChild) Then
If Not IsNothing(NextForm) Then
Me.ActivateMdiChild(NextForm)
NextForm.Focus()
Exit For
End If
End If
NextForm = ChildForm
Next
NextForm = Nothing
Catch ex As Exception
End Try
End Sub
这篇关于WinForms(Mdi容器)中的前进,后退,向上导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文