【问题标题】:Cannot open designer of a form无法打开表单设计器
【发布时间】:2020-03-24 10:22:26
【问题描述】:

我目前正在使用 MS VS 2017 进行一个项目。

我之前能够打开设计器并打开表单。现在,我正在尝试打开同一个文件,但无法打开所有表单的设计器。但项目运行顺利,我可以编辑代码。

我尝试了其他人的建议,例如清理和构建解决方案,以及删除 obj 子文件夹,但是这些都不适合我。我该怎么办?

这是我每次尝试打开设计器时得到的:

The designer could not be shown for this file because none of the classes within it can be designed. 

at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at
Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) 

这是我要打开的表单的代码:

Public Class frmLogin

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        Application.Exit()
    End Sub

    Private Sub lblExit_Click_1(sender As Object, e As EventArgs) Handles lblExit.Click
        If (MessageBox.Show("Are you sure to Exit?", "Exit from the system", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) = DialogResult.Yes Then
            Application.Exit()
        End If
    End Sub

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        frmDashboard.Show()
        Me.Hide()
    End Sub

End Class

【问题讨论】:

标签: vb.net visual-studio-2017 designer


【解决方案1】:

您需要查看的文件是您项目目录中的frmLogin.Designer.vb。您可以通过右键单击(在 Visual Studio 中)来查看它,例如您在上面发布的代码中的“btnLogin”,然后是“Go To Implementation”。或者只是使用文件资源管理器并使用记事本打开文件以查看内部。

这是存储表单设计的地方。该文件包含为您的表单自动生成的代码和数据,并且似乎以某种方式损坏,可能是被意外编辑了。

我不知道 frmLogin 实际上是什么样子,但这是我刚刚使用代码中的名称创建的 frmLogin.Designer.vb;

我建议您将文件的内容与下面的示例进行比较,这应该会导致问题的根源:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class frmLogin
Inherits System.Windows.Forms.Form

'Form 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.btnCancel = New System.Windows.Forms.Button()
    Me.btnLogin = New System.Windows.Forms.Button()
    Me.lblExit = New System.Windows.Forms.Label()
    Me.SuspendLayout()
    '
    'btnCancel
    '
    Me.btnCancel.Location = New System.Drawing.Point(310, 130)
    Me.btnCancel.Name = "btnCancel"
    Me.btnCancel.Size = New System.Drawing.Size(107, 43)
    Me.btnCancel.TabIndex = 0
    Me.btnCancel.Text = "Cancel"
    Me.btnCancel.UseVisualStyleBackColor = True
    '
    'btnLogin
    '
    Me.btnLogin.Location = New System.Drawing.Point(310, 192)
    Me.btnLogin.Name = "btnLogin"
    Me.btnLogin.Size = New System.Drawing.Size(107, 48)
    Me.btnLogin.TabIndex = 1
    Me.btnLogin.Text = "Log in"
    Me.btnLogin.UseVisualStyleBackColor = True
    '
    'lblExit
    '
    Me.lblExit.AutoSize = True
    Me.lblExit.Location = New System.Drawing.Point(233, 130)
    Me.lblExit.Name = "lblExit"
    Me.lblExit.Size = New System.Drawing.Size(24, 13)
    Me.lblExit.TabIndex = 2
    Me.lblExit.Text = "Exit"
    '
    'frmLogin
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(800, 450)
    Me.Controls.Add(Me.lblExit)
    Me.Controls.Add(Me.btnLogin)
    Me.Controls.Add(Me.btnCancel)
    Me.Name = "frmLogin"
    Me.Text = "frmLogin"
    Me.ResumeLayout(False)
    Me.PerformLayout()

End Sub

Friend WithEvents btnCancel As Button
Friend WithEvents btnLogin As Button
Friend WithEvents lblExit As Label
End Class

祝你好运!

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,项目将构建和运行,但 Windows 窗体设计器拒绝显示任何窗体或控件。

    我不得不删除 ProjectAssemblies 目录并重新打开项目,然后它工作正常。 %LOCALAPPDATA%\Microsoft\VisualStudio*16.0_72ecbfa4*\ProjectAssemblies

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      相关资源
      最近更新 更多