I tend to agree but we recently had a situation where the customer wanted the tooltip to show for a longer period of time. When that is the requirement you must come up with something other than title='blah'.
For anyone who has a similar requirement I recommend Walter Zorn's tooltip library (www.walterzorn.com). Here is a server side class I created based on his library. You don't get design time support but it fully supports his library as of about a year ago.
Imports System.Collections.Generic
Public Class WZToolTip
#Region " Fields and Enums "
Private _tipText As String = "" Private _above As Boolean = False Private _bgColor As String = "#E4E7FF" Private _bgImage As String = "" Private _borderColor As String = "#002299" Private _borderStyle As String = "solid" Private _borderWidth As Integer = 1 Private _centerMouse As Boolean = False Private _clickClose As Boolean = False Private _closeButton As Boolean = False Private _closeButtonText As String = " X " Private _closeButtonColors As CloseButtonColors Private _copyContent As CopyContent Private _delay As Integer = 400 Private _duration As Integer = 0 Private _fadeIn As Integer = 0 Private _fadeOut As Integer = 0 Private _fix As FixedCoordinate Private _followMouse As Boolean = True Private _fontColor As String = "#000044" Private _fontFamily As String = "Verdana,Geneva,sans-serif" Private _fontSize As String = "8pt" Private _fontWeight As FontWeight Private _left As Boolean = False Private _offsetX As Integer = 14 Private _offsetY As Integer = 8 Private _opacity As Integer = 100 Private _padding As Integer = 3 Private _shadow As Boolean = False Private _shadowColor As String = "#C0C0C0" Private _shadowWidth As Integer = 5 Private _sticky As Boolean = False Private _textAlign As Align Private _title As String = "" Private _titleAlign As Align Private _titleBGColor As String = "" Private _titleFontColor As String = "#ffffff" Private _titleFontFamily As String = "" Private _titleFontSize As String = "" Private _width As Integer = 0 Private _tip As StringBuilder Private _properties As ArrayList Private _listItemProps As ListItemCollection Private _balloon As Boolean = False Private _followScroll As Boolean = False Private _centerWindow As Boolean = False Private _centerAlways As Boolean = False
Enum BalloonColor Blue = 0 LightBlue = 1 Manilla = 2 End Enum
#End Region
#Region " Properties "
Public Property FollowScroll() As Boolean Get Return _followScroll End Get Set(ByVal value As Boolean) _followScroll = value Sticky = value SetListItemProperty("FOLLOWSCROLL, ", _followScroll.ToString().ToLower()) End Set End Property
Public Property CenterWindow() As Boolean Get Return _centerWindow End Get Set(ByVal value As Boolean) _centerWindow = value Sticky = value SetListItemProperty("CENTERWINDOW, ", _centerWindow.ToString().ToLower()) End Set End Property
Public Property CenterAlways() As Boolean Get Return _centerAlways End Get Set(ByVal value As Boolean) _centerAlways = value SetListItemProperty("CENTERALWAYS, ", _centerAlways.ToString().ToLower()) End Set End Property
Public Property Balloon() As Boolean Get Return _balloon End Get Set(ByVal value As Boolean) _balloon = value SetListItemProperty("BALLOON, ", _balloon.ToString().ToLower()) End Set End Property
Public Property TipText() As String Get Return _tipText End Get Set(ByVal value As String) _tipText = value.Replace("'", "\'") _tipText = _tipText.Replace(Chr(&HD) & Chr(&HA), "<br/>") _tipText = _tipText.Replace(vbCrLf, "<br/>")
If Not _tipText.Contains("<br/>") And _tipText.Length > 66 Then _tipText = clsUtil.WrapTextAt(_tipText, "<br/>", 66) End If
End Set End Property
Public Property Above() As Boolean Get Return _above End Get Set(ByVal value As Boolean) _above = value SetListItemProperty("ABOVE, ", _above.ToString().ToLower()) End Set End Property
Public Property BGColor() As String Get Return _bgColor End Get Set(ByVal value As String) _bgColor = value.Replace("'", "") SetListItemProperty("BGCOLOR, ", "'" & _bgColor & "'") End Set End Property
Public Property BGImage() As String Get Return _bgImage End Get Set(ByVal value As String) _bgImage = value.Replace("'", "") SetListItemProperty("BGIMG, ", "'" & _bgImage & "'") End Set End Property
Public Property BorderColor() As String Get Return _borderColor End Get Set(ByVal value As String) _borderColor = value.Replace("'", "") SetListItemProperty("BORDERCOLOR, ", "'" & _borderColor & "'") End Set End Property
Public Property BorderStyle() As String Get Return _borderStyle End Get Set(ByVal value As String) _borderStyle = value.Replace("'", "") SetListItemProperty("BORDERSTYLE, ", "'" & value.ToLower() & "'") End Set End Property
Public Property BorderWidth() As Integer Get Return _borderWidth End Get Set(ByVal value As Integer) _borderWidth = value SetListItemProperty("BORDERWIDTH, ", _borderWidth.ToString()) End Set End Property
Public Property CenterMouse() As Boolean Get Return _centerMouse End Get Set(ByVal value As Boolean) _centerMouse = value SetListItemProperty("CENTERMOUSE, ", _centerMouse.ToString().ToLower()) End Set End Property
Public Property ClickClose() As Boolean Get Return _clickClose End Get Set(ByVal value As Boolean) _clickClose = value SetListItemProperty("CLICKCLOSE, ", _clickClose.ToString().ToLower()) End Set End Property
Public Property CloseButton() As Boolean Get Return _closeButton End Get Set(ByVal value As Boolean) _closeButton = value Sticky = value SetListItemProperty("CLOSEBTN, ", _closeButton.ToString().ToLower()) End Set End Property
Public Property CloseButtonColors() As CloseButtonColors Get Return _closeButtonColors End Get Set(ByVal value As CloseButtonColors) _closeButtonColors = value SetTypeNameProperty(_closeButtonColors) End Set End Property
Public Property CloseButtonText() As String Get Return _closeButtonText End Get Set(ByVal value As String) _closeButtonText = value.Replace("'", "\'") SetListItemProperty("CLOSEBTNTEXT, ", "'" & _closeButtonText & "'") End Set End Property
Public Property CopyContent() As CopyContent Get Return _copyContent End Get Set(ByVal value As CopyContent) _copyContent = value SetTypeNameProperty(_copyContent) End Set End Property
Public Property Delay() As Integer Get Return _delay End Get Set(ByVal value As Integer) _delay = value SetListItemProperty("DELAY, ", _delay.ToString()) End Set End Property
Public Property Duration() As Integer Get Return _duration End Get Set(ByVal value As Integer) _duration = value SetListItemProperty("DURATION, ", _duration.ToString()) End Set End Property
Public Property FadeIn() As Integer Get Return _fadeIn End Get Set(ByVal value As Integer) _fadeIn = value SetListItemProperty("FADEIN, ", _fadeIn.ToString()) End Set End Property
Public Property FadeOut() As Integer Get Return _fadeOut End Get Set(ByVal value As Integer) _fadeOut = value SetListItemProperty("FADEOUT, ", _fadeOut.ToString()) End Set End Property
Public Property FixedCoordinates() As FixedCoordinate Get Return _fix End Get Set(ByVal value As FixedCoordinate) _fix = value SetTypeNameProperty(_fix) End Set End Property
Public Property FollowMouse() As Boolean Get Return _followMouse End Get Set(ByVal value As Boolean) _followMouse = value SetListItemProperty("FOLLOWMOUSE, ", _followMouse.ToString().ToLower()) End Set End Property
Public Property FontColor() As String Get Return _fontColor End Get Set(ByVal value As String) _fontColor = value.Replace("'", "") SetListItemProperty("FONTCOLOR, ", "'" & _fontColor & "'") End Set End Property
Public Property FontFamily() As String Get Return _fontFamily End Get Set(ByVal value As String) _fontFamily = value.Replace("'", "") SetListItemProperty("FONTFACE, ", "'" & _fontFamily & "'") End Set End Property
Public Property FontSize() As String Get Return _fontSize End Get Set(ByVal value As String) _fontSize = value.Replace("'", "") SetListItemProperty("FONTSIZE, ", "'" & _fontSize & "'") End Set End Property
Public Property FontWeight() As FontWeight Get Return _fontWeight End Get Set(ByVal value As FontWeight) _fontWeight = value SetTypeNameProperty(_fontWeight) End Set End Property
Public Property Left() As Boolean Get Return _left End Get Set(ByVal value As Boolean) _left = value SetListItemProperty("LEFT, ", _left.ToString().ToLower()) End Set End Property
Public Property OffsetX() As Integer Get Return _offsetX End Get Set(ByVal value As Integer) _offsetX = value SetListItemProperty("OFFSETX, ", _offsetX.ToString()) End Set End Property
Public Property OffsetY() As Integer Get Return _offsetY End Get Set(ByVal value As Integer) _offsetY = value SetListItemProperty("OFFSETY, ", _offsetY.ToString()) End Set End Property
Public Property Opacity() As Integer Get If _opacity > 100 Then Return 100 Else Return _opacity End If End Get Set(ByVal value As Integer) If Not value < 0 Then _opacity = value Else _opacity = 0 End If SetListItemProperty("OPACITY, ", _opacity.ToString()) End Set End Property
Public Property Padding() As Integer Get Return _padding End Get Set(ByVal value As Integer) _padding = value SetListItemProperty("PADDING, ", _padding.ToString()) End Set End Property
Public Property Shadow() As Boolean Get Return _shadow End Get Set(ByVal value As Boolean) _shadow = value SetListItemProperty("SHADOW, ", _shadow.ToString().ToLower()) End Set End Property
Public Property ShadowColor() As String Get If String.IsNullOrEmpty(_shadowColor) Then Return "#C0C0C0" End If Return _shadowColor End Get Set(ByVal value As String) _shadowColor = value.Replace("'", "") SetListItemProperty("SHADOWCOLOR, ", "'" & _shadowColor & "'") End Set End Property
Public Property ShadowWidth() As Integer Get If _shadowWidth = 0 Then Return 5 End If Return _shadowWidth End Get Set(ByVal value As Integer) _shadowWidth = value SetListItemProperty("SHADOWWIDTH, ", _shadowWidth.ToString()) End Set End Property
Public Property Sticky() As Boolean Get Return _sticky End Get Set(ByVal value As Boolean) _sticky = value SetListItemProperty("STICKY, ", _sticky.ToString().ToLower()) End Set End Property
Public Property TextAlign() As Align Get Return _textAlign End Get Set(ByVal value As Align) _textAlign = value SetTypeNameProperty(_textAlign) End Set End Property
Public Property Title() As String Get Return _title End Get Set(ByVal value As String) _title = value.Replace("'", "\'") SetListItemProperty("TITLE, ", "'" & _title & "'") End Set End Property
Public Property TitleAlign() As Align Get Return _titleAlign End Get Set(ByVal value As Align) _titleAlign = value SetTypeNameProperty(_titleAlign) End Set End Property
Public Property TitleBackgroundColor() As String Get Return _titleBGColor End Get Set(ByVal value As String) _titleBGColor = value.Replace("'", "") SetListItemProperty("TITLEBGCOLOR, ", "'" & _titleBGColor & "'") End Set End Property
Public Property TitleFontColor() As String Get Return _titleFontColor End Get Set(ByVal value As String) _titleFontColor = value.Replace("'", "") SetListItemProperty("TITLEFONTCOLOR, ", "'" & _titleFontColor & "'") End Set End Property
Public Property TitleFontFamily() As String Get If String.IsNullOrEmpty(_titleFontFamily) Then Return _fontFamily End If Return _titleFontFamily End Get Set(ByVal value As String) _titleFontFamily = value.Replace("'", "") SetListItemProperty("TITLEFONTFACE, ", "'" & _titleFontFamily & "'") End Set End Property
Public Property TitleFontSize() As String Get If String.IsNullOrEmpty(_titleFontSize) Then Return _fontSize End If Return _titleFontSize End Get Set(ByVal value As String) _titleFontSize = value.Replace("'", "") SetListItemProperty("TITLEFONTSIZE, ", "'" & _titleFontSize & "'") End Set End Property
Public Property Width() As Integer Get Return _width End Get Set(ByVal value As Integer) _width = value SetListItemProperty("WIDTH, ", _width.ToString()) End Set End Property
Public Property Tip() As String Get Return GetTip() End Get Set(ByVal value As String) _tip.Length = 0 _tip.Append(value) End Set End Property
#End Region
#Region " Methods "
Public Sub New(Optional ByVal ttipText As String = " ")
TipText = ttipText _tip = New StringBuilder() _properties = New ArrayList() _copyContent = New CopyContent _fix = New FixedCoordinate _closeButtonColors = New CloseButtonColors _textAlign = New Align(Align.eAlignType.TextAlign, Align.AlignValue.Left) _titleAlign = New Align(Align.eAlignType.TitleAlign, Align.AlignValue.Left) _listItemProps = New ListItemCollection()
End Sub
Private Sub SetListItemProperty(ByVal propertyName As String, ByVal propertyValue As String) Dim item As ListItem = _listItemProps.FindByText(propertyName) If item Is Nothing Then item = New ListItem(propertyName, propertyValue) _listItemProps.Add(item) Else item.Value = propertyValue End If
If Not item Is Nothing Then If Not _properties.Contains(item) Then _properties.Add(item) Else For Each obj As Object In _properties If TypeOf (obj) Is ListItem Then Dim pItem As ListItem = DirectCast(obj, ListItem) If Not pItem Is Nothing Then If pItem.Text = propertyName Then pItem.Value = item.Value Exit For End If End If End If
Next End If End If
End Sub
Private Sub SetTypeNameProperty(ByVal classType As Object) Dim found As Boolean = False Dim name As String = classType.GetType().Name
For Each obj As Object In _properties If obj.GetType().Name = name Then If Not name = "Align" Then obj = classType found = True Else Dim al As Align = obj Dim al2 As Align = DirectCast(classType, Align) If al.AlignType = al2.AlignType Then obj = classType found = True End If End If End If Next
If Not found Then _properties.Add(classType) End If
End Sub
Public Function GetTip() As String
Dim objectName As String = "" Dim paramItem As ListItem Dim algn As Align Dim fixedCoord As FixedCoordinate Dim fntWeight As FontWeight Dim cBtnColors As CloseButtonColors
_tip.Length = 0
If Not CopyContent.ControlID.Length = 0 Then _tip.Append("TagToTip('" & CopyContent.ControlID & "'") Else _tip.Append("Tip('" & TipText & "'") End If
For Each obj As Object In _properties Try objectName = obj.GetType().Name
_tip.Append(", ")
Select Case objectName
Case "ListItem"
paramItem = DirectCast(obj, ListItem) _tip.Append(paramItem.Text & paramItem.Value)
Case "Align"
algn = DirectCast(obj, Align) _tip.Append(algn.GetValue())
Case "FixedCoordinate"
fixedCoord = DirectCast(obj, FixedCoordinate) _tip.Append(fixedCoord.GetValue())
Case "FontWeight"
fntWeight = DirectCast(obj, FontWeight) _tip.Append(fntWeight.GetValue())
Case "CloseButtonColors"
cBtnColors = DirectCast(obj, CloseButtonColors) _tip.Append(cBtnColors.GetValue())
Case "CopyContent"
_tip.Append("COPYCONTENT, " & CopyContent.CopyInnerHTML.ToString.ToLower)
End Select
Catch ex As Exception
End Try
Next
Dim tipString As String = _tip.ToString().Trim() tipString = tipString.TrimEnd(Convert.ToChar(",")) tipString += ");" _tip.Length = 0 _tip.Append(tipString) Return _tip.ToString()
End Function
Public Function GetAnchorTip(ByVal displayText As String, Optional ByVal styleString As String = "text-decoration: none; border: 0;") As String
Dim lnk As String = "<a href='javascript:void(0);' style='" & styleString & "' onmouseover=""" & GetTip() & """>" & displayText & "</a>" Return lnk
End Function
Public Function GetImageTip(ByVal imageSrc As String, Optional ByVal styleString As String = "text-decoration: none; border: 0;") As String Dim lnk As String = "<img src='" & imageSrc & "' style='" & styleString & "' onmouseover=""" & GetTip() & """ alt=''/>" Return lnk
End Function
Public Function AttachMouseOver(ByVal control As Object) As Object
Dim webControl As System.Web.UI.WebControls.WebControl Dim htmlControl As System.Web.UI.HtmlControls.HtmlControl Dim htmlGenControl As System.Web.UI.HtmlControls.HtmlGenericControl
Try If TypeOf (control) Is WebControl Then webControl = DirectCast(control, WebControl)
If Not webControl Is Nothing Then webControl.Attributes("onmouseover") = GetTip() End If
Return webControl
Else If TypeOf (control) Is HtmlControl Then htmlControl = DirectCast(control, HtmlControl)
If Not htmlControl Is Nothing Then htmlControl.Attributes("onmouseover") = GetTip() End If
Return htmlControl ElseIf TypeOf (control) Is HtmlGenericControl Then htmlGenControl = DirectCast(control, HtmlGenericControl)
If Not htmlGenControl Is Nothing Then htmlGenControl.Attributes("onmouseover") = GetTip() End If
Return htmlGenControl End If End If Catch ex As Exception Return Nothing End Try
Return Nothing End Function
Public Shared Function GetBalloonImagePathStartUpScript(ByVal color As BalloonColor, Optional ByVal applicationRoot As String = "") As String
Dim tagStart As String = "<script language=" Dim tagEnd As String = "</script>" Dim mainDirectory As String = "/javascript" Dim imgDirectory As String = "" Dim config As String = " config. BalloonImgPath = '" Dim sb As New StringBuilder()
If applicationRoot.Length = 0 Then applicationRoot = clsUtil.GetRootUrl End If
sb.Append(tagStart) sb.Append(config) sb.Append(applicationRoot) sb.Append(mainDirectory)
Select Case color Case BalloonColor.Blue imgDirectory = "/tip_balloon_blue';"
Case BalloonColor.LightBlue imgDirectory = "/tip_balloon_lightblue';"
Case BalloonColor.Manilla imgDirectory = "/tip_balloon_manilla';"
Case Else imgDirectory = "/tip_balloon_lightblue';"
End Select
sb.Append(imgDirectory) sb.Append(" Balloon_PreCacheDefImgs();") sb.Append(tagEnd)
Return sb.ToString
End Function
Public Shared Function GetClientScriptIncludes(ByVal IncludeBalloon As Boolean, Optional ByVal color As BalloonColor = BalloonColor.LightBlue) As String
Dim sb As StringBuilder = New StringBuilder() Dim appRoot As String = GetRootUrl Dim mainJs As String = "/javascript/wz_tooltip.js'" Dim balloonJs As String = "" Dim tagStart As String = "<script language=" Dim tagEnd As String = "></script>"
sb.Append(tagStart) sb.Append(appRoot) sb.Append(mainJs) sb.Append(tagEnd)
If IncludeBalloon Then
sb.Append(tagStart) sb.Append(appRoot)
Select Case color Case BalloonColor.Blue balloonJs = "/javascript/tip_balloon_blue.js'"
Case BalloonColor.LightBlue balloonJs = "/javascript/tip_balloon_lightblue.js'"
Case BalloonColor.Manilla balloonJs = "/javascript/tip_balloon_manilla.js'"
Case Else balloonJs = "/javascript/tip_balloon_lightblue.js'"
End Select
sb.Append(balloonJs) sb.Append(tagEnd) sb.Append(GetBalloonImagePathStartUpScript(color, appRoot)) End If
Return sb.ToString
End Function
Public Shared Function GetRootUrl() As String Dim ctrl As New System.Web.UI.Control() Dim str As String = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) & ctrl.ResolveUrl(HttpContext.Current.Request.ApplicationPath) ctrl.Dispose() Return str End Function
#End Region
End Class
Public Class CloseButtonColors
#Region " Fields "
Private _bkgndColor As String = "#990000" Private _textColor As String = "#FFFFFF" Private _hoverColor As String = "#DD3333" Private _textHoverColor As String = "#FFFFFF"
#End Region
#Region " Properties "
Public Property BackGroundColor() As String Get Return _bkgndColor End Get Set(ByVal value As String) _bkgndColor = value.Replace("'", "") End Set End Property
Public Property TextColor() As String Get Return _textColor End Get Set(ByVal value As String) _textColor = value.Replace("'", "") End Set End Property
Public Property HoverColor() As String Get Return _hoverColor End Get Set(ByVal value As String) _hoverColor = value.Replace("'", "") End Set End Property
Public Property TextHoverColor() As String Get Return _textHoverColor End Get Set(ByVal value As String) _textHoverColor = value.Replace("'", "") End Set End Property
#End Region
#Region " Methods "
Public Sub New()
End Sub
Public Sub New(ByVal sBackGroundColor As String, ByVal sTextColor As String, ByVal sHoverColor As String, ByVal sTextHoverColor As String) BackGroundColor = sBackGroundColor TextColor = sTextColor HoverColor = sHoverColor TextHoverColor = sTextHoverColor End Sub
Public Function GetValue() As String Return "CLOSEBTNCOLORS, ['" & _bkgndColor & "', '" & _textColor & "', '" & _hoverColor & "', '" & _textHoverColor & "']" End Function
#End Region
End Class
Public Class CopyContent #Region " Fields "
Private _controlID As String = "" Private _copyInnerHtml As Boolean = True
#End Region
#Region " Properties "
Public Property ControlID() As String Get Return _controlID End Get Set(ByVal value As String) _controlID = value End Set End Property
Public Property CopyInnerHTML() As Boolean Get Return _copyInnerHtml End Get Set(ByVal value As Boolean) _copyInnerHtml = value End Set End Property
#End Region
#Region " Methods "
Public Sub New() End Sub
Public Sub New(ByVal sControlID As String) ControlID = sControlID End Sub
#End Region
End Class
Public Class FixedCoordinate
#Region " Fields "
Private _x As Integer Private _y As Integer Private _jsFunction As String
#End Region
#Region " Properties "
Public Property X() As Integer Get Return _x End Get Set(ByVal value As Integer) _x = value End Set End Property
Public Property Y() As Integer Get Return _y End Get Set(ByVal value As Integer) _y = value End Set End Property
Public Property JavaScriptFunction() As String Get Return _jsFunction End Get Set(ByVal value As String) _jsFunction = value End Set End Property
#End Region
#Region " Methods "
Public Sub New()
End Sub
Public Sub New(ByVal iX As Integer, ByVal iY As Integer) X = iX Y = iY End Sub
Public Function GetValue() As String If Not String.IsNullOrEmpty(_jsFunction) Then Return "FIX, " & _jsFunction Else Return "FIX, [" & _x.ToString() & ", " & _y.ToString() & "]" End If End Function
#End Region
End Class
Public Class FontWeight
#Region " Fields "
Private _fntWeight As FntWeight
Enum FntWeight Normal = 0 Bold = 1 End Enum
#End Region
#Region " Properties "
Public Property Value() As FntWeight Get Return _fntWeight End Get Set(ByVal value As FntWeight) _fntWeight = value End Set End Property
#End Region
#Region " Methods "
Public Sub New()
End Sub
Public Sub New(ByVal eFontWeight As FntWeight) Value = eFontWeight End Sub
Public Function GetValue() As String Select Case _fntWeight Case FntWeight.Bold Return "FONTWEIGHT, " & "'bold'" Case Else Return "FONTWEIGHT, " & "'normal'" End Select End Function
#End Region
End Class
Public Class Align
#Region " Fields "
Private _alignType As eAlignType Private _alignValue As AlignValue
Enum eAlignType TextAlign = 0 TitleAlign = 1 End Enum
Enum AlignValue Left = 0 Right = 1 Center = 2 Justify = 3 End Enum
#End Region
#Region " Properties "
Public Property AlignType() As eAlignType Get Return _alignType End Get Set(ByVal value As eAlignType) _alignType = value End Set End Property
Public Property Value() As AlignValue Get Return _alignValue End Get Set(ByVal value As AlignValue) _alignValue = value End Set End Property
#End Region
#Region " Methods "
Public Sub New()
End Sub
Public Sub New(ByVal enumAlignType As eAlignType, ByVal enumAlignValue As AlignValue) AlignType = enumAlignType Value = enumAlignValue End Sub
Private Function AlignTypeToString() As String If AlignType = eAlignType.TitleAlign Then Return "TITLEALIGN" Else Return "TEXTALIGN" End If End Function
Public Function GetValue() As String
Select Case Value Case AlignValue.Left Return AlignTypeToString() & ", 'left'" Case AlignValue.Right Return AlignTypeToString() & ", 'right'" Case AlignValue.Center Return AlignTypeToString() & ", 'center'" Case AlignValue.Justify Return AlignTypeToString() & ", 'justify'" Case Else Return AlignTypeToString() & ", 'left'" End Select
End Function
#End Region
End Class
|