From: K on
how can I make below vb code work. I am getting error syaing "Operator
'=' is not defined for types 'System.Drawing.Image' and
'System.Drawing.Bitmap' ". Please can any friend can help me on this.
I am using Visual basic 2008 and trying to create image change in
picture box control with timer.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If PictureBox1.Image = My.Resources.oneimg Then
PictureBox1.Image = My.Resources.twoimg
ElseIf PictureBox1.Image = My.Resources.twoimg Then
PictureBox1.Image = My.Resources.threeimg
ElseIf PictureBox1.Image = My.Resources.threeimg Then
PictureBox1.Image = My.Resources.fourimg
ElseIf PictureBox1.Image = My.Resources.fourimg Then
PictureBox1.Image = My.Resources.oneimg
End If

End Sub
From: Onur Güzel on
On Jun 15, 12:25 pm, K <kamranr1...(a)yahoo.co.uk> wrote:
> how can I make below vb code work. I am getting error syaing "Operator
> '=' is not defined for types 'System.Drawing.Image' and
> 'System.Drawing.Bitmap' ". Please can any friend can help me on this.
> I am using Visual basic 2008 and trying to create image change in
> picture box control with timer.
>
> Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Timer1.Tick
>         If PictureBox1.Image = My.Resources.oneimg Then
>             PictureBox1.Image = My.Resources.twoimg
>         ElseIf PictureBox1.Image = My.Resources.twoimg Then
>             PictureBox1.Image = My.Resources.threeimg
>         ElseIf PictureBox1.Image = My.Resources.threeimg Then
>             PictureBox1.Image = My.Resources.fourimg
>         ElseIf PictureBox1.Image = My.Resources.fourimg Then
>             PictureBox1.Image = My.Resources.oneimg
>         End If
>
>     End Sub

You're trying to evaluate equality of two pictures which cannot be
done using "=" operator. It requires image comparing algorithms which
some samples available on the net, though, most of are comparing
colors rather than objects which i'm quite interested in.

However, you may have wanted to compare image path(s) or anything
else? Describe your aim.

Onur Güzel
From: Phill W. on
On 15/06/2010 10:25, K wrote:

> how can I make below vb code work. I am getting error syaing "Operator
> '=' is not defined for types 'System.Drawing.Image' and
> 'System.Drawing.Bitmap' ". Please can any friend can help me on this.

Short answer:
Use "Is" to compare object references:

If PictureBox1.Image Is My.Resources.oneimg Then
. . .

Better Answer:
[In this case, anyway] Don't compare object references!

It's far, /far/ clearer to use a counter that you increment on each
Timer tick and load the relevant resource, something like:

Private m_images as Image() = Nothing

Private Sub Form_Load( ...

' you might need an "=" in here somewhere:
m_images = new Image() { My.Resources.oneimg _
, My.Resources.twoimg _
, My.Resources.threeimg _
, My.Resources.fourimg _
}

End Sub

Private m_image as Integer = 0

Private Sub Timer1_Tick( ...
m_image = m_image + 1
if ( m_image >= m_images.Length ) then
m_image = 0
end if
PictureBox1.Image = images( m_image )
End Sub

HTH,
Phill W.
 | 
Pages: 1
Prev: WPF media element marker
Next: VS2010