0

我找到了在移动时使表单半透明的好代码。我有一个多项目解决方案,其中一个项目对所有其他项目都是通用的,并编译为所有项目都引用的 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 但这为我创建了一个新表单。

如何配置此类仅用于某些表单?
放在哪里以及如何放置?

4

1 回答 1

1

我建议clsTransForm通过将其标记为MustInherit. 然后,在您的其他形式中,继承 fromclsTransForm而不是System.Windows.Forms.Form. 每个继承自的表单clsTransform都会有透明效果。

至于将文件本身放在哪里:没关系。只是不要忘记将项目引用添加到包含clsTransForm在每个需要使用它的项目中的项目。

于 2013-08-19T20:20:39.727 回答