Solved

Label Forecolor is changing unexpectedly?

Posted on 2014-07-18
8
198 Views
Last Modified: 2014-07-18
I have a datagridview that contains quite a few controls, GroupBoxes, Tabs to name a couple. In one of my GB's, I have several labels that when they appear, there Forecolor is either Green or Red. This GB is resides on a TabPage as well as does another smaller TabControl. When I click on a TabPage of the smaller TabControl...the ForeColor of the Labels in the GB revert back to Black. Now there is no code in my logic that does this...consequently I'm stumped as to why this would happen. Any other action I do on the form doesn't change the Labels back to Green or Red. My guess is that it has something to do with the Form and/or certain controls repainting themselves but not certain.
0
Comment
Question by:BlakeMcKenna
  • 3
  • 3
  • 2
8 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40204751
Can you post a screen shot of the UI it will help in visualizing what you are saying. Also post the code showing the way you update the Forecolor of the control.

What type of application Windows Form, WPF other?
What language are you using?
0
 
LVL 40
ID: 40204855
Perform a project wide search for .Green and .Red, using the Find in Files feature (Ctrl-Shift-F). It might lead you to the culprit.

If this does not give results, try for Green, but without the dot in case the color is not straight Green, but something like DarkGreen.
0
 

Author Comment

by:BlakeMcKenna
ID: 40204954
This is a VB.Net Windows App. Here is a screenshot.
Screenshot.jpg
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40205018
How about the code showing how the Forecolor is being set.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:BlakeMcKenna
ID: 40205039
Sorry...here ya go!

                    If CBool(clsMain.loadTEST) Then
                        lblLoad_TestStatus.Visible = True
                        cboDefaultLoad.Checked = True

                        If clsMain.loadTESTComplete Then
                            lblLoad_TestStatus.ForeColor = Color.Green
                            lblLoad_TestStatus.Text = "Complete"
                        Else
                            lblLoad_TestStatus.ForeColor = Color.Red
                            lblLoad_TestStatus.Text = "Incomplete"
                        End If

                        InitializeErrorClass(EH)
                        cmbChannel1.Text = BL.GetChannel(clsLoadH.channel_ID, EH)

                        InitializeErrorClass(EH)
                        cmbDirection1.Text = BL.GetDirection(clsLoadH.direction_ID, EH)

                        InitializeErrorClass(EH)
                        cmbCellPosition1.Text = BL.GetAngle(clsLoadH.angle_ID, EH)

                        txtLoadingCapacity.Text = clsLoadH.load
                        cmbLoadDecimal1.Text = clsLoadH.loadDecimalPlaces

                        InitializeErrorClass(EH)
                        cmbLoadUnitType.Text = BL.GetUnitType(clsLoadH.loadUnitType_ID, EH)

                        InitializeErrorClass(EH)
                        cmbLoadUnit.Text = BL.GetUnit(clsLoadH.loadUnit_ID, EH)

                        InitializeErrorClass(EH)
                        cmbOutputUnitType.Text = BL.GetUnitType(clsLoadH.outputUnitType_ID, EH)

                        InitializeErrorClass(EH)
                        cmbOutputUnit.Text = BL.GetUnit(clsLoadH.outputUnit_ID, EH)

                        InitializeErrorClass(EH)
                        cmbOutputDecimal1.Text = clsLoadH.outputDecimalPlaces

                        InitializeErrorClass(EH)
                        GetLoadData(iMain_ID, EH)

                        cmbRunNo.SelectedIndex = 0

                        If EH.ErrorMessage > "" Then
                            GoTo ProcessMessage
                        End If
                    End If

                    If CBool(clsMain.repeatabilityTEST) Then
                        lblRepeatability_TestStatus.Visible = True
                        cboRepeatabilityTest.Checked = True

                        If clsMain.repeatabilityTESTComplete Then
                            lblRepeatability_TestStatus.ForeColor = Color.Green
                            lblRepeatability_TestStatus.Text = "Complete"
                        Else
                            lblRepeatability_TestStatus.ForeColor = Color.Red
                            lblRepeatability_TestStatus.Text = "Incomplete"
                        End If

                        If Not tabTests.TabPages.Contains(tabRepeatabilityTest) Then
                            tabTests.TabPages.Add(tabRepeatabilityTest)
                        End If
                    End If

                    If CBool(clsMain.creepTEST) Then
                        lblCreep_TestStatus.Visible = True
                        cboCreepTest.Checked = True

                        If clsMain.creepTESTComplete Then
                            lblCreep_TestStatus.ForeColor = Color.Green
                            lblCreep_TestStatus.Text = "Complete"
                        Else
                            lblCreep_TestStatus.ForeColor = Color.Red
                            lblCreep_TestStatus.Text = "Incomplete"
                        End If

                        If Not tabTests.TabPages.Contains(tabCreepTest) Then
                            tabTests.TabPages.Add(tabCreepTest)
                        End If
                    End If

                    If CBool(clsMain.zeroBalanceTEST) Then
                        lblFirstFinalZero_TestStatus.Visible = True
                        cboFirstFinalZero.Checked = True

                        If clsMain.zeroBalanceTESTComplete Then
                            lblFirstFinalZero_TestStatus.ForeColor = Color.Green
                            lblFirstFinalZero_TestStatus.Text = "Complete"
                        Else
                            lblFirstFinalZero_TestStatus.ForeColor = Color.Red
                            lblFirstFinalZero_TestStatus.Text = "Incomplete"
                        End If
                    End If

                    If CBool(clsMain.shuntTEST) Then
                        lblShunt_TestStatus.Visible = True
                        cboShuntTest.Checked = True

                        If clsMain.shuntTESTComplete Then
                            lblShunt_TestStatus.ForeColor = Color.Green
                            lblShunt_TestStatus.Text = "Complete"
                        Else
                            lblShunt_TestStatus.ForeColor = Color.Red
                            lblShunt_TestStatus.Text = "Incomplete"
                        End If
                    End If

                    If CBool(clsMain.excitationTEST) Then
                        lblExcitation_TestStatus.Visible = True
                        cboExcitation.Checked = True

                        If clsMain.excitationTESTComplete Then
                            lblExcitation_TestStatus.ForeColor = Color.Green
                            lblExcitation_TestStatus.Text = "Complete"
                        Else
                            lblExcitation_TestStatus.ForeColor = Color.Red
                            lblExcitation_TestStatus.Text = "Incomplete"
                        End If
                    End If

                    If CBool(clsMain.reproducibilityTEST) Then
                        lblReproducibility_TestStatus.Visible = True
                        cboReproducibility.Checked = True

                        If clsMain.reproducibilityTESTComplete Then
                            lblReproducibility_TestStatus.ForeColor = Color.Green
                            lblReproducibility_TestStatus.Text = "Complete"
                        Else
                            lblReproducibility_TestStatus.ForeColor = Color.Red
                            lblReproducibility_TestStatus.Text = "Incomplete"
                        End If
                    End If

                    If CBool(clsMain.recoveryTEST) Then
                        lblRecovery_TestStatus.Visible = True
                        cboRecovery.Checked = True

                        If clsMain.recoveryTESTComplete Then
                            lblRecovery_TestStatus.ForeColor = Color.Green
                            lblRecovery_TestStatus.Text = "Complete"
                        Else
                            lblRecovery_TestStatus.ForeColor = Color.Red
                            lblRecovery_TestStatus.Text = "Incomplete"
                        End If
                    End If

                    If CBool(clsMain.resistanceTEST) Then
                        lblResistance_TestStatus.Visible = True
                        cboResistance.Checked = True

                        If clsMain.resistanceTESTComplete Then
                            lblResistance_TestStatus.ForeColor = Color.Green
                            lblResistance_TestStatus.Text = "Complete"
                        Else
                            lblResistance_TestStatus.ForeColor = Color.Red
                            lblResistance_TestStatus.Text = "Incomplete"
                        End If
                    End If

                    If CBool(clsMain.leakageTEST) Then
                        lblLeakage_TestStatus.Visible = True
                        cboLeakage.Checked = True

                        If clsMain.leakageTESTComplete Then
                            lblLeakage_TestStatus.ForeColor = Color.Green
                            lblLeakage_TestStatus.Text = "Complete"
                        Else
                            lblLeakage_TestStatus.ForeColor = Color.Red
                            lblLeakage_TestStatus.Text = "Incomplete"
                        End If
                    End If
                End If

Open in new window

0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40205141
Do you ever set the ForeColor to Nothing?
Also Have you done a global search of the project for Green as James has suggested?

The reason I ask if you have set the ForeColor somewhere to Nothing is because ForeColor is a ambient  property.

From Microsoft Documentation.

The ForeColor property is an ambient property. An ambient property is a control property that, if not set, is retrieved from the parent control. For example, a Button will have the same BackColor as its parent Form by default. For more information about ambient properties, see the AmbientProperties class or the Control class overview.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40205153
Have you tried my solution? If the color is set to green or red, it is done somewhere, possibly in a place you did not think to look for. A search will find it.
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40205187
I know why it's doing it now. I have a routine that handles all control settings including the ForeColor and BackColor properties. When I selected a Tab from the TabControl, it executed that function which caused the Label to revert back to it's specified color, which in this case was it's default color of Black!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Duplicate a row 2 46
Procedure or function has too many arguments specified 9 41
Make a border less form movable 2 22
Help with sorting data in Listbox using VB.NET 3 53
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

8 Experts available now in Live!

Get 1:1 Help Now