表单的新实例 [英] New instance of a form

查看:103
本文介绍了表单的新实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是当我每次以新的形式调用此子对象时,都会创建该子对象
但是我想如果打开frmcompanylist然后将焦点设置在它上,如果
没有打开,然后打开一个新的instencse
而且每次我想
设置frmcompanylist =无

验证码:

problem is when i call this sub its create every time a new new instencse of form
but i want if frmcompanylist is opend then set focus to it and if
not opend then open a new instencse
and also every time i want to
set frmcompanylist =nothing

exp code:

private frmcompanylist as companylistform   
Public Sub Show(ByVal FormName As String)
    Select Case FormName
         Case 
            If frmcompanylist Is Nothing Then
                Set frmcompanylist = New CompanyListForm
            End If
            frmcompanylist.Show 1
            Set frmcompanylist = Nothing
   end select
end sub

推荐答案

很难从一个小的代码片段中分辨出来,但是我认为这可能是因为frmcompanylist是一个实例变量-它是针对您所使用的方法的类的每个版本新鲜创建的.尝试使其共享,并且您应该排序:
It''s difficult to tell from that small code fragment, but I think it is probably because frmcompanylist is an instance variable - it is created fresh for each version of the class you method is in. Try making it shared, and you should be sorted:
Private Shared frmcompanylist As companylistform = Nothing


这篇关于表单的新实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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