Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:43:22+00:00 2026-06-15T17:43:22+00:00

I have a custom text box control which validates input (striped out unwanted chars).

  • 0

I have a custom text box control which validates input (striped out unwanted chars). This works fine apart from when I also want to do further processing on an implementation of the control.

Example I have 3 “specialTextbox”s on a form. sText1, sText2 and sText3. sText1 & sText2 work as as intended. However, I need to make changes on the forum when the value of sText3 is changed, so I have a handler in the form to handle the ctext changed event:

Private Sub sText3(sender As Object, e As EventArgs) Handles sText3.TextChanged
  'do some stuff here
End Sub

However this routine appears to override the OnTextChanged method of the custom text box. I have tried includeing a call to MyBase.OnTextChanged, but this still doesn’t cascade up and no matter what I do I can’t seem to get the text box to do its validation duties.

Must be something really simple, but I’m stumped!

Here is a class which overrides textbox

Public Class restrictedTextBox
  Inherits Windows.Forms.TextBox

  Protected validChars As List(Of Char)

  Public Sub New(ByVal _validChars As List(Of Char))
    MyBase.New()

    validChars = _validChars
  End Sub

  Public Sub setValidChars(ByVal chrz As List(Of Char))
    validChars = chrz
  End Sub

  Protected Overrides Sub OnTextChanged(e As System.EventArgs)
    MyBase.OnTextChanged(e)

    Dim newValue As String = ""
    For Each c As Char In Me.Text.ToCharArray
      Dim valid As Boolean = False
      For Each c2 As Char In validChars
        If c = c2 Then valid = True
      Next

      If valid Then newValue &= c.ToString
    Next

    Me.Text = newValue
  End Sub
End Class

Here is a form which has a a custom textbox

Public Class frmNewForm
  Private Sub btnOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOK.Click
      MessageBox.Show("the text from the restricted text is: " & txtRestricted.Text)
  End Sub
End Class

Here is a form with a custom text box, which implements the TextChanged event

Public Class frmNewForm2
  Private Sub btnOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOK.Click
    MessageBox.Show("the text from the restricted text is: " & txtRestricted.Text)
  End If

 Private Sub txtRestricted_TextChanged(sender As Object, e As EventArgs) Handles txtRestricted.TextChanged
    'now that I have implemented this method, the restrictedTextBox.OnTextChanged() doesn't fire - even if I call MyBase.OnTextChanged(e)

    'just to be completely clear. the line of code below DOES get executed. But the code in restrictedTextBox.vb does NOT 
    lblAwesomeLabel.Text=txtRestricted.Text
  End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:43:23+00:00Added an answer on June 15, 2026 at 5:43 pm

    It fires, but probably not the way you are implementing it.

    Your sample code does not have an empty constructor for the textbox, which means you are most likely not using the designer when you are adding the textbox to the form.

    But your form shows it was created by the designer:

    Private Sub txtRestricted_TextChanged(sender As Object, e As EventArgs) _
      Handles txtRestricted.TextChanged
    End Sub
    

    That’s not possible with your posted code. If you are creating “new” controls programmatically, then you need to wire up the events programmatically, too.

    Drop the handler and just leave the stub:

    Private Sub txtRestricted_TextChanged(sender As Object, e As EventArgs)
      'yada-yada-yada
    End Sub
    

    then when you create a new textbox, wire it up:

    txtRestricted = new restrictedTextBox(myCharsList)
    AddHandler txtRestricted.TextChanged, AddressOf txtRestricted_TextChanged
    Me.Controls.Add(txtRestricted)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using a custom textbox control which doesn't have Text.Split() function in this
I'm writing a custom control which includes a text box input and an unordered
I have made one custom user control (search text box), which basically consists of
I have a custom text box control which raises a routed event when its
I am creating a custom text box control to have some default formatting and
I have created a custom TextBox control which also contains a RequiredFieldValidator. Everything works
I have custom components which must adjust their text content based on space constraints.
I have a custom WPF control which consist of single TextBox <UserControl HorizontalAlignment=Left x:Class=WPFDiagramDesignerControl.Components.UcWBSBlock
I have a custom control template which is set via the style property on
Our team decided that we need our own custom Rich text box control for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.