Printing a pictureBox

I have created an application that searches and finds drawings from an access databse but on one form you can open a drawing (tif file - from a network share) and view it in the picturebox ok but when i try to print it i cant how can i get the picturebox to print bear in mind the images change

i have all the buttons and print document items there help.

Ps: im new to vb.net 2003 so please try not to baffle me with too much code

Check out the code below.


Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

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.

Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter

Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand

Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection

Friend WithEvents DataSet11 As WindowsApplication2.DataSet1

Friend WithEvents Button2 As System.Windows.Forms.Button

Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog

Friend WithEvents Button3 As System.Windows.Forms.Button

Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument

Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents Label2 As System.Windows.Forms.Label

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader

Me.ComboBox1 = New System.Windows.Forms.ComboBox

Me.DataSet11 = New WindowsApplication2.DataSet1

Me.Button1 = New System.Windows.Forms.Button

Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter

Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand

Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection

Me.Button2 = New System.Windows.Forms.Button

Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog

Me.Button3 = New System.Windows.Forms.Button

Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument

Me.PrintDialog1 = New System.Windows.Forms.PrintDialog

Me.PictureBox1 = New System.Windows.Forms.PictureBox

Me.Label1 = New System.Windows.Forms.Label

Me.Label2 = New System.Windows.Forms.Label

Me.TextBox1 = New System.Windows.Forms.TextBox

CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'ComboBox1

'

Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("SelectedItem", Me.DataSet11, "Drawing Register.Field2"))

Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.DataSet11, "Drawing Register.Field1"))

Me.ComboBox1.DataSource = Me.DataSet11.Drawing_Register

Me.ComboBox1.DisplayMember = "Field2"

Me.ComboBox1.Location = New System.Drawing.Point(160, 32)

Me.ComboBox1.Name = "ComboBox1"

Me.ComboBox1.Size = New System.Drawing.Size(121, 21)

Me.ComboBox1.TabIndex = 1

Me.ComboBox1.ValueMember = "Field1"

'

'DataSet11

'

Me.DataSet11.DataSetName = "DataSet1"

Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-GB")

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(696, 536)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 2

Me.Button1.Text = "&Cancel"

'

'OleDbDataAdapter1

'

Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1

Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Drawing Register", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Field1", "Field1"), New System.Data.Common.DataColumnMapping("Field2", "Field2")})})

'

'OleDbSelectCommand1

'

Me.OleDbSelectCommand1.CommandText = "SELECT Field1, Field2 FROM [Drawing Register] ORDER BY Field1"

Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1

'

'OleDbConnection1

'

Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _

"ocking Mode=1;Data Source=""K:\Drawing\SQL_DRAW_DRAWINGS.mdb"";Jet OLEDB:Engine Ty" & _

"pe=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP" & _

"=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet" & _

" OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:D" & _

"on't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False" & _

";User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"

'

'Button2

'

Me.Button2.Location = New System.Drawing.Point(520, 536)

Me.Button2.Name = "Button2"

Me.Button2.TabIndex = 4

Me.Button2.Text = "&Open"

'

'OpenFileDialog1

'

Me.OpenFileDialog1.InitialDirectory = CType(configurationAppSettings.GetValue("OpenFileDialog1.InitialDirectory", GetType(System.String)), String)

'

'Button3

'

Me.Button3.Location = New System.Drawing.Point(608, 536)

Me.Button3.Name = "Button3"

Me.Button3.TabIndex = 7

Me.Button3.Text = "&Print"

'

'PrintDocument1

'

Me.PrintDocument1.DocumentName = "Drawing"

'

'PrintDialog1

'

Me.PrintDialog1.AllowSelection = True

Me.PrintDialog1.Document = Me.PrintDocument1

'

'PictureBox1

'

Me.PictureBox1.DataBindings.Add(New System.Windows.Forms.Binding("Image", Me.DataSet11, "Drawing Register.Field1"))

Me.PictureBox1.Location = New System.Drawing.Point(32, 112)

Me.PictureBox1.Name = "PictureBox1"

Me.PictureBox1.Size = New System.Drawing.Size(736, 400)

Me.PictureBox1.TabIndex = 10

Me.PictureBox1.TabStop = False

'

'Label1

'

Me.Label1.Location = New System.Drawing.Point(24, 32)

Me.Label1.Name = "Label1"

Me.Label1.TabIndex = 11

Me.Label1.Text = "Drawing Number:"

'

'Label2

'

Me.Label2.Location = New System.Drawing.Point(24, 72)

Me.Label2.Name = "Label2"

Me.Label2.TabIndex = 12

Me.Label2.Text = "Image Number:"

'

'TextBox1

'

Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DataSet11, "Drawing Register.Field1"))

Me.TextBox1.Location = New System.Drawing.Point(160, 72)

Me.TextBox1.Name = "TextBox1"

Me.TextBox1.ReadOnly = True

Me.TextBox1.TabIndex = 13

Me.TextBox1.Text = "TextBox1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(792, 573)

Me.Controls.Add(Me.TextBox1)

Me.Controls.Add(Me.Label2)

Me.Controls.Add(Me.Label1)

Me.Controls.Add(Me.PictureBox1)

Me.Controls.Add(Me.Button3)

Me.Controls.Add(Me.Button2)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.ComboBox1)

Me.Name = "Form1"

Me.Text = "Drawing Search"

CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

OleDbDataAdapter1.Fill(DataSet11)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.Close()

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

TextBox1.Text = " " & ComboBox1.SelectedValue

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim MyImage As Bitmap

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

MyImage = New Bitmap(OpenFileDialog1.OpenFile())

PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

PictureBox1.Image = CType(MyImage, Image)

End If

 

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

End Sub

Private Sub PrintPreviewDialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

End Sub

Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

End Sub

End Class




Answer this question

Printing a pictureBox

  • Printing a pictureBox