04-04-2006, 09:50 PM
Is there a way to make tooltips include an image, resize the tooltip box etc.
I am making a small app and I would like to implement a pretty tooltip. Anyone familiar with this?
If any of you are familiar with Amazon or Netflix, they have nice bubble tips that show info on mouseover...I'm trying to do pretty mucht the same thing in VB.NET. Any help greatly appreciated. I can make my tooltips, I just dont know how to make them pretty :)
04-05-2006, 10:40 AM
Look into the OwnerDraw property and DrawItem event; I can give you an example later (I've gotta run to school now).
04-05-2006, 01:23 PM
Ok, here's that sample I promised. The following code will create a tooltip as shown in attached image (Prt Scrn never includes the mouse, so it looks a bit weird).
First add a tooltip to your form. Set the OwnerDraw property to True. Then add the following code:
Dim tltImage As Bitmap ' add to Declarations section
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tltImage = New Bitmap("C:\Documents and Settings\User\My Documents\My Pictures\meet_charlie_brown_big.gif") ' a pic on my computer, you'll need to change this.
Private Sub ToolTip1_Draw(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawToolTipEventArgs) Handles ToolTip1.Draw
e.Graphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
' do a cool gradient "glass" look.
Dim topHalf As New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height \ 2 + 1)
Dim bottomHalf As New Rectangle(e.Bounds.X, e.Bounds.Y + e.Bounds.Height \ 2 - 2, e.Bounds.Width, e.Bounds.Height \ 2 + 2)
e.Graphics.FillRectangle(New Drawing2D.LinearGradientBrush(topHalf, Color.WhiteSmoke, Color.Silver, Drawing2D.LinearGradientMode.Vertical), topHalf)
e.Graphics.FillRectangle(New Drawing2D.LinearGradientBrush(bottomHalf, Color.DimGray, Color.Gray, Drawing2D.LinearGradientMode.Vertical), bottomHalf)
' draw our picture
e.Graphics.DrawImage(tltImage, 4, 4, 58, 80)
' draw the text
e.Graphics.DrawString(e.ToolTipText, Me.Font, Brushes.Black, 64, 4)
Private Sub ToolTip1_Popup(ByVal sender As Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup
' make sure our tooltip is large enough for the added space of the image
Dim newHeight As Integer = e.ToolTipSize.Height
If newHeight < 80 Then newHeight = 80
e.ToolTipSize = New Size(e.ToolTipSize.Width + 68, newHeight)
Ok, a few things to note. I've hardcoded the size that the image will be drawn at --you may need to alter this, but make sure you also change the code in the Popup event to resize the tooltip appropriately. Also, it sounds as if you might want each item in your list (or whatever) to display a different image in it's tooltip; if this is so, you'll probably need to turn this into a custom tooltip class and use an extender property to allow each control on the form to have it's own "Picture on Tooltip1" type of property.
04-05-2006, 06:22 PM
thanks so much!
I am developing a rapid prototype to be approved so complete functionality isnt a must. That was super helpful!
Not to be greedy, but do you know how to set them to be semi-transparent?
04-05-2006, 06:31 PM
I'm not sure that can be with an owner-drawn tooltips (or without getting into API calls anyways). Any level of transparency will probably require writing your own tooltip class (which might be a good idea anyways, considering the functionality you're looking for). Fortunately it's pretty easy to make your own --just create a new class, inherit Tooltip and get busy with all the trimmings.
04-15-2006, 09:05 PM
Thanks so much for the help JNewt.
I have since run accross another stump, and I have no one around me with working knowledge of .net. I found some other ballloon tips and I have the .cls, .frm, .vbp, and vpw...I spent about an hour and a half trying to import the tool to use as I would any existing tool. What is the correct way to import a tool?
Im using .net 2003
04-16-2006, 12:52 AM
Well, you're going to need to compile the project with the controls you want. Then open up the project you want to use them in, goto the toolbox, right click and selected Add/Remove Items. In the dialog that opens, click browse and navigate to the compiled project with the controls (probably in the project's "bin" folder). Double click on the .exe or .dll in that folder; VB should add the controls to your project.