• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 645
  • Last Modified:

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
0
stevenlewis
Asked:
stevenlewis
  • 4
  • 4
  • 3
1 Solution
 
aelatikCommented:
This will set the background picture

Me.Picture = LoadPicture("C:\yourpic.jpg")
0
 
aelatikCommented:
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.
0
 
EDDYKTCommented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
aelatikCommented:
You can use the commondialog to load your pictures, just put the Microsoft Common Dialog Control on your form.

Private Sub Form_Load()
    With CommonDialog1
        .Filter = "Pictures (*.bmp;*.jpg;*.gif)"
        .ShowOpen
        If .FileName <> "" Then Me.Picture = LoadPicture(.FileName)
    End With
End Sub
0
 
stevenlewisAuthor Commented:
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)?
0
 
EDDYKTCommented:
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
0
 
stevenlewisAuthor Commented:
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 :~)
0
 
aelatikCommented:
Change : PicFilename=.Filename

And from form1 one : form1.picture = loadpicture(PicFilename)
0
 
stevenlewisAuthor Commented:
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"
0
 
EDDYKTCommented:
>>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

0
 
stevenlewisAuthor Commented:
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!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now