Example : How to set Default image in Picture Box on load event.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  PictureBox1.Image = My.Resources.imagename    '(image extension name not required only image name).
  PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub

'NB: First,Store the pictures in your system resource folder of vb net.
  [Path - Open your VB application/project - solution explorer - My project - Resources - select 
   'Images' option from 'Strings' menu of the resource window menu list - 'Paste' the pictures 
   in this images window.]
Example : How to set Normal border line (black) in a Picture box.
 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PictureBox1.BorderStyle = BorderStyle.FixedSingle   '-- OR --.
        PictureBox1.BorderStyle = BorderStyle.Fixed3D
 End Sub
Example : How to set Color border line in a Picture box.
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint

    ControlPaint.DrawBorder(e.Graphics, PictureBox1.ClientRectangle, Color.Green, 
        ButtonBorderStyle.Solid)
End Sub
Example : How to set images in stretch/full mode in a Picture box.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Example : How to browse/change images (with stretch mode, color border line) in a Picture   box.
Public Class Form1    
    
    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
        ' Color Border line of Picture Box Code
        ControlPaint.DrawBorder(e.Graphics, PictureBox1.ClientRectangle, Color.Green, 
           ButtonBorderStyle.Solid)
    End Sub
    --------------------------------------------------------------
    Private Sub Button1Browse_Click(sender As Object, e As EventArgs) Handles Button1Browse.Click
        ' Image Browse Code
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then           
                PictureBox1.ImageLocation = OpenFileDialog1.FileName
        End If
    End Sub

End Class

NB: First of all, open your design window/page and then double click on 'OpenFileDialog' tool from 
    'ToolBox' list.
Example : How to browse/change images (with stretch mode, color border line, with                                default image set, without image path) in a Picture box.
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Default Image set with stretch mode Code
        PictureBox1.Image = My.Resources.image1
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub
    --------------------------------------------------------------
    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
        ' Color Border line of Picture Box Code
        ControlPaint.DrawBorder(e.Graphics, PictureBox1.ClientRectangle, Color.Green, 
           ButtonBorderStyle.Solid)
    End Sub
    --------------------------------------------------------------
    Private Sub Button1Browse_Click(sender As Object, e As EventArgs) Handles Button1Browse.Click
        ' Image Browse Code
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then           
                PictureBox1.ImageLocation = OpenFileDialog1.FileName
        End If
    End Sub

End Class

NB: First of all, open your design window/page and then double click on 'OpenFileDialog' tool from 
    'ToolBox' list.
Example : How to browse/change images (with stretch mode, color border line,Image path                    details with default image set) in a Picture box.
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Default Image set with stretch mode Code
        PictureBox1.Image = My.Resources.image1
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub
    --------------------------------------------------------------
    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
        ' Color Border line of Picture Box Code
        ControlPaint.DrawBorder(e.Graphics, PictureBox1.ClientRectangle, Color.Green, 
           ButtonBorderStyle.Solid)
    End Sub
    --------------------------------------------------------------
    Private Sub Button1Browse_Click(sender As Object, e As EventArgs) Handles Button1Browse.Click
        ' Image Browse Code
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextBox2.Text = OpenFileDialog1.FileName
            PictureBox1.ImageLocation = TextBox2.Text
        End If
    End Sub

End Class

NB: First of all, open your design window/page and create a text box as name TextBox1 and then double 
    click on 'OpenFileDialog' tool from 'ToolBox' collection list.

Example : How to browse/change images with limited image resolution (with stretch mode,                      color border line,Image path details with default image set) in a Picture box.
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Default Image Code
        PictureBox1.Image = My.Resources.image1
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub
'-------------------------------------------------------------------------------------------------
    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
        ' Color Border line of Picture Box Code
        ControlPaint.DrawBorder(e.Graphics, PictureBox1.ClientRectangle, Color.Green, 
           ButtonBorderStyle.Solid)
    End Sub
'-------------------------------------------------------------------------------------------------
    Private Sub Button1Browse_Click(sender As Object, e As EventArgs) Handles Button1Browse.Click
        ' Image Browse Code with limited height & width (Image Resolution)
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            If Image.FromFile(OpenFileDialog1.FileName).Size.Width > 1700 And 
                   Image.FromFile(OpenFileDialog1.FileName).Size.Height > 1300 Then
                MsgBox("Size Exceeded than 1700X1300,Change it")
                Exit Sub
            Else
                TextBox2.Text = OpenFileDialog1.FileName
                PictureBox1.ImageLocation = TextBox2.Text
            End If
        End If
    End Sub
End Class

[For More further details click this link]

Loading

Categories: VB .Net Codes

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.