在代码编辑器中修改了Forms.UserControl的designer.vb,现在在Visual Studio 2017中不可见设计视图

时间:2019-01-01 18:46:03

标签: vb.net visual-studio

如何恢复我的设计师视图。我通过实现事件处理程序错误地编辑了自动生成的设计器类。下次我打开Vistual Studio项目时,缺少设计视图。我找不到找到返回“设计”视图的方法。

这是我的Control_IncidentWatcher.Designer.vb文件

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Controls_IncidentWatcher
    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()
...
...
...
    Private Sub c_playsample_Click(sender As Object, e As EventArgs) Handles c_playsample.Click
        SoundAndAlerts.SetVolume(c_Volume.SelectedItem.ToString())

        SoundAndAlerts.PlayAlert(c_Loops.SelectedItem.ToString(), c_CustomSound.Text)
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            c_CustomSound.Text = OpenFileDialog1.FileName
        End If
    End Sub

End Class

Control_IncidentWatcher

如您所见,设计器,vb和resx已解除关联。

更新:

我添加了另一个用户控件test_usercontrol.vb,并尝试模仿Control_IncidentWatcher中的所有配置 在打开项目时,我的Control_IncidentWatcher在大约2秒钟内从UserControl更改为普通的VB文件。我能够捕捉到变化 Change in appearance

我的project.vb文件也更改了

<Compile Include="test_usercontrol.Designer.vb">
  <DependentUpon>test_usercontrol.vb</DependentUpon>
</Compile>
<Compile Include="test_usercontrol.vb">
  <SubType>UserControl</SubType>
</Compile>

<Compile Include="Control_IncidentWatcher.Designer.vb">
  <DependentUpon>Control_IncidentWatcher.vb</DependentUpon>
</Compile>
<Compile Include="Control_IncidentWatcher.vb" />

打开项目时,将从Control_IncidentWatcher中删除SubType属性。

2 个答案:

答案 0 :(得分:1)

根据互联网,有一个手动修复程序。

您在XML编辑器中打开项目文件,并将以下元素添加到  受影响的部分...

例如受影响的部分:

form1.vb

form1.designer.vb

form1.resx

<EmbeddedResource Include="Forms\form1.designer.vb">
<DependentUpon>form1.vb</DependentUpon>
</EmbeddedResource>

<EmbeddedResource Include="Forms\form1.resx">
<DependentUpon>form1.vb</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>

答案 1 :(得分:1)

这真令人尴尬,Control_IncidentWatcher.Designer.vb内部的类定义与Control_IncidentWatcher.vb不同 我必须重新创建此定义才能解决问题。

Partial Class Controls_IncidentWatcher
    Inherits System.Windows.Forms.UserControl

其中UserControl表单中的类定义是

Public Class Control_IncidentWatcher
End Class

类名不匹配。我还使类的名称和文件一致。在将Subtype重新添加到project.vb文件中之后,终于可以解决此问题