Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Let user change form jpg

Posted on 2003-11-13
11
Medium Priority
?
642 Views
Last Modified: 2010-05-01
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
Comment
Question by:stevenlewis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 9741344
This will set the background picture

Me.Picture = LoadPicture("C:\yourpic.jpg")
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9741349
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9741377
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Accepted Solution

by:
aelatik earned 2000 total points
ID: 9741399
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
 
LVL 41

Author Comment

by:stevenlewis
ID: 9743619
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9743867
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
 
LVL 41

Author Comment

by:stevenlewis
ID: 9745390
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
 
LVL 14

Expert Comment

by:aelatik
ID: 9745498
Change : PicFilename=.Filename

And from form1 one : form1.picture = loadpicture(PicFilename)
0
 
LVL 41

Author Comment

by:stevenlewis
ID: 9747123
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9747318
>>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
 
LVL 41

Author Comment

by:stevenlewis
ID: 9749412
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question