?
Solved

Picture Viewer

Posted on 2006-04-10
5
Medium Priority
?
353 Views
Last Modified: 2010-05-01
Hi
I am just learning VB and I am following tutorials, I have just created a picture viewer using the code as below

The Code

Private Sub Form_Load()
Left = (Screen.Width - Width) \ 2
Top = (Screen.Height - Height) \ 2

Combo1.Text = "All graphic files"
Combo1.AddItem "All graphic files"
Combo1.AddItem "All files"

End Sub
 

Private Sub Combo1_Change()
If ListIndex = 0 Then
File1.Pattern = ("*.bmp;*.wmf;*.jpg;*.gif")
Else
Fiel1.Pattern = ("*.*")
End If

End Sub


Private Sub Dir1_Change()

File1.Path = Dir1.Path
File1.Pattern = ("*.bmp;*.wmf;*.jpg;*.gif")


End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Exit_Click()
End
End Sub

Private Sub File1_Click()
If Combo1.ListIndex = 0 Then
File1.Pattern = ("*.bmp;*.wmf;*.jpg;*.gif")
Else
File1.Pattern = ("*.*")
End If

If Right(File1.Path, 1) <> "\" Then
filenam = File1.Path + "\" + File1.FileName
Else
filenam = File1.Path + File1.FileName
End If
Text1.Text = filenam

End Sub


Private Sub play_Click()
MMPlayer.FileName = Text1.Text

End Sub



Private Sub show_Click()
If Right(File1.Path, 1) <> "\" Then

filenam = File1.Path + "\" + File1.FileName
Else
filenam = File1.Path + File1.FileName
End If

picture1.Picture = LoadPicture(filenam)
End Sub


The program works but the picture files are to big for my picture box is there any thing I can do to make the images fit inside my picture box.
Regards
Planner
0
Comment
Question by:planner1234
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
kriyeng earned 375 total points
ID: 16417138
hi planner!

You should use image control and not picture control.
In image control you have the stretch option to fit the image in your image control (true=fit image, false=not fit). You have other properties like constrain proportions or not.

The usage is similar than picture box.

bye!
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16417311
If you want to maintain the aspect ratio then load the picture into a stdpicture object and then use the PictureBoxes PaintPicture() method:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20060075.html
0
 

Author Comment

by:planner1234
ID: 16417314
Hi kriyeng
I thought this that would be a solution to the problem I was having, but do I need to alter my code to reflect using an image box instead of a picture box.

probably alter the line that is
picture1.Picture = LoadPicture(filename) maybe ?
Regards
Planner

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16418186
Just substitute the Image control name for the PictureBox name:

    Image1.Picture = LoadPicture("c:\someImage.bmp")
0
 
LVL 2

Expert Comment

by:kriyeng
ID: 16426964
hi planner!

thx for points!

yes, the usage is quite similar than picture control.

bye.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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

850 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