如何在vb.net中的MDI表单上设置子表单 [英] How to set child form over mdi form in vb.net

查看:143
本文介绍了如何在vb.net中的MDI表单上设置子表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在vb.net中有一个MDI表单和3个子表单. Mdi表单对它具有图片框控制的确切作用是.如果我从mdi表单调用子表单,则MDI表单的图片框会与子表单重叠,这意味着它将子表单隐藏在MDI表单的图片框后面.然后,我在按钮上单击了mdi表单,即对图片框调用sendtoback(),在子表单卸载时对图片框调用了brintToFront().但是在子窗体卸载时,它给出了错误.实际代码如下:

Mdi表单按钮单击代码

Hi,
I have a MDI form and 3 child form in vb.net. What exactly done that the Mdi form have a picture box control over it. If I call a child form from mdi form then picture box of MDI form overlap the child form mean it hides the child form behind the picture box of MDI form. Then what I did that in the button click of mdi form I called sendtoback() for picture box and on child form unload I called brintToFront() for picture box. But at the time of child form unload it is giving error. Actual Code given below:

Mdi form button click code

 Dim fm As employeeimage
fm  = New employeeimage
        fm.MdiParent = Me
        fm .Show()
        Me.PictureBox1.SendToBack()


子表单卸载代码


child form unload code

Dim s
s = MessageBox.Show("Do you want to close that", "SMS", MessageBoxButtons.YesNo)
If (s = vbYes) Then
Dim ss As Mainform
ss.PictureBox1.BringToFront()
End If


在此先感谢


Thanks in advance

推荐答案

它将.因为你说过:
It will. Because you have said:
Dim ss As Mainform
ss.PictureBox1.BringToFront()

所以ss为空-它不包含任何内容.因此,当您尝试使用它时,它会报告一个空引用错误.
相反,您需要通过之前设置的MdiParent属性引用MainForm:

So ss is empty - it contains nothing. So when you try to use it, it reports a null reference error.
Instead, you need to either refer to the MainForm via the MdiParent property you set earlier:

Dim ss As Mainform = Me.MdiParent
ss.PictureBox1.BringToFront()

或(最好)在主窗体中处理子窗体的FormClosing事件,并在那里执行BringToFront方法.这样更好,因为这意味着子窗体不需要了解主要窗体在做什么.

Or (preferably) handle the FormClosing event of the child form in the main form and do the BringToFront method there. This way is better, because it means that the child form needs to know less about what the main form is doing.


这篇关于如何在vb.net中的MDI表单上设置子表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆