在将多项目解决方案重新创建为单个项目解决方案时,我遇到了巨大的麻烦,我的程序变得无法使用。
我保存了所有代码文件,问题在于在 IDE 中显示设计器以及与之相关的错误。
情况:
所有表单都使用名为 cls_transform 的类进行子类化,该类在移动时使表单透明。
Public Class cls_transform
Inherits System.Windows.Forms.Form
Private _OpacityMove As Double = 0.5
Private _OpacityOriginal As Double = 1
Private Const WM_NCLBUTTONDOWN As Long = &HA1
Private Const WM_NCLBUTTONUP As Long = &HA0
Private Const WM_MOVING As Long = &H216
Private Const WM_SIZE As Long = &H5
Private Sub cls_transform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Protected Overrides Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
Static LButtonDown As Boolean
If CLng(m.Msg) = WM_NCLBUTTONDOWN Then
LButtonDown = True
ElseIf CLng(m.Msg) = WM_NCLBUTTONUP Then
LButtonDown = False
End If
If LButtonDown Then
If CLng(m.Msg) = WM_MOVING Then
If Me.Opacity <> _OpacityMove Then
_OpacityOriginal = Me.Opacity
Me.Opacity = _OpacityMove
End If
End If
ElseIf Not LButtonDown Then
If Me.Opacity <> _OpacityOriginal Then Me.Opacity = _OpacityOriginal
End If
MyBase.DefWndProc(m)
End Sub
Public Property OpacityMove() As Double
Get
Return _OpacityMove
End Get
Set(ByVal Value As Double)
_OpacityMove = Value
End Set
End Property
Private Sub InitializeComponent()
Me.SuspendLayout()
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Name = "cls_transform"
Me.ResumeLayout(False)
End Sub
End Class
这是一个空表单“frm_myForm”的代码的样子:
Public Class frm_myForm
Inherits cls_transform
Private Sub frm_myForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
这是该形式的设计器代码:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frm_myForm
Inherits cls_transform
'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.SuspendLayout()
'
'frm_myForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Name = "frm_myForm"
Me.Text = "frm_myForm"
Me.ResumeLayout(False)
End Sub
End Class
当我尝试从 IDE 中“查看设计器”而不是查看表单时,出现白屏错误:
无法为此文件显示设计器,因为无法设计其中的任何类。设计者检查了文件中的以下类: frm_myForm --- 无法加载基类“noviprog.cls_transform”。确保已引用程序集并且已构建所有项目。
从 cls_transform 继承的所有表单都会发生这种情况。
当 cls_transform 位于单独的库(相同解决方案的单独项目)中时,该库被引用到有效的实际项目中。
当代码文件和该类在同一个项目中时,是否有可能让它工作?如何让它工作?