无法打开表单设计器

问题描述 投票:0回答:1

我目前正在使用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) 

enter image description here

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

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个回答
0
投票

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

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

我不知道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

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.