Solved

Let user change form jpg

Posted on 2003-11-13
11
633 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 14

Accepted Solution

by:
aelatik earned 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 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