【问题标题】:How to transform this into a DLL如何将其转换为 DLL
【发布时间】:2013-01-11 03:15:01
【问题描述】:

我想编译一个 DLL 控件,是一个扩展面板但我只有类,我不喜欢使用类来添加自定义控件,我更喜欢将 DLL 添加到工具箱中。

谁能帮我把它转成类库DLL控件?

PS:另外,也许我也需要一个指导步骤来制作类库,这是我第一次尝试。

谢谢。

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Text
Imports System.Windows.Forms

Namespace GradientPanel
    Public Partial Class GradientPanel
        Inherits System.Windows.Forms.Panel

        ' member variables
        Private mStartColor As System.Drawing.Color
        Private mEndColor As System.Drawing.Color

        Public Sub New()
            ' InitializeComponent()
            PaintGradient()
        End Sub

        Protected Overrides Sub OnPaint(pe As PaintEventArgs)
            ' TODO: Add custom paint code here

            ' Calling the base class OnPaint
            MyBase.OnPaint(pe)
        End Sub


        Public Property PageStartColor() As System.Drawing.Color
            Get
                Return mStartColor
            End Get
            Set
                mStartColor = value
                PaintGradient()
            End Set
        End Property


        Public Property PageEndColor() As System.Drawing.Color
            Get
                Return mEndColor
            End Get
            Set
                mEndColor = value
                PaintGradient()
            End Set
        End Property


        Private Sub PaintGradient()
            Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush
            gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), PageStartColor, PageEndColor)

            Dim bmp As New Bitmap(Me.Width, Me.Height)

            Dim g As Graphics = Graphics.FromImage(bmp)
            g.FillRectangle(gradBrush, New Rectangle(0, 0, Me.Width, Me.Height))
            Me.BackgroundImage = bmp
            Me.BackgroundImageLayout = ImageLayout.Stretch
        End Sub

    End Class
End Namespace

【问题讨论】:

标签: vb.net visual-studio dll user-controls class-library


【解决方案1】:

我一直只是使用 CustomControlLibrary 为其命名并将程序集名称和默认命名空间设置为您希望 dll 成为的名称,然后您将右键单击项目并选择添加类,然后您将添加您的自定义控件的类代码到项目。那时您还可以添加一个新的 UserControl。当您编译它时,它将创建一个 dll,您可以通过右键单击工具箱选择选择项目然后浏览到您创建的 Dll 来浏览它。然后它将包含在您的控件库中的控件添加到您的工具箱中。

【讨论】:

  • 感谢您的评论,问题是我很愚蠢,我试图在“类库”项目中做到这一点,但我需要在“Windows 窗体控件库”项目中做到这一点大声笑,现在一切都很好,再次感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-27
相关资源
最近更新 更多