ImageExtensions Module
Description
The ImageExtensions Module contains several Extension Methods for the Image, ImageButton, and HtmlImage controls to simply several common tasks.
Example
Image
Me.imgImage1.SetWidthHeight()
Me.imgImage2.AddRollover("~/images/rotatefrog.gif")
Me.imgImage3.AddRollover("~/images/rotatefrog.gif", "~/images/frog.gif")
ImageButton
Me.imgButton1.SetWidthHeight()
Me.imgButton2.AddRollover("~/images/rotatefrog.gif")
Me.imgButton3.AddRollover("~/images/rotatefrog.gif", "~/images/frog.gif")
HtmlImage
Me.imgHtml1.SetWidthHeight()
Me.imgHtml2.AddRollover("~/images/rotatefrog.gif")
Me.imgHtml3.AddRollover("~/images/rotatefrog.gif", "~/images/frog.gif")
Properties & Methods
SetWidthHeight()This Extension Method extends the Image, ImageButton, and HtmlImage controls by setting the Width and Height properties of the Image or ImageButton or the width and height CSS properties of the HtmlImage. If the ImageUrl or Src property is not set or the image specified does not exist, no action is taken. AddRollover(ByVal rollover As String)This Extension Method can be used with the Image, ImageButton, or HtmlImage controls to add a rollover using the control's current ImageUrl or Src property and the specified image. Note: The rollover will not work with the ImageButton if the Enabled property is set to False.
  • rollover - The URL of the rollover image
AddRollover(ByVal rollover As String, ByVal initial As String)This Extension Method can be used with the Image, ImageButton, or HtmlImage controls to set the control's ImageUrl or Src property and add a rollover using the specified images. Note: The rollover will not work with the ImageButton if the Enabled property is set to False.
  • rollover - The URL of the rollover image
  • initial - The URL of the image to set the ImageUrl or Src property to
Source Code
ImageExtensions.vb:

Remarks
When using the AddRollover Extension Methods with an ImageButton, be sure to keep in mind that the rollover will not work when Enabled="False".