problem with picturebox adding pictures from images

crazycheetah
05-08-2002, 08:33 PM
ok, i need to add a picture from a image to a picture box. here is the code i used:
In form with images:

Dim x1 As Integer
Dim y1 As Integer
Dim w1 As Integer
Dim h1 As Integer
Dim x2 As Integer
Dim y2 As Integer
Dim w2 As Integer
Dim h2 As Integer
Dim x3 As Integer
Dim y3 As Integer
Dim w3 As Integer
Dim h3 As Integer

Private Sub Timer1_Timer()
x1 = (Image1.Top * 4)
y1 = (Image1.Left * 4)
w1 = (Image1.Width * 4)
h1 = (Image1.Height * 4)
x2 = (Image2.Top * 4)
y2 = (Image2.Left * 4)
w2 = (Image2.Width * 4)
h2 = (Image2.Height * 4)
x3 = (Image3.Top * 4)
y3 = (Image3.Left * 4)
w3 = (Image3.Width * 4)
h3 = (Image3.Height * 4)
End Sub

In form with picture box:

Private Sub Form_Load()
Picture1.PaintPicture Layer1.Image1.Picture, x1, y1, w1, h1
Picture1.PaintPicture Layer1.Image2.Picture, x2, y2, w2, h2
Picture1.PaintPicture Layer1.Image3.Picture, x3, y3, w3, h3
End Sub


Layer1 is the form in which the images are on. Here is the error I get:

Invalid Property Value

Thanks if you help me at all.

EDIT: Just to let you know I am using these variables, incase these images move at all. I am obviously enlarging them to go into the picturebox, but they only enlarge in the picture box, and remain the same in the images. I hope this is all clear.

The IceMan
05-08-2002, 08:37 PM
In which line are u getting this error ??

crazycheetah
05-08-2002, 08:39 PM
this is the line that is highlighted:


Picture1.PaintPicture Layer1.Image1.Picture, x1, y1, w1, h1

The IceMan
05-08-2002, 08:43 PM
The variables need to be declared as Public ones...
to all forms get values from them...

The IceMan
05-08-2002, 08:44 PM
add a module to your project and declare tha variables there...

same as follow:

Public x1, y1, w1, h1 as integer
Public x2, y2, w2, h2 as integer
Public x3, y3, w3, h3 as integer

crazycheetah
05-08-2002, 08:49 PM
ok, i made the code as follows now:

In Module:

Sub Main()
Public x1 As Integer
Public y1 As Integer
Public w1 As Integer
Public h1 As Integer
Public x2 As Integer
Public y2 As Integer
Public w2 As Integer
Public h2 As Integer
Public x3 As Integer
Public y3 As Integer
Public w3 As Integer
Public h3 As Integer
Load Layer1
Load Form2
Form2.Show
End Sub

Then in the form called Layer1:

Private Sub Timer1_Timer()
x1 = (Image1.Top * 4)
y1 = (Image1.Left * 4)
w1 = (Image1.Width * 4)
h1 = (Image1.Height * 4)
x2 = (Image2.Top * 4)
y2 = (Image2.Left * 4)
w2 = (Image2.Width * 4)
h2 = (Image2.Height * 4)
x3 = (Image3.Top * 4)
y3 = (Image3.Left * 4)
w3 = (Image3.Width * 4)
h3 = (Image3.Height * 4)
End Sub

then in the form with the picture box:

Private Sub Form_Load()
Picture1.PaintPicture Layer1.Image1.Picture, x1, y1, w1, h1
Picture1.PaintPicture Layer1.Image2.Picture, x2, y2, w2, h2
Picture1.PaintPicture Layer1.Image3.Picture, x3, y3, w3, h3
End Sub


however i get the Invalid Property Value error
Im getting extremely confused from this

The IceMan
05-08-2002, 08:51 PM
Don't Declare the variables into te Sub Main !!!

Declare it out...


Public x1 As Integer
Public y1 As Integer
Public w1 As Integer
Public h1 As Integer
Public x2 As Integer
Public y2 As Integer
Public w2 As Integer
Public h2 As Integer
Public x3 As Integer
Public y3 As Integer
Public w3 As Integer
Public h3 As Integer

Sub Main()
Load Layer1
Load Form2
Form2.Show
End Sub



Understood ??

crazycheetah
05-08-2002, 08:52 PM
ok, i did exactly that, and well now it is still giving me the same error???

The IceMan
05-08-2002, 08:57 PM
before the Picture1.PaintPicture thing...

write this code:
msgbox str(x1) & vbcrlf & str(x2) & vbcrlf & str(x3)


what did u got in Message box ???

crazycheetah
05-08-2002, 08:59 PM
3 0's which is what it should be so i'm not suprised that that is what it is

The IceMan
05-08-2002, 09:01 PM
oh...

the x1, x2, x3 are all 0's ???

do the follow:


Private Sub Timer1_Timer()
x1 = (Image1.Top * 4) + 1
y1 = (Image1.Left * 4) + 1
w1 = (Image1.Width * 4)
h1 = (Image1.Height * 4)
x2 = (Image2.Top * 4) + 1
y2 = (Image2.Left * 4) + 1
w2 = (Image2.Width * 4)
h2 = (Image2.Height * 4)
x3 = (Image3.Top * 4) + 1
y3 = (Image3.Left * 4) + 1
w3 = (Image3.Width * 4)
h3 = (Image3.Height * 4)
End Sub

The IceMan
05-08-2002, 09:03 PM
Oh man !!
I'm so stupid !!!


In the Form1...

Put the Picture1.PaintPicture things in Form_Activate event !!!

and i'm sure it'll work !!!:D

crazycheetah
05-08-2002, 09:04 PM
they remain as 0's and i just realized they are not all supposed to be 0. the y axis is but not the x axis.

and um, stupid me i forgot to say that they are in the Form_Load event.

The IceMan
05-08-2002, 09:08 PM
and the X and Y axis things...

I think you should change this one thing to...

the Y axis is the TOP property
and X is the LEFT one...:D

crazycheetah
05-08-2002, 09:10 PM
ok, i am officially confused, but i think i accidentally clicked new thread, so um yeah what i have is there.

The IceMan
05-08-2002, 09:12 PM
can you ZIP this and attach ?

so I can take a look at it ??

crazycheetah
05-08-2002, 09:14 PM
ok, here it is, there is also another form i don't use right now there, however.

The IceMan
05-08-2002, 09:25 PM
I've looked at it ...
and it's working fine now...

But, anyways... I cannot attach anything (don't know why)
so, do u have any other way for me to sending this ??

The IceMan
05-08-2002, 09:36 PM
I'll post forms, One by One...
Overwrite all the codes os then with these...


Form2

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
Unload Me
End If
End Sub

Private Sub Form_Activate() 'PAINT ONLY WHEN FORM HAS BEEN FULLY LOADED AND SHOWN
Picture1.PaintPicture Layer1.Image1.Picture, x1, y1, w1, h1
Picture1.PaintPicture Layer1.Image2.Picture, x2, y2, w2, h2
Picture1.PaintPicture Layer1.Image3.Picture, x3, y3, w3, h3
End Sub

Private Sub Form_Unload(Cancel As Integer)
End
End Sub

Private Sub Picture1_Click()

End Sub

Private Sub Timer1_Timer()
Picture1.Cls
Picture1.PaintPicture Layer1.Image1.Picture, x1, y1, w1, h1
Picture1.PaintPicture Layer1.Image2.Picture, x2, y2, w2, h2
Picture1.PaintPicture Layer1.Image3.Picture, x3, y3, w3, h3
End Sub


Layer1


Private Sub Form_Activate() 'HERE...I'LL ONLY SHOW THE FORM2 WHEN THE POSTIONS HAVE ALREADY BEEN SET...
Timer1_Timer
DoEvents
Form2.Show
End Sub

Private Sub Timer1_Timer()
x1 = (Image1.Left * 4) + 1
y1 = (Image1.Top * 4) + 1
w1 = (Image1.Width * 4)
h1 = (Image1.Height * 4)
x2 = (Image2.Left * 4) + 1
y2 = (Image2.Top * 4) + 1
w2 = (Image2.Width * 4)
h2 = (Image2.Height * 4)
x3 = (Image3.Left * 4) + 1
y3 = (Image3.Top * 4) + 1
w3 = (Image3.Width * 4)
h3 = (Image3.Height * 4)
End Sub



Module

Public x1 As Integer
Public y1 As Integer
Public w1 As Integer
Public h1 As Integer
Public x2 As Integer
Public y2 As Integer
Public w2 As Integer
Public h2 As Integer
Public x3 As Integer
Public y3 As Integer
Public w3 As Integer
Public h3 As Integer

Sub Main() 'SHOW LAYER1 ONLY... SEE THERE WHY...
Layer1.Show
Layer1.Hide
End Sub



Also...
go in Project Properties...
and Set Start Up Form as Sub Main...:D

crazycheetah
05-08-2002, 09:41 PM
well, i had a small problem, cause i was trying to get my e-mail to work, and then I had to change it, so I had to wait and get re-registered pretty much. But the code worked, thanks man!

The IceMan
05-08-2002, 09:45 PM
Oh...

Finally...

I'm so glad to see that finally it's working !!!!:D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum