Link to home
Start Free TrialLog in
Avatar of stevenlewis
stevenlewis

asked on

Let user change form jpg

Hi all, I've got a form with a jpg as a backround, in VB5 (I know old school) and I want to let the user pick a jpg/bmp/gif and then apply it to the form, but have no clue
Note this is the only form in the app
It's a clock (very simple) and I hope to port it to a screen saver
TIA
Avatar of aelatik
aelatik
Flag of Netherlands image

This will set the background picture

Me.Picture = LoadPicture("C:\yourpic.jpg")
Only thing you have to worry about is to set the picture back to its place when the app reloads. This means saving the path in a configuration file or registry.
OR add imagebox


Option Explicit

Private Sub Form_Load()
Image1.Top = 0
Image1.Left = 0
Image1.Width = Me.ScaleWidth
Image1.Height = Me.ScaleHeight
Image1.Stretch = True
Image1.Picture = LoadPicture("C:\yourpic.jpg")
End Sub

Private Sub Form_Resize()
Image1.Width = Me.ScaleWidth
Image1.Height = Me.ScaleHeight
End Sub
ASKER CERTIFIED SOLUTION
Avatar of aelatik
aelatik
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stevenlewis
stevenlewis

ASKER

I'll give these (and any others that might come along) a whirl tomorrow at work (that's where I'm working on it) and let you know
Steve
I think I don't want to use an image box, as I want everything else on top
How would I let the user choose a file using a command button on a seperate form
I know
Private  Sub Command1_Click()
    formchoose.show
End Sub
this will open the second form
Now on the second form I'll have a command button

Private  Sub Command1_Click()
 On Error GoTo DialogError
    With CommonDialog1
        .CancelError = True
        .InitDir = "C:\" On Error GoTo DialogError
    With CommonDialog1
        .CancelError = True
        .InitDir = "C:\"
   With CommonDialog1
        .Filter = "Pictures (*.bmp;*.jpg;*.gif)"
        .ShowOpen
        If .FileName <> "" Then Me.Picture = LoadPicture(.FileName)
    End With

End Sub

Now how would I pass the file to the original form (form1)?
You can use global variable

ie create a new module and add

Public filename as string

in form2 just set the value


>>I think I don't want to use an image box, as I want everything else on top
imagebox is always at the bottom. Everything should go to the top of imagebox
Well, I've had some sucess loading the picture to form 2
by combining the two

Private Sub Form_Load()
Image1.Top = 0
Image1.Left = 0
Image1.Width = Me.ScaleWidth
Image1.Height = Me.ScaleHeight
Image1.Stretch = True
End Sub
and then
Privae Sub Command1_Click
   With CommonDialog1
        .Filter = "Pictures (*.bmp;*.jpg;*.gif)"
        .ShowOpen
        If .FileName <> "" Then Me.Picture = LoadPicture(.FileName)
    End With
   Image1.Picture = Me.Picture
  PicFilename=Image1.picture
End Sub

and I've put
Public PicFilename as String
in my module
but when I try and call it from form1 I get an error

PS, Everyone will be well rewarded for their help :~)
Change : PicFilename=.Filename

And from form1 one : form1.picture = loadpicture(PicFilename)
OK, when I put in my Module
PicFilename=.Filename
I get "Invalid Outside Procedure"
and if I put .filename as string
I get "Expected Expression
and if I put
Public PicFilename = .Filename
I get "Expected end of statement"
>>PicFilename=.Filename

should be PicFilename=yourformname.CommonDialog1.Filename


>> Public PicFilename = .Filename

You can not assign the value like that

try

Public PicFilename as string

in your routine somewhere

PicFilename=yourformname.CommonDialog1.Filename

Cool, It works!
Will post another question for EDDYKT
To award points here
I will also be posting another on how to upcdate form1 dynamically (with out the user having to click a button)
Thanks a million both of you!