2017-02-19 60 views
-1

我有一个名为“Grid”的用户控件。在我的表单中,设计师的一行代码(用于网格)遇到了一些问题,每隔一段时间就会消失。不过,我只是从一个较旧的备份复制并粘贴它,并且它工作正常,所以它不是特别困扰我,我有更重要的事情要做,我离开它。我刚才试图把网格到窗体从工具箱中,我得到这个错误:未能创建用户控件,未找到构造函数

enter image description here

谁能帮助我吗?如果我错过了任何东西或者您需要更多信息,我应该尽快回复。

编辑:刚才我摆弄了一下周围,这是共同的我所有的用户问题控制

干杯 - 马丁

编辑:以为它可能是有用的,包括电网设计。

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ 
Partial Class Grid 
Inherits System.Windows.Forms.UserControl 

'UserControl overrides dispose to clean up the component list. 
<System.Diagnostics.DebuggerNonUserCode()> _ 
Protected Overrides Sub Dispose(ByVal disposing As Boolean) 
    Try 
     If disposing AndAlso components IsNot Nothing Then 
      components.Dispose() 
     End If 
    Finally 
     MyBase.Dispose(disposing) 
    End Try 
End Sub 

'Required by the Windows Form Designer 
Private components As System.ComponentModel.IContainer 

'NOTE: The following procedure is required by the Windows Form Designer 
'It can be modified using the Windows Form Designer. 
'Do not modify it using the code editor. 
<System.Diagnostics.DebuggerStepThrough()> _ 
Private Sub InitializeComponent() 
    Me.SuspendLayout() 
    ' 
    'Grid 
    ' 
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) 
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font 
    Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch 
    Me.Name = "Grid" 
    Me.Size = New System.Drawing.Size(450, 450) 
    Me.ResumeLayout(False) 

End Sub 

End Class 
+0

请记住,以纪念我的答案,因为接受_if它解决您的problem_。通过按下帖子左侧的勾号/复选标记来接受答案。 –

回答

0

当您为控件编写自己的构造函数时,会发生这种情况。设计者只能创建一个控件的实例,如果它有一个无参数的构造函数。所以,如果你已经添加了一个带参数的自定义构造函数,那么设计者将无法识别这个参数。

要解决它,只需在您控制的任意位置添加一个构造函数不带参数,你应该是好去:

Public Sub New() 
    InitializeComponent() 
    'Do other stuff here if necessary. 
End Sub