Mega Code Archive

 
Categories / VB.Net Tutorial / GUI
 

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.EventArgs) Handles btnSelectPicture.Click         picShowPicture.Image = Image.FromFile("yourfile.jpg")     End Sub     Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click         Me.Close()     End Sub     Private Sub btnDrawBorder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 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(301, 10)         Me.btnSelectPicture.Name = "btnSelectPicture"         Me.btnSelectPicture.Size = New System.Drawing.Size(85, 23)         Me.btnSelectPicture.TabIndex = 0         Me.btnSelectPicture.Text = "Select Picture"         Me.btnSelectPicture.UseVisualStyleBackColor = True         '         'btnQuit         '         Me.btnQuit.Location = New System.Drawing.Point(301, 40)         Me.btnQuit.Name = "btnQuit"         Me.btnQuit.Size = New System.Drawing.Size(85, 23)         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(8, 8)         Me.picShowPicture.Name = "picShowPicture"         Me.picShowPicture.Size = New System.Drawing.Size(282, 275)         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(301, 69)         Me.btnDrawBorder.Name = "btnDrawBorder"         Me.btnDrawBorder.Size = New System.Drawing.Size(85, 23)         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(392, 291)         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