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

  • Home
  • SEARCH
  • 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 9106245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:17:37+00:00 2026-06-17T02:17:37+00:00

I Set the controls back ground color in Red when i press the submit

  • 0

I Set the controls back ground color in Red when i press the submit button without any data in mandatory fields. But i need to re enter data in these missing mandatory fields. When i start to re enter data, the back ground red color goes white. Is there any chance to change all other mandatory fields color to White?

Private Sub TXTEMPID_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TXTEMPID.KeyPress
    UncheckMyControls()
    If Asc(e.KeyChar) <> 8 Then
        If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
            e.Handled = True
        End If
    End If
End Sub

Private Sub UncheckMyControls()
    Dim txt, cmb, mtxt, rtxt As Control
    For Each cmb In EMPGBDATA.Controls
        If TypeOf cmb Is ComboBox Then
            If cmb.BackColor = Color.Red Then
                cmb.BackColor = Color.White
            End If
        End If
    Next
    For Each rtxt In EMPGBDATA.Controls
        If TypeOf rtxt Is RichTextBox Then
            If rtxt.BackColor = Color.Red Then
                rtxt.BackColor = Color.White
            End If
        End If
    Next
    For Each mtxt In EMPGBDATA.Controls
        If TypeOf mtxt Is MaskedTextBox Then
            If mtxt.BackColor = Color.Red Then
                mtxt.BackColor = Color.White
            End If
        End If
    Next
    For Each txt In EMPGBDATA.Controls
        If TypeOf txt Is TextBox Then
            If txt.BackColor = Color.Red Then
                txt.BackColor = Color.White
            End If
        End If
    Next
End Sub

This is my Code

  • 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-17T02:17:39+00:00Added an answer on June 17, 2026 at 2:17 am

    As SolarBear suggested:

         For Each cnt In EMPGBDATA.Controls
            If cnt.BackColor = Color.Red Then
                cnt.BackColor = Color.White
            End If
          Next
    

    Now can you describe your problem exactly?

    So after your comments:
    You said that you are able to check if the mandatory fields are blank and if yes you are setting their backcolor to red. and you popUp as message.
    After the message you want in the first time that the user try to type something in any of your textboxes to reset the color to white:

       Private Sub txt_KeyPress(sender As System.Object, e As System.EventArgs) Handles TextBox1.KeyPress,TextBox2.KeyPress,TextBox3.KeyPress,TextBox4.KeyPress
     'After the Handles you put all the textboxes,richtexboxes that you want
     'THis way you handle the same event for a lot of controls in the same Sub
         UncheckMyControls()
       End Sub
    

    So after your comments2:

        Private Sub control_KeyPress(sender As System.Object, e As System.EventArgs) Handles TextBox1.KeyPress,TextBox2.KeyPress,TextBox3.KeyPress,ComboBox1.KeyPress,ComboBox2.KeyPress
     'After the Handles you put all the textboxes,richtexboxes,comboboxes that you want
     'THis way you handle the same event for a lot of controls in the same Sub
         UncheckMyControls()
       End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of controls bound to data, on which I would like
The setup: Web form with lots of TextBox controls. When I set any one
I have TextBlock inside HierarchicalDataTemplate. I need to set foreground color to Red when
I need to set the foreground color of disabled controls to black instead of
Is there a way using CSS, to set a mx.controls.ComboBox 's background color. This
How can we set border and background color in the WPF grid control ,
If a set of controls on a WinForm have had DataBindings created and attached
When I set webbrowser controls Width and Height at form_load and navigate then it
I have a list of items on a page with a set of controls
How can I set the System.Windows.Controls.DatePicker control as used within a Silverlight project to

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.