Results 1 to 2 of 2

Thread: vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    1

    vb.net

    Hello sir i have question, please reply immediately.


    How to design an application in VB.NET such that a form has 2 command buttons. When user makes a mouse-move event on commandbutton1 the color of commnd button1 changed slowly to RED. Green for commandbutton2.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: vb.net

    try this:

    vb Code:
    1. Imports System.Drawing.Imaging
    2.  
    3. Public Class Form1
    4.  
    5.     Dim img1 As Bitmap
    6.     Dim img2 As Bitmap
    7.  
    8.     Dim offSetRed As Integer = 100
    9.     Dim offSetGreen As Integer = 100
    10.  
    11.     Public Enum fadeColor
    12.         green
    13.         red
    14.     End Enum
    15.  
    16.     Private Sub Button1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseWheel
    17.         If e.Delta > 0 Then
    18.             offSetRed = If(offSetRed - (e.Delta / 20) > 100, CInt(offSetRed - (e.Delta / 20)), 100)
    19.             Button1.Image = setRGBContrast(img1, fadeColor.red)
    20.         Else
    21.             offSetRed = If(offSetRed + (Math.Abs(e.Delta) / 20) < 200, CInt(offSetRed + (Math.Abs(e.Delta) / 20)), 200)
    22.             Button1.Image = setRGBContrast(img1, fadeColor.red)
    23.         End If
    24.     End Sub
    25.  
    26.     Private Sub Button2_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseWheel
    27.         If e.Delta > 0 Then
    28.             offSetGreen = If(offSetGreen - (e.Delta / 20) > 100, CInt(offSetGreen - (e.Delta / 20)), 100)
    29.             Button2.Image = setRGBContrast(img2, fadeColor.green)
    30.         Else
    31.             offSetGreen = If(offSetGreen + (Math.Abs(e.Delta) / 20) < 200, CInt(offSetGreen + (Math.Abs(e.Delta) / 20)), 200)
    32.             Button2.Image = setRGBContrast(img2, fadeColor.green)
    33.         End If
    34.     End Sub
    35.  
    36.     Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
    37.         img1 = New Bitmap(Button1.Width, Button1.Height)
    38.         Button1.DrawToBitmap(img1, New Rectangle(0, 0, Button1.Width, Button1.Height))
    39.         img2 = New Bitmap(Button2.Width, Button2.Height)
    40.         Button2.DrawToBitmap(img2, New Rectangle(0, 0, Button2.Width, Button2.Height))
    41.         Button1.TextImageRelation = TextImageRelation.Overlay
    42.         Button1.Image = img1
    43.         Button2.TextImageRelation = TextImageRelation.Overlay
    44.         Button2.Image = img2
    45.     End Sub
    46.  
    47.     Public Function setRGBContrast(ByVal original As Bitmap, ByVal changeColor As fadeColor) As Bitmap
    48.         Dim brtR As Single = If(changeColor = fadeColor.red, CSng(offSetRed / 100), 1.0F)
    49.         Dim brtG As Single = If(changeColor = fadeColor.green, CSng(offSetGreen / 100), 1.0F)
    50.         Dim brtB As Single = 1.0F
    51.         Dim image_attr As New ImageAttributes
    52.         Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
    53.             { _
    54.             New Single() {brtR, 0.0, 0.0, 0.0, 0.0}, _
    55.             New Single() {0.0, brtG, 0.0, 0.0, 0.0}, _
    56.             New Single() {0.0, 0.0, brtB, 0.0, 0.0}, _
    57.             New Single() {0.0, 0.0, 0.0, 1.0, 0.0}, _
    58.             New Single() {0.0, 0.0, 0.0, 0.0, 1.0}})
    59.  
    60.         Dim rect As Rectangle = _
    61.             Rectangle.Round(original.GetBounds(GraphicsUnit.Pixel))
    62.         Dim wid As Integer = original.Width
    63.         Dim hgt As Integer = original.Height
    64.  
    65.         Dim newImage As New Bitmap(wid, hgt)
    66.         Dim gr As Graphics = Graphics.FromImage(newImage)
    67.  
    68.         image_attr.SetColorMatrix(cm)
    69.         gr.DrawImage(original, rect, 0, 0, wid, _
    70.             hgt, GraphicsUnit.Pixel, image_attr)
    71.  
    72.         Return newImage
    73.  
    74.     End Function
    75.  
    76. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width