Is there an event for image change for a PictureBox Control? please help.

  • Thread starter Thread starter Jose Michael Meo R. Barrido
  • Start date Start date
J

Jose Michael Meo R. Barrido

Hi! Can u please tech me a way to know if the image in the picturebox has
changed? what event should i catch the chage?
 
Jose,
Hi! Can u please tech me a way to know if the image in the picturebox has
changed? what event should i catch the chage?

By what (how) is the change done?

Cor
 
Jose Michael Meo R. Barrido said:
Hi! Can u please tech me a way to know if the image in the picturebox has
changed? what event should i catch the chage?

As the developer you should know yourself when you change the image ;-). In
other words: No, there is no such event.
 
Hefried,
As the developer you should know yourself when you change the image ;-).
In other words: No, there is no such event.

Again, please do not answer questions which I ask to an OP, wherefore
probably (not always for sure) the answer is obvious.

Cor
 
Cor Ligthert said:
Again, please do not answer questions which I ask to an OP, wherefore
probably (not always for sure) the answer is obvious.

Huh?!
 
me 2 ;-)Has to do with politness, I am sorry that you did not understand it.

When the OP ask something what is for you strange because the answer is
obvious, than you can give an answer, however you can as well do what I did
and ask what he means with his question, although you know almost for sure
your answer.

When than somebody else give in a (in my opinion kind of rude way) that
answer I am not happy.
In that way the OP will probably never ask a question here again.

I can than write nothing or ask to do it not again the next time.

Clear?

Cor
 
Cor Ligthert said:
When than somebody else give in a (in my opinion kind of rude way) that
answer I am not happy.

My reply was /not/ rude. Period.
 
Herfried,
My reply was /not/ rude. Period

I know it is not meant as that by you, however could be read like that.

The same way as you write that "Period".

Cor
 
I would like to help. Indeed the PictureBox control has no event associated
with the change of an image. But I can see no problem in creating your own
picturebox control, inheriting from the system PictureBox. In your control
you may add your own event capturing an image change. This is only a
suggestion, I have no code,
I'll try it myself.
 
hi, try this one:

Imports System
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System.Drawing
<ToolboxBitmap(GetType(PictureBox))> _
Public Class adxPictureControl
Inherits PictureBox
Private _image As System.Drawing.Image
Event ImageBeforeChanged(ByVal sender As Object, ByVal e As
EventArgsImageChanged)
Event ImageAfterChanged(ByVal sender As Object, ByVal e As
EventArgsImageChanged)

Public Shadows Property Image() As Image
Get
Return _image
End Get
Set(ByVal Value As Image)

If Not Value Is _image Then
If Me.DesignMode Then
MyBase.Image = Value
_image = Value
Else
Dim ea As New EventArgsImageChanged
If Not _image Is Nothing Then
RaiseEvent ImageBeforeChanged(Me, ea)
If ea.Cancel = True Then
Exit Property
End If
End If
MyBase.Image = Value
_image = Value
RaiseEvent ImageAfterChanged(Me, ea)
End If
End If
End Set
End Property

End Class
Public Class EventArgsImageChanged
Inherits EventArgs
Private _cancel As Boolean = False
Public Property Cancel() As Boolean
Get
Return _cancel
End Get
Set(ByVal Value As Boolean)
_cancel = Value
End Set
End Property


End Class
 
Hi,
Here is a Picture box control with two extra events , before image changed
and after image changed...

Imports System
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System.Drawing
<ToolboxBitmap(GetType(PictureBox))> _
Public Class adxPictureControl
Inherits PictureBox
Private _image As System.Drawing.Image
Event ImageBeforeChanged(ByVal sender As Object, ByVal e As
EventArgsImageChanged)
Event ImageAfterChanged(ByVal sender As Object, ByVal e As
EventArgsImageChanged)

Public Shadows Property Image() As Image
Get
Return _image
End Get
Set(ByVal Value As Image)

If Not Value Is _image Then
If Me.DesignMode Then
MyBase.Image = Value
_image = Value
Else
Dim ea As New EventArgsImageChanged
If Not _image Is Nothing Then
RaiseEvent ImageBeforeChanged(Me, ea)
If ea.Cancel = True Then
Exit Property
End If
End If
MyBase.Image = Value
_image = Value
RaiseEvent ImageAfterChanged(Me, ea)
End If
End If
End Set
End Property

End Class
Public Class EventArgsImageChanged
Inherits EventArgs
Private _cancel As Boolean = False
Public Property Cancel() As Boolean
Get
Return _cancel
End Get
Set(ByVal Value As Boolean)
_cancel = Value
End Set
End Property


End Class
 
Here is a control you can use:
Imports System
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System.Drawing
<ToolboxBitmap(GetType(PictureBox))> _
Public Class adxPictureControl
Inherits PictureBox
Private _image As System.Drawing.Image
Event ImageBeforeChanged(ByVal sender As Object, ByVal e As
EventArgsImageChanged)
Event ImageAfterChanged(ByVal sender As Object, ByVal e As
EventArgsImageChanged)
'Avi D. New York, NY 2004
Public Shadows Property Image() As Image
Get
Return _image
End Get
Set(ByVal Value As Image)

If Not Value Is _image Then
If Me.DesignMode Then
MyBase.Image = Value
_image = Value
Else
Dim ea As New EventArgsImageChanged
If Not _image Is Nothing Then
RaiseEvent ImageBeforeChanged(Me, ea)
If ea.Cancel = True Then
Exit Property
End If
End If
MyBase.Image = Value
_image = Value
RaiseEvent ImageAfterChanged(Me, ea)
End If
End If
End Set
End Property

End Class
Public Class EventArgsImageChanged
Inherits EventArgs
Private _cancel As Boolean = False
Public Property Cancel() As Boolean
Get
Return _cancel
End Get
Set(ByVal Value As Boolean)
_cancel = Value
End Set
End Property


End Class
 
AviD,
Event ImageBeforeChanged(ByVal sender As Object, ByVal e As
EventArgsImageChanged)
Event ImageAfterChanged(ByVal sender As Object, ByVal e As
EventArgsImageChanged)

Rather then ImageBeforeChanged & ImageAfterChanged you might consider naming
the events ImageChanging & ImageChanged which is the normal convention for
..NET.

http://msdn.microsoft.com/library/d.../cpgenref/html/cpconEventNamingGuidelines.asp

http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconEventUsageGuidelines.asp
Public Class EventArgsImageChanged
Inherits EventArgs
Private _cancel As Boolean = False
Rather then define a class with a Cancel Property you can simply use
System.ComponentModel.CancelEventArgs or inherit from it.

http://msdn.microsoft.com/library/d...emcomponentmodelcanceleventargsclasstopic.asp
Public Class adxPictureControl
Inherits PictureBox

Public Event ImageChanging As System.ComponentModel.CancelEventHandler
Public Event ImageChanged As System.Event Handler

...
End Class


Hope this helps
Jay
 
Hi Jay
Advice well taken!
AviD.
Jay B. Harlow said:
AviD,

Rather then ImageBeforeChanged & ImageAfterChanged you might consider
naming the events ImageChanging & ImageChanged which is the normal
convention for .NET.

http://msdn.microsoft.com/library/d.../cpgenref/html/cpconEventNamingGuidelines.asp

http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconEventUsageGuidelines.asp

Rather then define a class with a Cancel Property you can simply use
System.ComponentModel.CancelEventArgs or inherit from it.

http://msdn.microsoft.com/library/d...emcomponentmodelcanceleventargsclasstopic.asp


Public Event ImageChanging As System.ComponentModel.CancelEventHandler
Public Event ImageChanged As System.Event Handler

...



Hope this helps
Jay
 
The only solution I can think of, is to Inherit from a PictureBox, and
override (or shadow, for that matter) the Image property. I needed to do
that to make a PictureBox that supported "DBNull" values, and it worked
Ok... Then you can call MyBase.Image to set or get the PictureBox's real
values.
Hope this helps.
VBen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top