在构造期间,表单从默认实例引用自身,这导致无限递归。 [英] The form referred to itself during construction from a default instance which led to infinite recursion.

查看:175
本文介绍了在构造期间,表单从默认实例引用自身,这导致无限递归。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Folks,

Hello Folks,

我正在使用Vb.net 2015,我有两种形式,即frmLogin和frmMain。通过带有子过程的frmLogin上的按钮(带有单击事件),我引用了frmMain上的所有控件。例如frmMain.txtUsername。

I'm using Vb.net 2015 and I have two forms, namely frmLogin and frmMain. Through a button (with a click event) on the frmLogin with a sub procedure I make reference to all the controls on frmMain. e.g. frmMain.txtUsername.

现在,问题是当我运行frmLogin表单并单击登录按钮时,调用子过程(procLogin)并立即到达frmMain行。 txtUserName.Text然后是错误"在构造期间引用自身的形式
来自默认实例导致无限递归。在Form的构造函数中,参考from使用'Me。'出现。

Now, the problem is the moment I run the frmLogin form and click on the login button, the sub procedure (procLogin) is called and immediately it reaches the line frmMain.txtUserName.Text then the error "The form referred to itself during construction from a default instance which led to infinite recursion. Within the Form's constructor refer to the from using 'Me.' appears.

我已经检查了每个地方,但知道有用。我真的不知道这个错误来自哪里。请帮帮我。

I have checked every where but to know avail. I do not really know where this error is coming from. Please help me out.

谢谢

推荐答案

< Benenit,

Benniit,

您的问题可能是因为尽管所有真正的.Net VB开发人员都提出抗议,但微软希望取悦那些告诉不应该有任何人的VB6程序员版本VB8的进展并保留在VB6中与
相同的所有内容。

Your problem is probably caused because of the fact that despite of all protest from all real .Net VB developers Microsoft wanted to please the VB6 programmers who told there should not be any progress in version VB8 and stayed in everything the same as in VB6.

VB得到了一个默认的表单实例(并且只有表单才能在其他地方使用)。真正的.Net程序员可以避免这种情况。 

VB got a default form instance (and only for forms it is nowhere else). Real .Net programmers avoid it as hell. 

不要通过名称调用您的表单,而是实例并传递主表单参考。 

Don't call your form by name but instance it and pass the main form reference. 

(有更好的方法,然后我使用构造函数显示,但这使得理解起来更复杂)

(There are better ways then I show here using the constructor, but that makes it more complicated to understand)

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim login As New Form2
        login.Mainform = Me
        login.Show()
    End Sub
End Class
Public Class Form2
    Friend Mainform As Form1
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
        Mainform.TextBox1.Text = "Whatever"
        Me.Close()
    End Sub
End Class







这篇关于在构造期间,表单从默认实例引用自身,这导致无限递归。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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