VB.NET 2012, how to make ErrorProvider's message stay visible? - vb.net

Does anyone know how to make the ErrorProvider's message stay visible when the mouse is over the ErrorProvider's icon? The message goes away or becomes not visible after a few seconds. People are complaining that there isn't enough time to read the message and they have to move the mouse away then back onto to the icon to see the message again.
Edit:
Tried Steve's suggestion (below) but the message still goes away
ErrorProvider1.BlinkRate = ErrorBlinkStyle.NeverBlink
ErrorProvider1.BlinkStyle = ErrorBlinkStyle.NeverBlink
ErrorProvider1.SetError(Me.TextBox1, "Error")
This link Set ErrorProvider ToolTip Duration asks the exact same question I'm trying to ask here, unfortunately the question in the link is unanswered too.

VB 2012, Framework 3.5, Windows Forms Application. For reasons unknown to me, if one sets the BlinkRate to something between 10 and approx 4500 and sets the BlinkStyle = ErrorBlinkStyle.AlwaysBlink the ErrorProvider's tooltip / message will stay visible indefinitely as long as the mouse is hovered over the ErrorProvider's icon.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
ErrorProvider.BlinkRate = 250
ErrorProvider.BlinkStyle = ErrorBlinkStyle.AlwaysBlink
End Sub

Related

MessageBox launches but does not display

I'm working on a project and I am using a button to show a message box with sample data.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("hi")
End Sub
Simple enough.
However, when you click the button, I hear the sound that the MessageBox has launched, but the form is never displayed.
I know it has launched because if I try to do anything after clicking the button, I'm locked out. I have to press enter to acknowledge the MessageBox before I can continue.
This project used to display the MessageBox, but it has stopped.
I've tried several different areas in code, but whenever I show a MessageBox, I get the same results. Any ideas on what I have done?
never mind, I solved it.
there was a sub that was rendering a picturebox every time the form_paint was called. It overwrote the messagebox on the screen.

What causes Visual Studio To Change Control Names?

In one project, the names of my GUI controls are being changed at compile time.
Say, for example, I have a Label control named **lblRow0Col1".
I noticed my code was failing to find the control by name:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each ctrl As Control In Controls ' .Find("Label*", False)
If ctrl.Name = "lblRow0Col1" Then
ctrl.Text = DateTime.Now.ToShortDateString()
End If
Next
End Sub
So, I stepped through that routine and found the control I needed had been renamed to what looks like a GUI string.
lbl.Name = "07178f89-6fdd-47c7-9f84-d4d661df7554"
I created a test project to see what was going on, but this is not happening in the test project.
Is there a VS setting that tells the compiler to scramble the control names?
How do I stop this behavior?
OK, I’ve been looking at the code for that routine that populates a "details view" screen.
Before, I was filling the detail screen as soon as the Inventory Item variable changed.
I got to thinking that people rarely view the details screen, so why not just populate it after the screen was displayed? I had an event for “after displayed”, so I moved it there.
Well, I just moved it back ...and the odd behavior went away.
I don’t know what the issue was that caused that to happen, though.
The Label controls should have already been generated, but it acts like they were not until the tab screen they were on was selected.
So, there's an answer, but I'd rather someone explain to me what I did wrong.

Why doesn't a MsgBox trigger a lost focus event VB.net?

I have a timer that each time displays a message box saying "Hello." I also have the code configured so whenever the window loses focus, it should stop the timer that keeps the boxes coming. However, they keep coming.
I have tried a similar thing in a similar program with way too long of code to post here, but what it did was it paused the first time, stop the timer, and when the timer was stopped again, it didn't work correctly. There was also some other code there that had a random element, that displayed a different prompt when a certain number was generated, but once it was generated, it kept using that same different prompt every time.
Is this a error of not enough time to process all the code and it "overlaps" some? I can delay the timer without that much different effects, but I think that my [lower end] CPU that it is running this program on, that with 1.6 GHz that it could handle a timer with a few message boxes. Though, VS is running at the same time, but I shouldn't have to export my code and close VS everytime that I need to test it.
If the problem is not enough time, is there a way that I can prevent my program from "multithreading" or whatever it is doing? It seems like a weird problem, but computers are very weird too. :P
Edit:
By "Focus" I mean the selected window that is the most apparent. For example, my browser is now "focused." I have been informed that the correct term is "selected." I must have been using the wrong type of event trigger... :P
It doesn't generate a lost-focus event because the form doesn't have the focus in the first place. A control on the form always gets the focus, like a Button or TextBox. You could use the Deactivate event instead.
Or just not display the message box when the Tick event fires again. Roughly:
Private ShowingMsgBox As Boolean
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'' Do stuff
''
If Not ShowingMsgBox Then
ShowingMsgBox = True
MsgBox("yada")
ShowingMsgBox = False
End If
End Sub
The underlying reason for this behavior is that MsgBox pumps a message loop. It keeps normal Windows messages getting delivered, like WM_PAINT that keeps the windows painted. And WM_TIMER, the one that generates the Tick event. The only kind of messages that it blocks are input events, mouse and keyboard messages. Otherwise the reason that Application.DoEvents() is so very dangerous. It does the same thing as MsgBox() does, without disabling input.
Create a new project with a Timer (Timer1) and write this code:
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
If (Me.Focused) Then
MessageBox.Show("Hello")
End If
End Sub
If you put the mouse over your form, you would see that a message box will popup after the given Interval is over. If you don't click on the accept button and keep the mouse on the form, you would see that no further messages appear: Me.Focus is False. If you click on the accept button, the messages would start poping up; you don't even need to select the form (the focus is transferred automatically from the MessageBox to the Form).
Summary: the MessageBox does make the Form to lose the focus, although it is a kind of a "tricky" lost as far as will automatically come back after clicking on the accept button.
UPDATE: the proposed configuration does trigger a LostFocus event of the form:
Private Sub Form1_LostFocus(sender As Object, e As System.EventArgs) Handles Me.LostFocus
MsgBox("lost")
End Sub
Unlikely the other answers/comments, what I understood from your question is that you want to know the reason and if this is a normal behaviour, rather than getting a working solution to make the form to lose the focus (you are not even describing the exact conditions under which you want this to happen).

Winforms: Closing a program to system tray

'This is the event that is fired as the application is closing, whether it
'be from a close button in the application or from the user
'clicking the X in the upper right hand corner
Private Sub Form1_FormClosing(sender as Object, e as FormClosingEventArgs) Handles Form1.FormClosing
'What we will do here is trap the closing of the application and send the application
'to the system tray (or so it will appear, we will just make it invisible, re-showing
'it will be up to you and your notify icon)
'First minimize the form
Me.WindowState = FormWindowState.Minimized
'Now make it invisible (make it look like it went into the system tray)
Me.Visible = False
End Sub
Hello again Stackoverflow!
Im trying to make an application that when you press X, the program gets put in system tray. But i have like no idea how i'm suppost to do that, so did a search on google and found this code. Only VB2010 (what i use) doesn't like the fourth line. Can anybody give me a quick tutorial on this, and make this work in VB 2010?
By the way, i will most likely use VB only tonight, just to make one application. So im not thinking of learing the whole language.
It looks like you found code over here Dream.In.Code: Minimize To System Tray
Did you "keep" reading the rest of the messages?
You need to add:
e.Cancel = True
to your FormClosing event or else the program just ends. Also, you need to add the NotifyIcon component and a ContextMenuStrip.

Problems with message boxes in VB.NET

Windows 7 Home Premium X64
Visual Basic 2010 Express SP1
All Visual Studio updates installed except for a Visual C++ security update
The problem:
Sometimes message boxes in a console app close after clicking the ok button on one before all the messages are displayed. It is just supposed to display one message box after another.
Same code as above, A message box in a console app will sometimes minimize to the taskbar before displaying all the messages after the OK button is clicked on
The same code as the above 2 problem but in a Windows form app will display all of the message boxes, But.sometimes won't show the form at the end like it should.
The bugs I know happen when I run the programs from VB itself, don't know about the EXE outside of VB.
I know it isn't my code because others have tried it and had no problems.
What can I try to fix it?
EDIT: Code for the one with the button and form:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim anInteger As Integer = 42
Dim aSingle As Single = 39.345677653
Dim aString As String = "I like pancakes"
Dim aBoolean As Boolean = True
MsgBox(anInteger)
MsgBox(aSingle)
MsgBox(aString)
MsgBox(aBoolean)
End Sub
End Class
Code for the console ones:
Module Module1
Sub Main()
Dim anInteger As Integer = 42
Dim aSingle As Single = 39.345677653
Dim aString As String = "I like candy"
Dim aBoolean As Boolean = True
MsgBox(anInteger)
MsgBox(aSingle)
MsgBox(aString)
MsgBox(aBoolean)
End Sub
End Module
If you've run the exact code you posted above, and you're getting the symptoms you describe... I would say that it is probably a hardware problem, specifically a problem with either your mouse or your keyboard.
You believe you are clicking the mouse button once (to close the OK button). But just at the moment that the system is trying to show you the next message box, it thinks you hit the mouse button a second time - or maybe it thinks you hit the SPACE bar - either way, it closes the next message box instantly.
Prove (or disprove) my theory:
First, wait until after hours, or until you're the only one in the building. (Hint: One of your "friends" might be playing a joke on you, using some sort of remote-access technology.)
Remove your mouse and keyboard. Borrow the mouse and keyboard from some other computer (at least temporarily) and plug them in instead.
Reboot. (Shouldn't need this, but try it anyway -- just to be sure.)
Start your program. When the first message box appears, wait to make sure it doesn't go away on it's own. Then carefully click the mouse ONCE on the OK button. Repeat for the other 3 message boxes.
If the problem still happens, try it again, except don't use the mouse at all - use your keyboard's SPACE bar to dismiss the message boxes.
If needed, try it one more time, this time with the ENTER key.
If the problem still hasn't gone away, try booting in SAFE MODE -- perhaps some other software is interfering! Also try doing a virus scan, even if you're fairly certain you don't have a virus.