How to add a MaskedTextBox On The ToolStrip

Mansour_Dalir 1,551 Reputation points
2024-04-16T18:24:36.6766667+00:00

User's image

hi . Is such a thing possible?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,575 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 26,591 Reputation points Microsoft Vendor
    2024-04-17T02:47:02.67+00:00

    Hi @Mansour_Dalir ,

    You can create a custom ToolStripControlHost and add the MaskedTextBox to it.

    
    Public Class MaskedTextBoxToolStripControlHost
        Inherits ToolStripControlHost
    
        Public Sub New()
            MyBase.New(New MaskedTextBox())
        End Sub
    
        Public ReadOnly Property MaskedTextBoxControl As MaskedTextBox
            Get
                Return CType(Me.Control, MaskedTextBox)
            End Get
        End Property
    End Class
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim maskedTextBoxHost As New MaskedTextBoxToolStripControlHost()
    
            maskedTextBoxHost.MaskedTextBoxControl.Mask = "00/00/0000"
            maskedTextBoxHost.MaskedTextBoxControl.Size = New Size(100, 20)
    
            ToolStrip1.Items.Add(maskedTextBoxHost)
        End Sub
    End Class
    
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    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 person found this answer helpful.

0 additional answers

Sort by: Most helpful