BalloonTipText on NotifyIcon1 Hover over?

I've been looking at how to use BalloonTipText, and I found this small section of code:

NotifyIcon1.BalloonTipTitle = "Balloon Tip Title"

NotifyIcon1.BalloonTipText = "Balloon Tip Text."

NotifyIcon1.BalloonTipIcon = ToolTipIcon.Error

That isn't working for me though, in the test app I made to try it out. I put it in the NotifyIcon1_Click event and nothing showed up. I'd really like to be able to display something when the user hovers over the notify icon too, and I couldn't find a hover over event. Also, can I use a variable for the text in the balloon tip Any help would be appreciated.



Answer this question

BalloonTipText on NotifyIcon1 Hover over?

  • KavitaRavi

    There was actually no error.  It just didn't do anything.  Like I said, the form loaded, it displayed the weather page in the browser, and that was it.  The BalloonToolTip never showed on its own or whether I hovered or clicked on the notify icon.  The only time I got an error was when I hovered over the icon before getting any weather, and I expected to see that error (which was "Object reference not set to an instance of an object") because the variable which would hold the weather forecast was not equal to anything at that point.
  • Venksys

    This is why I suggested you put a BreakPoint in your code, that way you can step thru it (even if there is no actual error raised) and see in the values for all your variables and maybe trace where the problem is. And you will know if the messages are being sent to the Notify Icon's BalloonToolTip that way.

    Otherwise, as I mentioned earlier, it may be a problem with your installation, OS version, or a spyware program blocking messages to the Notify Icon.

    james

    aka:Trucker


  • Pavel Cristian Gabriel

    This works for me, for getting weather (ignore the HTML stuff, I haven't bothered to strip that out yet) . Add a Button to a form, a Textbox, a Web Browser Control and a NotifyIcon. Then the following code:

    Public Class Form1

    Dim mytxt As String

    Private Sub btnGetWeather_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetWeather.Click

    Dim sr As IO.StreamReader

    Dim wc As New System.Net.WebClient

    Dim strUrl As String

    Dim strOut As String = ""

    strUrl = String.Format("http://xml.weather.yahoo.com/forecastrss p={0}", txtZip.Text)

    Try

    sr = New IO.StreamReader(wc.OpenRead(strUrl))

    Dim strHtml As String = sr.ReadToEnd

    Dim x As Integer = strHtml.IndexOf("<img src")

    Dim y As Integer = strHtml.IndexOf(")<br/>")

    strOut = strHtml.Substring(x, y - x + 6)

    sr.Close()

    Catch

    strOut = "<h1>Error getting weather</h1>"

    Finally

    WebBrowser1.DocumentText = strOut

    End Try

    mytxt = strOut.ToString

    ' Me.NotifyIcon1.BalloonTipText = strOut.ToString

    ' Me.NotifyIcon1.ShowBalloonTip(100)

    End Sub

    Private Sub NotifyIcon1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseMove

    Me.NotifyIcon1.BalloonTipText = mytxt.ToString

    Me.NotifyIcon1.ShowBalloonTip(100)

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Me.NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info

    Me.NotifyIcon1.BalloonTipTitle = "WEATHER ALERT!"

    End Sub

    End Class

    Enter a zip code in the Textbox and click on BtnGetWeather and it will retreive Yahoo's weather forcast. Hover your mouse pointer over the Notify Icon in the system Tray, and the Balloon Tooltip will popup with the weather forcast, along with all the other stuff it cannot display correctly, but, you get the idea here.

    james

    aka:Trucker


  • Slugo

    Put it in your Form's Deactivated Event. And add this:

    NotifyIcon1.ShowTooltip(1)

    That way, when you minimize the form ( clicking the Minus sign in the upper right corner of the form) it will show the tooltip text  at the Notify Icon you added to your project. Also, if you look in the Notify Icon's Properties you will see a TEXT property, this is where you add the text for when the mouse pointer is over the Notify Icon in the System Tray. And you can use a variable to hold your string for your Notify Icon's Text Property.

    Dim nifIconTxt as String

    NotifyIcon1.Text = nifIcon

     

     

    james

    aka:Trucker

     

     


  • chrisfewtrell

    That is strange!! I cannot imagine why it wouldn't work. You are using VB2005 Express Edition aren't you Your code example sure looks that way to me. Do you get the weather when you click the Get Weather button ( after putting in a zip code in txtZip) I even did this to get the weather info to show up when the weather page completed loading:

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

    Me.NotifyIcon1.BalloonTipText = mytxt.ToString

    Me.NotifyIcon1.ShowBalloonTip(100)

    End Sub

    Enter a zip, click Get Weather, and in a moment............the BalloonTooltip pops up and has the weather in it. Pretty cool. I cannot imagine why this isn't working for you.

    james

    aka:Trucker


  • Jim Carnicelli

    Yes, I'm using VB2005 Express Edition.  Very strange.  Is this some kind of bug   I get the icon, and the weather page loads properly, but nothing else happens.  Another odd thing is that I moved the mouse over the notify icon once before entering any weather, and got an error, because there was no weather data to display, so it looks like it is trying to do something, it just isn't working when there's weather.
  • xcao

    Thanks.  I tried that and it didn't work.  I know about setting the text property for a notify icon and that it shows that text, but I have a weather program, and I'd like it to show the weather for a specific area, which my program gets, whenever the mouse hovers over the icon in the system tray.  Thanks for any help.  Here's what I have.

     

    Public Class Form1

    Dim mytext As String = "This is a line of text"

    Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate

    NotifyIcon1.BalloonTipTitle = "Balloon Tip Title"

    NotifyIcon1.BalloonTipText = mytext

    NotifyIcon1.ShowBalloonTip(1000)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    End Class


  • Freddie70

    No problem! Other than an OS specific problem or VB2005 install issue, I cannot see what could be going on here. Unless, you are running an anti-spyware program that thinks the messages between the app and the Notify Icon are suspect in some way. You can try an put a Breakpoint in the Notify Icon's Mouse_Move event or even send the output to the Output Window to see if the message is actually being passed to the Notify Icon.

    Console.WriteLine(mytxt.ToString)

    then, when you exit out of the program the data should show up in the Output Window.

    ( you may have to go to VIEW: OTHER WINDOWS: OUTPUT WINDOW to see it.)

    james

    aka:Trucker


  • LIKEKE1

    I'm sure you did this, but, just in case, did you assign an Icon to the Notify Icon on it's property page The code you posted is basicly the same thing that I did here as a test and it works fine. It appears that the BalloonToolTip only shows up when it is triggered by some event, like Deactivating the form. You could have your application grab your weather info on a timer, and when the timer reaches the point that you want it to ( the time it checks for a weather update) you could grab the data as a string and assign it to the BalloonToolTip. Then, it should pop up the Balloon Tooltip with the info. Other than that, you may have to roll your own. (just an idea)

    james

    aka:Trucker


  • KimFreeborn

    Blake81 wrote:
    Yes, I'm using VB2005 Express Edition. Very strange. Is this some kind of bug I get the icon, and the weather page loads properly, but nothing else happens. Another odd thing is that I moved the mouse over the notify icon once before entering any weather, and got an error, because there was no weather data to display, so it looks like it is trying to do something, it just isn't working when there's weather.

    I don't see why this isn't working for you. Maybe, it is OS specific. I am using Windows XP and it works fine here. You may have to do a reinstall of VB2005 EE to fix the problem. As for the error you mentioned when there is no weather to display and you move the mouse pointer over the Notify Icon, it's a simple fix. I had slapped the code I posted together to test the problem you were having. All is needed it to check to see if the Web Browser's Document is empty, like so:

    Private Sub NotifyIcon1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseMove

    If Not WebBrowser1.Document Is Nothing Then

    Me.NotifyIcon1.BalloonTipText = mytxt.ToString

    Me.NotifyIcon1.ShowBalloonTip(100)

    Else

    Exit Sub

    End If

    End Sub

    Now, if you move the pointer over the Notify Icon before clicking Get Weather button, nothing will happen (other than a popup with the Notify Icon's regular Tooltip Text).

    But, when you enter the zip code and click get weather, the Balloon Tip will pop up when the document is completed (loaded into the web browser). Or when you hold the mouse pointer over it.

    james

    aka:Trucker


  • Victor Havin

    This is strange. I used the exact code you posted, down to naming the controls the same thing, and it doesn't work for me. I did specify an icon for the notify icon like you asked, and I can see the notify icon. It just doesn't do anything if I hover over it or click it. I'm not sure why.
  • Julio Molinero

    Giving trucker the exact error would be helpful. There isn't much definitive information in, "it didn't work".



  • oman

    Thanks. It didn't really matter about the error, I was just pointing out the fact that the program gave the error because it obviously knew I was moving the mouse over the icon, which is good. It's just strange that it isn't working for me.
  • Sat-Bangalore

    In case you're wondering, I just ran your code again, and it works. I don't know what the problem was. It could have just been some problem with my system. I've been having unrelated problems with this computer and I'm now running Windows XP Professional x64 trial version. The format could have gotten rid of whatever the problem was. This is great because I can now have the weather show up for the user's favorite zip code when they have my app minimized. Is there a way to have it automatically go away so I don't have to click the X to close the balloon I thought that was what the number was for in this line:

    Me.NotifyIcon1.ShowBalloonTip(100)

    I thought that was the timeout in milliseconds. Maybe not.


  • BalloonTipText on NotifyIcon1 Hover over?