Windows Develop Bookmark and Share   
 index > Windows Forms General > BalloonTip Problems of C#
 

BalloonTip Problems of C#

well, I have some Balloontip problems need to be settled, please help~~

I have a Event ListBox on the form, in the ListBox are some events

there is a NotifyIcon on the form

I want to show all the event to the user by using BalloonTip, Balloon can be closed only by user.(not automatically) How can I make it, thank you.

I have already give a code, but this code has problem, can any of you rewrite one, or find the problem of the code?

for(int i = 0; i<listBox1.Items.Count;++i)

{

notifyIcon1.Visible = true;
notifyIcon1.BalloonTipTitle = "You have a Notice";

notifyIcon1.BalloonTipText = this.listBox1.Items[ i ].ToString();
notifyIcon1.ShowBalloonTip(2000);

}

Rong Sheng  Thursday, August 09, 2007 5:05 PM

Hi,

Try the following. As you are invalidating the BalloonTip every time you call a new ShowBalloonTip method, the BalloonTipClosed method is getting called without the help of the user. Therefore, by employing a boolean to tell your program when the BalloonTip is being updated, it can distinguish between a user clicking the close button and the routine update of the time. Also, you might want to disable the Timer rather than just changing a flag when the user clicks the close button so that you're not using up memory with a timer not executing any code. Hope this helps Wink

-----------------------------------------------------------

Public Class BalloonTipTime

Private startTime As Date

Private Invalidated As Boolean


Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim timeSpent As TimeSpan = DateTime.Now - startTime

Dim toopTipText As String = timeSpent.Hours & ":" & timeSpent.Minutes & ":" & timeSpent.Seconds

'Let your program know it's about to update the BalloonTip

Invalidated = True

NotifyIcon1.ShowBalloonTip(500, "Yout Status", toopTipText, ToolTipIcon.None)

End Sub


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

startTime = DateTime.Now

End Sub


Private Sub NotifyIcon1_BalloonTipClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.BalloonTipClosed

If Invalid = False Then 'This method wasn't called by updating the BalloonTip

Timer1.Enabled = False

End If

Invalid = False 'Finished updating the BalloonTip

End Sub


End Class

For more information ,check this

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=281450&SiteID=1

With Regards

Gavin Jin - MSFT  Friday, August 10, 2007 8:34 AM

Rong Sheng,

your code is showing a list of BalloonTips one immediately after the other. According to the documentation, if you attempt to show a balloon whenanother isalready active, and both balloons are from the same application, the first will be closed and the second will be shown immediately (this may vary, please look at the doc). In your case, you will only see the last balloon. To achieve an effect of showing a list of notifications one after the other, make a list of them, and then wait for the BalloonTipClosed event before attempting to show the next in the list.

As for your second issue, you cannot keep a balloon active forever. As the documentation says, it depends on the OS and a few other conditions, but there are limits to the timeouts allowed, and are generally between 10 and 30 seconds. Your timeout will be automatically adjusted if it doesn't fit in this range.

The only possibility I see is to draw your own balloons. In this case you will be fully in control of their behavior.

--mc

Mario Cossi  Thursday, August 09, 2007 5:51 PM

Hello, thank you for answering me, I have a problem from your reply, that is

how can i wait for the BalloonTipClosed event?

can youshow mea hand?

Rong Sheng  Thursday, August 09, 2007 6:07 PM

Hi,

Try the following. As you are invalidating the BalloonTip every time you call a new ShowBalloonTip method, the BalloonTipClosed method is getting called without the help of the user. Therefore, by employing a boolean to tell your program when the BalloonTip is being updated, it can distinguish between a user clicking the close button and the routine update of the time. Also, you might want to disable the Timer rather than just changing a flag when the user clicks the close button so that you're not using up memory with a timer not executing any code. Hope this helps Wink

-----------------------------------------------------------

Public Class BalloonTipTime

Private startTime As Date

Private Invalidated As Boolean


Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim timeSpent As TimeSpan = DateTime.Now - startTime

Dim toopTipText As String = timeSpent.Hours & ":" & timeSpent.Minutes & ":" & timeSpent.Seconds

'Let your program know it's about to update the BalloonTip

Invalidated = True

NotifyIcon1.ShowBalloonTip(500, "Yout Status", toopTipText, ToolTipIcon.None)

End Sub


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

startTime = DateTime.Now

End Sub


Private Sub NotifyIcon1_BalloonTipClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.BalloonTipClosed

If Invalid = False Then 'This method wasn't called by updating the BalloonTip

Timer1.Enabled = False

End If

Invalid = False 'Finished updating the BalloonTip

End Sub


End Class

For more information ,check this

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=281450&SiteID=1

With Regards

Gavin Jin - MSFT  Friday, August 10, 2007 8:34 AM

Thanks toall of you, I have custom a form to instead of BalloonTip. I had solved the problem.

And, I am very sorry, for I am not familiar with VB.

Thank you again.

Rong Sheng  Saturday, August 11, 2007 12:18 PM

You can use google to search for other answers

Custom Search

More Threads

• SqlClient error
• How to compile unrunnable classes?
• how to change the character spacing in richtextbox
• how do you find the tag of a clicked menu item
• Creating movable (via the mouse) objects
• Set status label text in MDIPartet from MDIChild
• FlowLayoutPanel very poor layout performance
• padding on tabpages
• MySettings1 debris being generated in designer?
• Code group attributes