• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

Picture Viewer

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
planner1234
Asked:
planner1234
  • 2
  • 2
1 Solution
 
kriyengCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
planner1234Author Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Just substitute the Image control name for the PictureBox name:

    Image1.Picture = LoadPicture("c:\someImage.bmp")
0
 
kriyengCommented:
hi planner!

thx for points!

yes, the usage is quite similar than picture control.

bye.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now