Imports System.Drawing.Imaging
Public Class Form1
Dim img1 As Bitmap
Dim img2 As Bitmap
Dim offSetRed As Integer = 100
Dim offSetGreen As Integer = 100
Public Enum fadeColor
green
red
End Enum
Private Sub Button1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseWheel
If e.Delta > 0 Then
offSetRed = If(offSetRed - (e.Delta / 20) > 100, CInt(offSetRed - (e.Delta / 20)), 100)
Button1.Image = setRGBContrast(img1, fadeColor.red)
Else
offSetRed = If(offSetRed + (Math.Abs(e.Delta) / 20) < 200, CInt(offSetRed + (Math.Abs(e.Delta) / 20)), 200)
Button1.Image = setRGBContrast(img1, fadeColor.red)
End If
End Sub
Private Sub Button2_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseWheel
If e.Delta > 0 Then
offSetGreen = If(offSetGreen - (e.Delta / 20) > 100, CInt(offSetGreen - (e.Delta / 20)), 100)
Button2.Image = setRGBContrast(img2, fadeColor.green)
Else
offSetGreen = If(offSetGreen + (Math.Abs(e.Delta) / 20) < 200, CInt(offSetGreen + (Math.Abs(e.Delta) / 20)), 200)
Button2.Image = setRGBContrast(img2, fadeColor.green)
End If
End Sub
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
img1 = New Bitmap(Button1.Width, Button1.Height)
Button1.DrawToBitmap(img1, New Rectangle(0, 0, Button1.Width, Button1.Height))
img2 = New Bitmap(Button2.Width, Button2.Height)
Button2.DrawToBitmap(img2, New Rectangle(0, 0, Button2.Width, Button2.Height))
Button1.TextImageRelation = TextImageRelation.Overlay
Button1.Image = img1
Button2.TextImageRelation = TextImageRelation.Overlay
Button2.Image = img2
End Sub
Public Function setRGBContrast(ByVal original As Bitmap, ByVal changeColor As fadeColor) As Bitmap
Dim brtR As Single = If(changeColor = fadeColor.red, CSng(offSetRed / 100), 1.0F)
Dim brtG As Single = If(changeColor = fadeColor.green, CSng(offSetGreen / 100), 1.0F)
Dim brtB As Single = 1.0F
Dim image_attr As New ImageAttributes
Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
{ _
New Single() {brtR, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, brtG, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, brtB, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, 1.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, 0.0, 1.0}})
Dim rect As Rectangle = _
Rectangle.Round(original.GetBounds(GraphicsUnit.Pixel))
Dim wid As Integer = original.Width
Dim hgt As Integer = original.Height
Dim newImage As New Bitmap(wid, hgt)
Dim gr As Graphics = Graphics.FromImage(newImage)
image_attr.SetColorMatrix(cm)
gr.DrawImage(original, rect, 0, 0, wid, _
hgt, GraphicsUnit.Pixel, image_attr)
Return newImage
End Function
End Class