Draw on PictureBox border : PictureBox « GUI « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » GUI » PictureBox 
14.28.8.Draw on PictureBox border
Draw on PictureBox border
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class DrawOnPictureBorder
   public Shared Sub Main
        Application.Run(New frmViewer)
   End Sub
End Class

Public Class frmViewer

    Private Sub btnSelectPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnSelectPicture.Click
        picShowPicture.Image = Image.FromFile("yourfile.jpg")
    End Sub

    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnQuit.Click
        Me.Close()
    End Sub

    Private Sub btnDrawBorder_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnDrawBorder.Click
        Dim objGraphics As Graphics

        objGraphics = Me.CreateGraphics
        objGraphics.Clear(SystemColors.Control)
        objGraphics.DrawRectangle(Pens.Red, _
                picShowPicture.Left - 1, picShowPicture.Top - 1, _
                picShowPicture.Width + 1, picShowPicture.Height + 1)
        objGraphics.Dispose()

    End Sub
End Class

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmViewer
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.btnSelectPicture = New System.Windows.Forms.Button
        Me.btnQuit = New System.Windows.Forms.Button
        Me.picShowPicture = New System.Windows.Forms.PictureBox
        Me.ofdSelectPicture = New System.Windows.Forms.OpenFileDialog
        Me.btnDrawBorder = New System.Windows.Forms.Button
        CType(Me.picShowPicture, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSelectPicture
        '
        Me.btnSelectPicture.Location = New System.Drawing.Point(30110)
        Me.btnSelectPicture.Name = "btnSelectPicture"
        Me.btnSelectPicture.Size = New System.Drawing.Size(8523)
        Me.btnSelectPicture.TabIndex = 0
        Me.btnSelectPicture.Text = "Select Picture"
        Me.btnSelectPicture.UseVisualStyleBackColor = True
        '
        'btnQuit
        '
        Me.btnQuit.Location = New System.Drawing.Point(30140)
        Me.btnQuit.Name = "btnQuit"
        Me.btnQuit.Size = New System.Drawing.Size(8523)
        Me.btnQuit.TabIndex = 1
        Me.btnQuit.Text = "Quit"
        Me.btnQuit.UseVisualStyleBackColor = True
        '
        'picShowPicture
        '
        Me.picShowPicture.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picShowPicture.Location = New System.Drawing.Point(88)
        Me.picShowPicture.Name = "picShowPicture"
        Me.picShowPicture.Size = New System.Drawing.Size(282275)
        Me.picShowPicture.TabIndex = 2
        Me.picShowPicture.TabStop = False
        '
        'ofdSelectPicture
        '
        Me.ofdSelectPicture.Filter = "Windows Bitmaps|*.BMP|JPEG Files|*.JPG"
        Me.ofdSelectPicture.Title = "Select Picture"
        '
        'btnDrawBorder
        '
        Me.btnDrawBorder.Location = New System.Drawing.Point(30169)
        Me.btnDrawBorder.Name = "btnDrawBorder"
        Me.btnDrawBorder.Size = New System.Drawing.Size(8523)
        Me.btnDrawBorder.TabIndex = 5
        Me.btnDrawBorder.Text = "Draw Border"
        Me.btnDrawBorder.UseVisualStyleBackColor = True
        '
        'frmViewer
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(392291)
        Me.Controls.Add(Me.btnDrawBorder)
        Me.Controls.Add(Me.picShowPicture)
        Me.Controls.Add(Me.btnQuit)
        Me.Controls.Add(Me.btnSelectPicture)
        Me.Name = "frmViewer"
        Me.Text = "Picture Viewer"
        CType(Me.picShowPicture, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents btnSelectPicture As System.Windows.Forms.Button
    Friend WithEvents btnQuit As System.Windows.Forms.Button
    Friend WithEvents picShowPicture As System.Windows.Forms.PictureBox
    Friend WithEvents ofdSelectPicture As System.Windows.Forms.OpenFileDialog
    Friend WithEvents btnEnlarge As System.Windows.Forms.Button
    Friend WithEvents btnShrink As System.Windows.Forms.Button
    Friend WithEvents btnDrawBorder As System.Windows.Forms.Button

End Class
14.28.PictureBox
14.28.1.PictureBox: StretchImage, CenterImagePictureBox: StretchImage, CenterImage
14.28.2.PictureBox: Save an ImagePictureBox: Save an Image
14.28.3.Load image to PictureBoxLoad image to PictureBox
14.28.4.Using a PictureBox to display imagesUsing a PictureBox to display images
14.28.5.Draw on a PictureBoxDraw on a PictureBox
14.28.6.PictureBox Mouse down event
14.28.7.Get Graphics from PictureBoxGet Graphics from PictureBox
14.28.8.Draw on PictureBox borderDraw on PictureBox border
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.