我找到了在移动时使表单半透明的好代码。我有一个多项目解决方案,其中一个项目对所有其他项目都是通用的,并编译为所有项目都引用的 dll。每个项目中的少数表单都需要用于使表单半透明的代码,但并非所有表单都需要代码。
我对在何处以及如何将此代码用于某些表单有疑问。这是一个代码:
Imports System.ComponentModel
Public Class clsTransForm
Inherits System.Windows.Forms.Form
Private _OpacityResize As Double = 0.5
Private _OpacityMove As Double = 0.5
Private _OpacityOriginal As Double
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
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
ElseIf CLng(m.Msg) = WM_SIZE Then
If Me.Opacity <> _OpacityResize Then
_OpacityOriginal = Me.Opacity
Me.Opacity = _OpacityResize
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
... etc...
Public Property OpacityResize() As Double
... etc...
我尝试在我的公共项目下创建一个类 clsTransForm 但这为我创建了一个新表单。
如何配置此类仅用于某些表单?
放在哪里以及如何放置?