A
Andrew
On my vb.net 2.0 app I am loading an image to a picture box and auto
resizing it to show as a thumbnail. As it find the correct size it calls
RaisesEvent with the size percent. In the app I use that to show back to the
person that is using the form.
Here is my class:
Public Class ClassWithEvent
Public Event ReportImageScale(ByVal ScaledSize As Integer)
Public Function GetThumbNailSize(ByVal strImagePath As String, ByVal
iScaleSize As Integer, _
Optional ByVal ScaleWidth As Integer = 0, Optional ByVal ScaleHeight As
Integer = 0) As Size
If System.IO.File.Exists(strImagePath) Then
Dim iW As Integer = 0
Dim iH As Integer = 0
Try
Dim iThumb As Image = Image.FromFile(strImagePath)
If ScaleWidth = 0 And ScaleHeight = 0 Then
Dim X As Double = (iScaleSize * 0.01)
iW = CInt(iThumb.Width * X)
iH = CInt(iThumb.Height * X)
Else
Dim bTrue As Boolean = False
Do Until bTrue = True
Dim X As Double = (iScaleSize * 0.01)
iW = CInt(iThumb.Width * X)
iH = CInt(iThumb.Height * X)
If iW <= ScaleWidth And iH <= ScaleHeight Then
bTrue = True
RaiseEvent ReportImageScale(iScaleSize)
End If
iScaleSize -= 1
System.Windows.Forms.Application.DoEvents()
Loop
End If
GetThumbNailSize.Width = iW
GetThumbNailSize.Height = iH
Return GetThumbNailSize
Catch ex As Exception
Call mdlMain.LogError(ex.Message)
End Try
End If
End Function
End Class
Here is when I call ReportImageScale:
Dim img = New ClassWithEvent()
If Not Me.pb1.Image Is Nothing Then Me.pb1.Image.Dispose()
Me.pb1.Size = img.GetThumbNailSize(pstrLogoPath, 100,
Me.pbDark.Width - 15, Me.pbDark.Height - 15)
Me.pb1.Image = img.GetThumbNail(pstrLogoPath, 100,
Me.pbDark.Width - 15, Me.pbDark.Height - 15)
Me.pb1.Left = (Me.pbDark.Left + (Me.pbDark.Width / 2)) -
(Me.pb1.Width / 2)
Me.pb1.Top = (Me.pbDark.Top + (Me.pbDark.Height / 2)) -
(Me.pb1.Height / 2)
Me.pb1.Visible = True
Here is when the event gets fired in the app:
Public WithEvents obj As ClassWithEvent
Protected Sub obj_ReportImageScale(ByVal ScaledSize As Integer) Handles
obj.ReportImageScale
Me.nud1.Value = ScaledSize
End Sub
Does anybody have any idea why it’s not fired when I call the RaiseEvent
from the class?
resizing it to show as a thumbnail. As it find the correct size it calls
RaisesEvent with the size percent. In the app I use that to show back to the
person that is using the form.
Here is my class:
Public Class ClassWithEvent
Public Event ReportImageScale(ByVal ScaledSize As Integer)
Public Function GetThumbNailSize(ByVal strImagePath As String, ByVal
iScaleSize As Integer, _
Optional ByVal ScaleWidth As Integer = 0, Optional ByVal ScaleHeight As
Integer = 0) As Size
If System.IO.File.Exists(strImagePath) Then
Dim iW As Integer = 0
Dim iH As Integer = 0
Try
Dim iThumb As Image = Image.FromFile(strImagePath)
If ScaleWidth = 0 And ScaleHeight = 0 Then
Dim X As Double = (iScaleSize * 0.01)
iW = CInt(iThumb.Width * X)
iH = CInt(iThumb.Height * X)
Else
Dim bTrue As Boolean = False
Do Until bTrue = True
Dim X As Double = (iScaleSize * 0.01)
iW = CInt(iThumb.Width * X)
iH = CInt(iThumb.Height * X)
If iW <= ScaleWidth And iH <= ScaleHeight Then
bTrue = True
RaiseEvent ReportImageScale(iScaleSize)
End If
iScaleSize -= 1
System.Windows.Forms.Application.DoEvents()
Loop
End If
GetThumbNailSize.Width = iW
GetThumbNailSize.Height = iH
Return GetThumbNailSize
Catch ex As Exception
Call mdlMain.LogError(ex.Message)
End Try
End If
End Function
End Class
Here is when I call ReportImageScale:
Dim img = New ClassWithEvent()
If Not Me.pb1.Image Is Nothing Then Me.pb1.Image.Dispose()
Me.pb1.Size = img.GetThumbNailSize(pstrLogoPath, 100,
Me.pbDark.Width - 15, Me.pbDark.Height - 15)
Me.pb1.Image = img.GetThumbNail(pstrLogoPath, 100,
Me.pbDark.Width - 15, Me.pbDark.Height - 15)
Me.pb1.Left = (Me.pbDark.Left + (Me.pbDark.Width / 2)) -
(Me.pb1.Width / 2)
Me.pb1.Top = (Me.pbDark.Top + (Me.pbDark.Height / 2)) -
(Me.pb1.Height / 2)
Me.pb1.Visible = True
Here is when the event gets fired in the app:
Public WithEvents obj As ClassWithEvent
Protected Sub obj_ReportImageScale(ByVal ScaledSize As Integer) Handles
obj.ReportImageScale
Me.nud1.Value = ScaledSize
End Sub
Does anybody have any idea why it’s not fired when I call the RaiseEvent
from the class?