我怎样才能加载“未来”?在使用表单控件之前?详细解释:

发布于 2024-12-17 20:18:53 字数 578 浏览 3 评论 0原文

我正在将 vb6 程序迁移到 vb.net。理解这个问题需要的基础知识是,有两种形式需要相互通信,frmInput1和frmInput2。我有以下代码(在 frmInput1 后面),它检查 frmInput2 上的文本框是否具有特定值,似乎是在加载之前:

If frminput2.lblInputMac.Text <> "(no filename)" Then
        Dim calc As CalculationCaster = New CalculationCaster
        Call calc.FillMac()
        cmdNext.Enabled = False

        frminput2.FraInner.Enabled = True

当我运行它时,我在 If 行上收到以下错误:

"Object reference not set to an instance of an object."

我认为这意味着 frmInput2 中的对象尚未加载。在显示之前如何加载 frmInput2?

谢谢尼克

I am performing a migration on a vb6 program, to vb.net. The basic knowledge you need to understand this question is that there are two forms that need to talk to each other, frmInput1 and frmInput2. I have the following code (behind frmInput1) that checks if a textbox on frmInput2 has a certain value, seemingly before it has loaded:

If frminput2.lblInputMac.Text <> "(no filename)" Then
        Dim calc As CalculationCaster = New CalculationCaster
        Call calc.FillMac()
        cmdNext.Enabled = False

        frminput2.FraInner.Enabled = True

I get the following error on the If line when i run it:

"Object reference not set to an instance of an object."

Which i assume means that the object in frmInput2 has not been loaded yet. How can i load frmInput2 before i show it?

Thanks

Nick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对你而言 2024-12-24 20:18:53

frminput2 可能是类型 frminput2 的隐式全局实例。

如果您在 VB6 中定义名为 MyForm 的表单类型,平台会自动创建同名的隐式全局变量 MyForm。每当您在代码中引用此变量时,它都会自动为您加载表单的实例。

就好像你有这段代码一样。

Public Function MyForm() As MyForm
  Static f As MyForm
  If f Is Nothing Then
    f = New MyForm
  End If
  Return f
End Function

frminput2 is probably the implicit global instance of the type frminput2.

If you define a form type in VB6 called MyForm, the platform automatically creates an implicit global variable of the same name MyForm. Whenever you refer to this variable in code, it automatically loads an instance of the form for you.

It's rather as if you had this code.

Public Function MyForm() As MyForm
  Static f As MyForm
  If f Is Nothing Then
    f = New MyForm
  End If
  Return f
End Function
夜未央樱花落 2024-12-24 20:18:53
dim frm1 as new frmInput1 
dim frm2 as new frmInput2

此时,您应该能够在不显示表单的情况下在表单之间进行通信。您不应在未显式实例化表单的情况下引用表单。

dim frm1 as new frmInput1 
dim frm2 as new frmInput2

At this point, you should be able to communicate between forms without them being displayed. You should not reference forms without explicitly instantiating them.

木格 2024-12-24 20:18:53

创建表单的实例。

Dim f As New frmInput2

然后您可以使用窗体上的任何属性、方法或控件。

If f.lblInputMac.Text  <> "(no filename)" Then
    ...
End If

Create an instance of the form.

Dim f As New frmInput2

Then you can use any properties, methods, or controls on the form.

If f.lblInputMac.Text  <> "(no filename)" Then
    ...
End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文