ExtenderProvider invalidated event problems...

Posted on 2007-07-22
Last Modified: 2013-11-26
VB.NET 2005

I have a component class that adds several provider extensions to a form and one of them is a Required property along with a Required color property and a Satisfied color property.  I add a xxxChanged event handler that checks to see if the control's text is empty and if it is, I set the backcolor of that field to the Required color and if it is not empty, then I set it to the Satisified color.  I was having trouble before with trying to get the control (textbox, combobox, etc.) painted initially until I started handling the Invalidated event.  This worked fine for the textbox, combobox but failed for the NumericUpDown control.  It fails with an infinite loop where the invalidated event triggers the text changed event triggering the invalidated event, ad nauseum.  So, then I thought that perhaps I might trap the Paint event of the container that contains the control I'm extending, but I've not been too successful with this approach.  Is there an event I can trap for a control when it is first displayed on a screen so that I can set its initial backcolor correctly depending on if it is empty or not?
Question by:dpbouchard
    LVL 7

    Accepted Solution

    Generally, you would need to use the OnPaint event for the control itself, but it appears that Windows does the painting for things such as Textbox controls (even if you inherit from them)

    See here for full details, and a possible workaround:
    LVL 7

    Expert Comment

    Just had another idea which could work, depending on how you're working the application:

    For the control you want to change the backcolor of, create an function for the Validating event, such as the following:

        Private Sub TextBox1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
           ' If text is empty, draw with a black background, otherwise set to white
            If String.IsNullOrEmpty(TextBox1.Text) Then
                TextBox1.BackColor = Color.Black
                TextBox1.BackColor = Color.White
            End If
        End Sub

    Then, place the following line in your Form_Load method:


    That way, if the textbox is empty when the form first loads, it will validate it straight away, and automatically set the background colour.

    Hope that helps, though I'm not sure if it's exactly what you need.........

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now