Solved

Let user change form jpg

Posted on 2003-11-13
11
628 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
  • 4
  • 4
  • 3
11 Comments
 
LVL 14

Expert Comment

by:aelatik
Comment Utility
This will set the background picture

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

Expert Comment

by:aelatik
Comment Utility
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
Comment Utility
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
 
LVL 14

Accepted Solution

by:
aelatik earned 500 total points
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
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
Comment Utility
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
Comment Utility
Change : PicFilename=.Filename

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

Author Comment

by:stevenlewis
Comment Utility
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
Comment Utility
>>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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now