JayBeeOH

Load Picture Box Demo

Mar 29th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.61 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2016. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   Load Picture Box Demo
  13. '
  14. ' Author:         Joseph L. Bolen
  15. ' Date Created:   29 MAR 2016
  16. '
  17. ' Description:    Demo to show how to load a picture box control from either
  18. '                 My.Resources or a file.
  19. '
  20. '                 Documentation is at:
  21. '                   App's screen image is at: http://imgur.com/DjLntjp
  22. '                   App's Visual Basic .NET code is at http://pastebin.com/PTZY6NFa
  23. '                   Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
  24. '
  25. '-------------------------------------------------------------------------------------------
  26.  
  27. Option Strict On
  28.  
  29. Public Class MainForm
  30.  
  31.     ' Toggle image depending on which gender button is checked.
  32.     Private Sub GenderButtons_CheckedChanged(sender As Object, e As EventArgs) _
  33.         Handles MaleRadioButton.CheckedChanged, FemaleRadioButton.CheckedChanged
  34.  
  35.         If MaleRadioButton.Checked Then
  36.             DisplayImage("MaleSihouette")
  37.         Else
  38.             DisplayImage("FemaleSihouette")
  39.         End If
  40.  
  41.     End Sub
  42.  
  43.     ' Display profile sihouette in picture box.
  44.     Private Sub DisplayImage(ByVal myImage As String)
  45.  
  46.         ' Retrieve object from resources and cast into an Image object.
  47.         ProfilePictureBox.Image = CType(My.Resources.ResourceManager.GetObject(myImage), Image)
  48.  
  49.     End Sub
  50.  
  51.     ' Use the OpenFileDialog component to get an image.
  52.     Private Sub GetImageButton_Click(sender As Object, e As EventArgs) _
  53.         Handles GetImageButton.Click
  54.  
  55.         Dim ofd As New OpenFileDialog
  56.         ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyPictures
  57.         ofd.Filter = "Image Files(*.PNG;*.JPG;*.GIF*;.BMP;)|*.PNG;*.JPG;*.GIF*;.BMP;|All files (*.*)|*.*"
  58.         If ofd.ShowDialog() = DialogResult.OK Then
  59.             ProfilePictureBox.Load(ofd.FileName)
  60.         End If
  61.  
  62.     End Sub
  63. End Class
Advertisement
Add Comment
Please, Sign In to add comment