|
-
December 29th, 2005, 06:34 PM
#1
How can the user insert their picture?
Hello CodeGurus!
On my form there is a PictureBox and a default image in it.
I want the Users insert their picture instead of that default image forever.
Thank you.
Bambii.
-
December 30th, 2005, 05:30 AM
#2
Re: How can the user insert their picture?
The only way to do this is to save the file path of the picture in a text file and load the picture in upon runtime. The best option would be to use a common dialog control to allow the user to select the desired picture then copy that picture to the location of the executable. Then read load the picture in from there everytime the program is run. Yu woul dbe better off using an imagebox as then the picture can be resized.
Code:
picture1.picture=loadpicture("...")
Rich
-
December 30th, 2005, 10:06 AM
#3
Re: How can the user insert their picture?
You can also save the path in the registry.
To search for a picture, use a command button with code
Code:
Private Sub cmdFindPicture_Click()
On Error GoTo ErrHandler
With CommonDialog1
.CancelError = True
.Filter = "JPEG Files|*.jpg|All Files|*.*|"
.FilterIndex = 2
.ShowOpen
End With
Caption = CommonDialog1.Filename
If CommonDialog1.Filename = "" Then Exit Sub
imgExample.Picture = LoadPicture(CommonDialog2.Filename)
Exit Sub
ErrHandler:
End Sub
then add a savebutton
Code:
SaveSetting App.Title, "Colors and Pics", "BackgroundPic", commonDialog1.Filename
when loading the form, use this for setting picture as background
Code:
frmMain.Picture = LoadPicture(GetSetting(App.Title, "Colors and Pics", "BackgroundPic"))
i hope the codes are without errors
-
December 31st, 2005, 11:17 PM
#4
Re: How can the user insert their picture?
i use this for adding a picture to a form
Dim Path$
Dim Filename$
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_DblClick()
If Right(File1.Path, 1) <> "\" Then
label1.Caption = File1.Path & "\" & File1.Filename
Else
label1.Caption = File1.Path & File1.Filename
End If
frmPicture.open.Picture = LoadPicture(label1.Caption)
End Sub
Private Sub Form_Load()
' cd2.Filter = "Image Files (*.*)|*.*"
'Filename$ = cd2.Filename
'txtpictures.Text = Filename$
Recordlen = Len(person)
Filenum = 1
'---------------------------------------------------------
If carryover > 0 Then Currentrecord = carryover Else Currentrecord = 1
'---------------------------------------------------------
Lastrecord = FileLen("info.dat") / Recordlen
If Lastrecord = 0 Then
Lastrecord = 1
End If
ShowCurrentrecord
frmPicture.open.Picture = LoadPicture(txtpictures.Text)
End Sub
Private Sub mnuOpen_Click()
On Error Resume Next
cd2.Filter = "Image Files (*.*)|*.*"
cd2.ShowOpen
Filename$ = cd2.Filename
Image.Picture = LoadPicture(Filename$) 'Loads the image into the form
Image.Refresh
txtpictures.Text = Filename$
frmPicture.open.Picture = LoadPicture(txtpictures.Text)
End Sub
-
December 31st, 2005, 11:29 PM
#5
Re: How can the user insert their picture?
Thank you very much friends. At the moment i kind of busy, because last night i had a new baby boy and his mother had to have c section.
I will check your answers soon and will let you guys know OK?
Thanks again. See you.
Bambii.
-
January 2nd, 2006, 11:07 AM
#6
It's Resolved
Hi Koenbuytaert I just used your code and it was perfect.Ive been making a little program and was just stack there several month.BUt your codes done it in a minute.Im very very happy.It was my very first little but full program. Thank you very much.
I want to ask you one thing what does "save the path in the registry" mean? Can you explain it clearly for me?
I also want to ask Rich2189 about"save the file path of the picture in a text file"How do you make picture into text file?
Also thank you duplincomputers i didnt check your code yet.
Thanks again you guys.
-
January 2nd, 2006, 11:37 AM
#7
Re: How can the user insert their picture?
Hi, glad i could help someone for a change.
To answer your question, it's easy, when u click the savebutton, the path of your picture is written in the registry (wich is like a database file wich contains settings of the programs on your computer, i think).
Search for it on this forum to understand more. I use it to store font-, color- and background settings, remembering sizes of form....
U can look in the registry to understand better, just open the execute line (don't know the exact name)from the windows start menu and type : regedit
U will see a treeview, open the HKEY_CURRENT_USER, Software, VB and VBA Program settings and then the name of your application should be there somewhere. I don't know why it's put under vb and vba program settings, while i am running it compiled, i still have to look at that.
bye
Last edited by koenbuytaert; January 2nd, 2006 at 11:48 AM.
-
January 3rd, 2006, 10:40 AM
#8
Re: It's Resolved
Rich said to save the file path to a text file. So you'd save something like "C:\Documents and Settings\User\My Documents\My Pictures\image.bmp" to file, not the actual image itself. Rich's suggestion is to save an image to the same directory as the EXE itself and when it loads, the program checks for that file and uses it if it finds it.
Code:
Private Sub Form_Load()
Dim sImagePath As String
sImagePath = Replace(App.Path & "\image.bmp", "\\", "\") 'This makes sure you don't get "C:\\image.bmp"
If Dir(sImagePath) <> "" Then 'Make sure the file exists
Picture1.Picture = LoadPicture(sImagePath) 'Load the image
End If
End Sub
Just make sure you save the image after they load it the first time.
And though it is a bit late, congratulations.
-
January 3rd, 2006, 08:46 PM
#9
Re: It's Resolved
Thanks ChaosTheEternal!
I will try your code soon.
See you!
Bambii
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|