VB.NET Changing Colors for each line in a error message - vb.net

Hi I created an error message that contains each value of whether or not is was a pass or fail. I would like each entry to change color based on Passed = green and pail = red.
Example:
Fare: Passed
Name: Passed
Date: Failed
Address: Failed
Age: Passed
This gets displayed in an output message box, currently
msgBox(errorMessage)
When this gets displayed I like the fails background to be red and the passed to have a
green background.
Currently I am still considered new to VB.Net I know how to do for mouse hovers and mouseleaves. I am assuming I need to make an event similar to those.
Thank you For your help.

You're not going to do that with MsgBox or MessageBox.Show, which MsgBox calls internally. You're going to have to create your own form and then either add one Label for each line, in which case you can set the ForeColor for each one, or else draw the text yourself using GDI+. If you do go the Label route, you'll probably want to use a TableLayoutPanel or FlowLayoutPanel to keep them aligned correctly.

Related

How do I highlight the content of a TextBox/RefEdit control and set focus simultaneously?

I'd like to highlight the content of a TextBox/RefEdit control and set focus simultaneously when there is any invalid entry and after prompting a message box warning the error so that user knows where to fix the error. You can try Data>Analysis>DataAnalysis>Sampling and enter some invalid range/data, then you will be redirected to the invalid entry. The invalid entry is highlighted as well as with focus set (you can see a flickering cursor).
I tried to emulate this and I used,
aControl.SetFocus
aControlt.SelStart = 0
aControl.SelLength = Len(aControl.Text)
While the content inside the control is highlighted in blue, there's no flickering cursor as if I did not set focus of the control. How can I fix this? Or what's the best way to guide the user to the place where the invalid entry exists?
What if user inputs more than one invalid entries. How do you plan them all selected and setfocused at the same time.
There is no need to complicate things for you and for user. What you can do is create invisible labels with the right message you want to deliver to user, preferably in red color, and place them below each TextBox/RefEdit. Make them visible with Label1.Visible = Truewithin your conditional check.

Excel-VBA Red color labeled

I am trying to make a red label appear on my form and can not. I have tried changing the property to RGB and HEX and just get errors. Is there a way to get a property value to make my label RGB(200, 0, 0)? I am unaware of how the value in the property areas is developed.
This is the only way I can make a red label:
Private Sub Label13_Click()
Label13.BackColor = RGB(200, 0, 0)
End Sub
I have to click the label to make it red. Is there a way to use code to make it red when the form starts? Or perhaps generate a value for the property? Thank you for your help in advance.
You can use the Initialize event for the form instead of putting the event on a Click event.
Here is an example with the form named UserForm. Use the dropdowns to select the form and then the Initialize event.
You can also just set the color in the properties if you know this is the color you want.

Show Data Grid View specified cell value in Textbox

I am a student programmer who is learning VB. I am trying to make a telephone book type project in VB (Windows Forms). In my project I am using an unbound Data Grid View control. Below the Data Grid View, I have some textboxes which will display the values of the selected row. On the form load event, my program accesses a file and populates the Data Grid View control with values from the file. This works perfectly, but the problem I get is when I use the code:
txtLast.Text = dgvMain.Rows.Item(0).Cells(0).Value
to populate the textbox called txtLast with the value at the specified cell, the textbox doesn't display the value. The program doesn't crash or hang, it simply won't display the value and when I try to edit the textbox, it acts as if the textbox is empty. I have tried using
txtLast.Text = dgvMain.Rows.Item(0).Cells(0).Value.ToString()
as well as trying to refresh my Data Grid View control and the textbox. Nothing has worked so far. When I use a breakpoint to see whether that line of code is executed, the autos window shows me that the line of code is executed and that it sees the value of the specified cell as "Smith". However, when I press F11 to step into the next line, the textbox.text property remains as "" instead of changing to "Smith".
Note: when I manually specify the text through the code (i.e. txtLast.Text = "Test") it will show that text. Also, this problem is not with just one textbox, it is with every textbox that I use (I have 5 textboxes showing various values from the specified row). The weird thing is that out of the 5 textboxes, one of them, the masked textbox which shows the phone number works perfectly with the same line of code. (note it is not a problem only affecting regular textboxes as I have tried using both regular textboxes and masked textboxes, both produce the same problem except for the phone textbox).
Also, I would prefer to keep the Data grid view unbound (not connected to a database) and the textboxes unbound (not connected to the data grid view as a data source) because while browsing the internet I have seen people suggesting to bind the textbox or data grid view, however I do not understand how to do so, and I believe that this can be done without binding to a data source.
Any help is appreciated in trying to figure out why the text doesn't change. Let me know if you need any other info or if part of my explanation is unclear.
Thanks!

How to assign an output to a label in a second form through the first form?

I wanna show the output of the calculations in a second form but I am writing the code in the first form. How can I do it?
Use the parent form name in front of the control that you are trying to work with. You may need to set the modifier to Friend.
Say that the label exists in form2 and you have code in form1 that is needing to change it. So you would do it like this: form2.label.text = "the string value here"
However, keep in mind that if the control was created or is owned by a different thread then the one that is trying to edit the control, you will receive a runtime exception.
To resolve that you will need to create a delegate for the calling sub or function.

What is a good way to indicate that data has changed, but not updated?

Once a record has been saved to the database, I want to have any field change color to indicate that the user has made uncommitted changes if they type into that field.
Is it best to just set the foreColor on closeField, or is it better to track each keypress, and compare it against a variable containing the previous field content?
Are you asking how to detect a text change once a process that loaded field data has been made, and new, unsaved data is being entered? You mentioned new uncommitted changes, and I am not sure what you have in mind. This means that using a closeField handler will not indicate "uncommitted changes if they type into that field"
If so, however, I would set a custom property of the field upon writing to the database, and put a simple handler in the field script
on textChanged
if me <> the lastText of me then set the foreColor of me to "blue"
end textChanged
The property is named "the lastText", and is set by whatever handler saves to the database.
set the lastText of field "yourField" to field "yourField"
The color will change to blue if anything is edited within that field. Of course, the saving handler ought as well to set the color back to black.
Here's a card level script to handle all the fields on a form. When you load the data on to the card, set each field's uOriginalText custom property to the same value as the text loaded into the field.
on closeField
# the target control for this message
put the target into tTarget
# detect case changes like 'mr jobs' to 'Mr Jobs'
set the caseSensitive to true
# compare with the original text, set when the form was loaded
if the text of tTarget <> the uOriginalText of tTarget then
# indicate the change - I've used backColor in case the field is now empty
set the backColor of tTarget to "red"
else
# clear warning background color
set the backColor of tTarget to empty
end if
end closeField
In glx2 we actually do a bit of overkill - save the md5digest of the field when you save it, then check the md5digest of the field against the saved value to see if it needs saving. Obviously you don't want to do the computation on each keypress, no matter how fast it is. Doing that on closeField is a good way to deal with it, although I seem to remember having a problem in the past with closeField not getting triggered if you click onto another app on OSX.