如何在属性窗格中显示文本框样式条目

时间:2013-11-11 16:23:43

标签: vb.net visual-studio-2010

我第一次尝试编写自定义控件。基本上,我使用继承的面板创建一组“图标”,用户可以单击该图标以打开某些表单。该类包含一个图片框的实例和两个标签:

enter image description here

但是,我发现我需要能够在字符串描述中使用类似于“VbCrLF”的内容,这样在输入项目时,它会将文本附加到下一行,而不是让描述继续运行。我想要做的是在输入新的txtDescription或txtHeaderDescription时,允许我按回车键并让它为我插入回车符。标签原样这样做:

showing label using vbCRLF

我的问题是如何在VS中修改我的类以显示该类型的输入框,而不是典型的“行”条目?

我的课程是:

Public Class WorkspaceIconControl
Inherits Panel
Dim pbIcon As New PictureBox
Dim lblHeader As New Label, lblDescrip As New Label
Public Sub New()

    'MODIFY THE BACKCOLOR
    Me.BackColor = Color.SteelBlue
    Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch
    Me.Width = 250
    Me.Height = 100
    Me.BorderStyle = BorderStyle.FixedSingle

    'ADD PICTUREBOX
    pbIcon.BackColor = System.Drawing.Color.Transparent
    pbIcon.Image = My.Resources.addressIcon2
    pbIcon.Dock = DockStyle.None
    pbIcon.Width = 96
    pbIcon.Height = 96
    pbIcon.Top = 5
    pbIcon.SizeMode = PictureBoxSizeMode.StretchImage
    Me.Controls.Add(pbIcon)


    'ADD HEADER
    lblHeader.Font = New System.Drawing.Font("Calibri", 12.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    lblHeader.Name = "lblHeader"
    lblHeader.Text = "txtHeader"
    lblHeader.Top = 15
    lblHeader.Left = 95
    lblHeader.Width = 300
    lblHeader.ForeColor = Color.White
    Controls.Add(lblHeader)

    'ADD DESCRIP
    lblDescrip.Font = New System.Drawing.Font("Calibri", 7.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    lblDescrip.Name = "lblDescrip"
    lblDescrip.Text = "txtDescription"
    lblDescrip.Top = 35
    lblDescrip.Left = 95
    lblDescrip.Width = 300
    lblDescrip.ForeColor = Color.White
    Me.Controls.Add(lblDescrip)


End Sub

<Description("The image associated with the picturebox of this control"), _
Category("Appearance")> _
Public Property MyImage() As Image

    Get
        Dim image1 As Image
        image1 = pbIcon.Image
        Return image1
    End Get
    Set(ByVal imgValue As Image)
        pbIcon.Image = imgValue
    End Set
End Property

<Description("The width of picturebox associated with the control"), _
Category("Appearance")> _
Public Property PictureBoxWidth() As Double

    Get
        Dim width As Double
        width = pbIcon.Width
        Return width
    End Get
    Set(ByVal widthVal As Double)
        pbIcon.Width = widthVal
    End Set
End Property


<Description("The height of picturebox associated with the control"), _
Category("Appearance")> _
Public Property PictureBoxHeight() As Double

    Get
        Dim height As Double
        height = pbIcon.Height
        Return height
    End Get
    Set(ByVal height As Double)

        pbIcon.Height = height
    End Set
End Property



<Description("The label header visible property associated with the control"), _
Category("Appearance")> _
Public Property HeaderVisible() As Boolean

    Get
        Dim bHeader As Boolean
        bHeader = lblHeader.Visible
        Return bHeader

    End Get
    Set(ByVal bHeader As Boolean)
        lblHeader.Visible = bHeader
    End Set
End Property


<Description("The label description text property associated with the control"), _
Category("Appearance")> _
Public Property txtDescription() As String

    Get
        Dim strText As String
        strText = lblDescrip.Text
        Return strText
    End Get
    Set(ByVal strText As String)
        lblDescrip.Text = strText
    End Set
End Property

<Description("The label description header text property associated with the control"), _
Category("Appearance")> _
Public Property txtHeaderDescription() As String

    Get
        Dim strText As String
        strText = lblHeader.Text
        Return strText
    End Get
    Set(ByVal strText As String)
        lblHeader.Text = strText
    End Set
End Property

End Class

1 个答案:

答案 0 :(得分:1)

您可以查看Label控件的源代码,并通过向属性添加UI Editor属性来查看它是如何做到的:

<Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor))> _
Property Text As String