Creating a User Control for Multi-Line Text Entry in a Text Box

Mansour_Dalir 2,036 Reputation points
2024-11-12T12:23:45.8033333+00:00

How can a user control be created to incorporate a multi-line text entry feature for a text box?

At the moment of design, you need to enter multi-line text

User's image

Public Property _Text As String
    Get
        Return txtNorTarget.Text
    End Get
    Set(value As String)
        txtNorTarget.Text = value
    End Set
End Property
Developer technologies | VB
Developer technologies | Visual Studio | Other
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2024-11-13T02:04:21.6766667+00:00

    Hi @Mansour_Dalir ,

    Adding Browsable and Editor attributes to the property.

    <System.ComponentModel.Browsable(True)>
    <System.ComponentModel.Editor(GetType(System.ComponentModel.Design.MultilineStringEditor), GetType(System.Drawing.Design.UITypeEditor))>
    Public Property _Text As String
        Get
            Return txtNorTarget.Text
        End Get
        Set(value As String)
            txtNorTarget.Text = value
        End Set
    End Property
    
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2024-11-12T12:23:45.8066667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To create a user control that incorporates a multi-line text entry feature for a text box in a Windows Forms application, you can follow these steps:

    1. Create a User Control: Start by creating a new User Control in your project.
    2. Add a TextBox Control: Drag a TextBox control onto your User Control. Set the Multiline property of the TextBox to true to allow multiple lines of text.
    3. Set Additional Properties: You may also want to set the WordWrap property to true and add scroll bars if necessary. This can enhance the usability of the multi-line text box.
    4. Expose Properties: Create properties in your User Control to expose the TextBox's text and other relevant properties. For example, you can create a property named _Text that gets and sets the text of the TextBox.

    Here’s a sample implementation in VB.NET:

    Public Class MultiLineTextBoxControl
        Inherits UserControl
    
        Private txtMultiLine As New TextBox()
    
        Public Sub New()
            ' Initialize the TextBox
            txtMultiLine.Multiline = True
            txtMultiLine.WordWrap = True
            txtMultiLine.ScrollBars = ScrollBars.Vertical
            Me.Controls.Add(txtMultiLine)
        End Sub
    
        Public Property _Text As String
            Get
                Return txtMultiLine.Text
            End Get
            Set(value As String)
                txtMultiLine.Text = value
            End Set
        End Property
    End Class
    

    In this example, the MultiLineTextBoxControl class inherits from UserControl, initializes a multi-line TextBox, and provides a property _Text to interact with the TextBox's text.


    References:

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.