Print a Cheque with PrintDocument in VB.NET - vb.net

I am using following code in VB.NET 4.0 to print a cheque.
In printpreview dialog, print is shown correctly but when printed actually,
print starts from bottom of cheque.
I want print to start from start point of cheque.
Cheque is inserted in middle of printer tray vertically.
Private print_document As PrintDocument
Private FIRST_TO_PRINT As String = "CHEQUE"
Private fontsize As Integer = 12
Private _ID As Integer = 0
Private CHEQUE_DATE As Date
Private CLIENT_NAME As String
Private CLIENT_NAME_ON_CHEQUE As String
Private AMOUNT As Decimal
Private AMOUNT_IN_WORDS As String
Public Sub New(ID As Integer)
_ID = ID
End Sub
Public Function PreparePrintDocument() As PrintDocument
' Make the PrintDocument object.
print_document = New PrintDocument
print_document.DefaultPageSettings.PaperSize = New PaperSize("Custom", 336, 768)
'print_document.OriginAtMargins = True
'print_document.DefaultPageSettings.Margins.Left = 200
'print_document.DefaultPageSettings.Margins.Right = 10
'print_document.DefaultPageSettings.Margins.Bottom = 10
'print_document.DefaultPageSettings.Margins.Top = 200
AddHandler print_document.BeginPrint, AddressOf Print_BeginPrint
' Install the PrintPage event handler.
AddHandler print_document.PrintPage, AddressOf Print_PrintPage
' Return the object.
Return print_document
End Function
Protected Sub Print_BeginPrint(sender As Object, e As PrintEventArgs)
GetVoucherDetails()
End Sub
Private Sub GetVoucherDetails()
Dim objVOUCHER_BLL As VOUCHER_BLL
Try
objVOUCHER_BLL = New VOUCHER_BLL
Dim temps As VOUCHERDataTable = objVOUCHER_BLL.GetVoucherByID(_ID)
If temps.Count > 0 Then
Dim temp As VOUCHERRow = temps(0)
CHEQUE_DATE = temp.CHEQUE_DATE
CLIENT_NAME = temp.CLIENT_NAME
CLIENT_NAME_ON_CHEQUE = temp.CLIENT_NAME_ON_CHEQUE
AMOUNT = temp.AMOUNT
AMOUNT_IN_WORDS = numToWords.AmtInWord(temp.AMOUNT)
End If
Catch ex As Exception
Finally
objVOUCHER_BLL = Nothing
End Try
End Sub
' Print the next page.
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e _
As System.Drawing.Printing.PrintPageEventArgs)
Dim our_brush As Brush = Brushes.Black
Dim font As New Font("Verdana", fontsize)
If FIRST_TO_PRINT = "CHEQUE" Then
e.PageSettings.PaperSize = New PaperSize("Custom", 336, 768)
e.Graphics.ResetTransform()
e.Graphics.TranslateTransform(306, 580)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(CHEQUE_DATE.ToString("dd MM yyyy"), font, our_brush, New Point(0, 0))
e.Graphics.ResetTransform()
e.Graphics.TranslateTransform(262, 20)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(CLIENT_NAME_ON_CHEQUE, font, our_brush, New Point(70, 0))
e.Graphics.ResetTransform()
e.Graphics.TranslateTransform(232, 140)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(AMOUNT_IN_WORDS.Replace("Rupees ", String.Empty).ToUpper, font, our_brush, New Point(0, 0))
e.Graphics.ResetTransform()
e.Graphics.TranslateTransform(206, 600)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(AMOUNT.ToString("F2") & " /-", font, our_brush, New Point(0, 0))
' e.HasMorePages = True
' e.Graphics.ResetTransform()
' FIRST_TO_PRINT = "VOUCHER"
'Else
' e.PageSettings.PaperSize = New PaperSize("Custom", 612, 792)
' e.Graphics.DrawString("VOUCHER", font, our_brush, New Point(200, 200))
' FIRST_TO_PRINT = "CHEQUE"
e.Graphics.ResetTransform()
e.HasMorePages = False
End If
End Sub

Related

VB.NET Print Large Image on Multiple Pages

i have a problem printing an large image over multiple Pages. I have scanned A4 Documents with 1-x Pages and they put together as one long image. I have to rescale Image to fit in width on A4 and to print with as many pages as on image are. There ist my code, can't achieve this, printing only first page. Any help woud be aprechiated. Thanks! (i'm a beginner...)
Imports System.Drawing.Printing
Imports System.Drawing.Imaging
Imports System.IO
Public Class Form1
Dim Bmp As Bitmap
dim pageNum As Int32 = 0
Private Sub PrintDocument4_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles PrintDocument4.PrintPage
Dim WidthRatio As Double = e.MarginBounds.Width / Bmp.Width
Dim maxpagenum As Int32 = Math.Ceiling(Bmp.Height / e.MarginBounds.Height * WidthRatio)
Debug.WriteLine(maxpagenum)
Debug.WriteLine(e.MarginBounds.Height)
Dim piece As New Bitmap(CInt(e.MarginBounds.Width / WidthRatio), CInt(e.MarginBounds.Height / WidthRatio))
Dim dest_rect As New Rectangle(0, 0, CInt(e.MarginBounds.Width / WidthRatio), CInt(e.MarginBounds.Height / WidthRatio))
Using gr As Graphics = Graphics.FromImage(piece)
Dim source_rect As New Rectangle(0, 0, CInt(e.MarginBounds.Width / WidthRatio), CInt(e.MarginBounds.Height / WidthRatio))
For i As Integer = 1 To maxpagenum
source_rect.X = 0
' Copy the piece of the image.
gr.DrawImage(Bmp, dest_rect, source_rect, _
GraphicsUnit.Pixel)
'piece.Save("Bmp" & i & ".jpg", ImageFormat.Bmp)
e.Graphics.DrawImage(piece, 0, source_rect.Y, CInt(piece.Width * WidthRatio), CInt(piece.Height * WidthRatio))
pageNum += 1
source_rect.Y += CInt(e.MarginBounds.Height / WidthRatio)
If pageNum < maxpagenum Then
e.HasMorePages = True
Else
pageNum = 0
End If
Next
End Using
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
If ListBox1.SelectedItem IsNot Nothing Then
Dim selItem As String = ListBox1.SelectedItem.ToString()
Dim fs1 As System.IO.FileStream
fs1 = New System.IO.FileStream(selItem, IO.FileMode.Open, IO.FileAccess.Read)
Bmp = New Bitmap(System.Drawing.Image.FromStream(fs1))
fs1.Close()
PrintDocument4 = New PrintDocument
With PrintDialog1
.AllowCurrentPage = False
.AllowPrintToFile = False
.AllowSelection = False
.AllowSomePages = False
.Document = PrintDocument4
.PrinterSettings.DefaultPageSettings.Margins.Top = 15
.PrinterSettings.DefaultPageSettings.Margins.Bottom = 15
.PrinterSettings.DefaultPageSettings.Margins.Left = 15
.PrinterSettings.DefaultPageSettings.Margins.Right = 15
End With
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument4.PrinterSettings = PrintDialog1.PrinterSettings
AddHandler PrintDocument4.PrintPage, AddressOf PrintDocument4_PrintPage
PrintDocument4.Print()
End If
End If
End Sub

I've trying to make a simple application in visual basic.NET,

I'm new to Visual Basic.NET and I've been trying to make this simple application. It's a tax calculator.
Two-dimensional arrays are a bit... well not easy for me to grasp yet. So my question is: can you take a look at my code and give me hints on how to solve this issue?
When I run the code in the Labelbox I get a result of 0.00
Public Class PerrytownForm
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
Friend WithEvents IdFwtLabel As System.Windows.Forms.Label
Friend WithEvents FwtLabel As System.Windows.Forms.Label
Friend WithEvents CalculateButton As System.Windows.Forms.Button
Friend WithEvents ExitButton As System.Windows.Forms.Button
Friend WithEvents StatusGroupBox As System.Windows.Forms.GroupBox
Friend WithEvents MarriedRadioButton As System.Windows.Forms.RadioButton
Friend WithEvents SingleRadioButton As System.Windows.Forms.RadioButton
Friend WithEvents IdTaxableLabel As System.Windows.Forms.Label
Friend WithEvents TaxableTextBox As System.Windows.Forms.TextBox
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'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.IdTaxableLabel = New System.Windows.Forms.Label()
Me.StatusGroupBox = New System.Windows.Forms.GroupBox()
Me.MarriedRadioButton = New System.Windows.Forms.RadioButton()
Me.SingleRadioButton = New System.Windows.Forms.RadioButton()
Me.TaxableTextBox = New System.Windows.Forms.TextBox()
Me.IdFwtLabel = New System.Windows.Forms.Label()
Me.FwtLabel = New System.Windows.Forms.Label()
Me.CalculateButton = New System.Windows.Forms.Button()
Me.ExitButton = New System.Windows.Forms.Button()
Me.StatusGroupBox.SuspendLayout()
Me.SuspendLayout()
'
'IdTaxableLabel
'
Me.IdTaxableLabel.AutoSize = True
Me.IdTaxableLabel.Location = New System.Drawing.Point(24, 24)
Me.IdTaxableLabel.Name = "IdTaxableLabel"
Me.IdTaxableLabel.Size = New System.Drawing.Size(99, 16)
Me.IdTaxableLabel.TabIndex = 0
Me.IdTaxableLabel.Text = "&Taxable wages:"
'
'StatusGroupBox
'
Me.StatusGroupBox.Controls.Add(Me.MarriedRadioButton)
Me.StatusGroupBox.Controls.Add(Me.SingleRadioButton)
Me.StatusGroupBox.Location = New System.Drawing.Point(184, 24)
Me.StatusGroupBox.Name = "StatusGroupBox"
Me.StatusGroupBox.Size = New System.Drawing.Size(95, 88)
Me.StatusGroupBox.TabIndex = 2
Me.StatusGroupBox.TabStop = False
Me.StatusGroupBox.Text = "Status"
'
'MarriedRadioButton
'
Me.MarriedRadioButton.Checked = True
Me.MarriedRadioButton.Location = New System.Drawing.Point(8, 21)
Me.MarriedRadioButton.Name = "MarriedRadioButton"
Me.MarriedRadioButton.Size = New System.Drawing.Size(80, 24)
Me.MarriedRadioButton.TabIndex = 0
Me.MarriedRadioButton.TabStop = True
Me.MarriedRadioButton.Text = "&Married"
'
'SingleRadioButton
'
Me.SingleRadioButton.Location = New System.Drawing.Point(8, 50)
Me.SingleRadioButton.Name = "SingleRadioButton"
Me.SingleRadioButton.Size = New System.Drawing.Size(80, 24)
Me.SingleRadioButton.TabIndex = 1
Me.SingleRadioButton.Text = "&Single"
'
'TaxableTextBox
'
Me.TaxableTextBox.Location = New System.Drawing.Point(24, 40)
Me.TaxableTextBox.Name = "TaxableTextBox"
Me.TaxableTextBox.Size = New System.Drawing.Size(136, 23)
Me.TaxableTextBox.TabIndex = 1
'
'IdFwtLabel
'
Me.IdFwtLabel.AutoSize = True
Me.IdFwtLabel.Location = New System.Drawing.Point(24, 80)
Me.IdFwtLabel.Name = "IdFwtLabel"
Me.IdFwtLabel.Size = New System.Drawing.Size(146, 16)
Me.IdFwtLabel.TabIndex = 5
Me.IdFwtLabel.Text = "Federal withholding tax:"
'
'FwtLabel
'
Me.FwtLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.FwtLabel.Location = New System.Drawing.Point(24, 96)
Me.FwtLabel.Name = "FwtLabel"
Me.FwtLabel.Size = New System.Drawing.Size(136, 23)
Me.FwtLabel.TabIndex = 6
Me.FwtLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'CalculateButton
'
Me.CalculateButton.Location = New System.Drawing.Point(184, 120)
Me.CalculateButton.Name = "CalculateButton"
Me.CalculateButton.Size = New System.Drawing.Size(96, 25)
Me.CalculateButton.TabIndex = 3
Me.CalculateButton.Text = "&Calculate Tax"
'
'ExitButton
'
Me.ExitButton.Location = New System.Drawing.Point(184, 152)
Me.ExitButton.Name = "ExitButton"
Me.ExitButton.Size = New System.Drawing.Size(96, 25)
Me.ExitButton.TabIndex = 4
Me.ExitButton.Text = "E&xit"
'
'PerrytownForm
'
Me.AcceptButton = Me.CalculateButton
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 16)
Me.ClientSize = New System.Drawing.Size(312, 205)
Me.Controls.Add(Me.StatusGroupBox)
Me.Controls.Add(Me.ExitButton)
Me.Controls.Add(Me.CalculateButton)
Me.Controls.Add(Me.FwtLabel)
Me.Controls.Add(Me.IdFwtLabel)
Me.Controls.Add(Me.TaxableTextBox)
Me.Controls.Add(Me.IdTaxableLabel)
Me.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "PerrytownForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Perrytown Gift Shop"
Me.StatusGroupBox.ResumeLayout(False)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
'declare form-level arrays
Private msngSingle(,) As Single = {{51, 0, 0, 0},
{552, 0, 0.15, 51},
{1196, 75.15, 0.28, 552},
{2662, 255.47, 0.31, 1196},
{5750, 709.93, 0.36, 2662},
{99999, 1821.61, 0.396, 5750}}
Private msngMarried(,) As Single = {{124, 0, 0, 0},
{960, 0, 0.15, 124},
{2023, 124.4, 0.28, 960},
{3292, 423.04, 0.31, 2023},
{5809, 816.43, 0.36, 3292},
{99999, 1722.55, 0.396, 5809}}
Private Sub ExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub TaxableTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TaxableTextBox.Enter
Me.TaxableTextBox.SelectAll()
End Sub
Private Sub ClearLabels(ByVal sender As Object, ByVal e As System.EventArgs) Handles MarriedRadioButton.Click, SingleRadioButton.Click, TaxableTextBox.TextChanged
Me.FwtLabel.Text = ""
End Sub
Private Sub CalculateButton_Click(sender As Object, e As EventArgs) Handles CalculateButton.Click
Dim sngTaxTable(5, 3) As Single
Dim sngTaxable, sngFwt As Single, intRow As Integer
Dim blnFound As Boolean
'assign taxable wages to a variable
sngTaxable = Val(Me.TaxableTextBox.Text)
'determine appropriate array
If Me.SingleRadioButton.Checked = True Then
sngTaxable = msngSingle
Else
sngTaxable = msngMarried
End If
'search for taxable wages in the first column in the array
Do While intRow < 6 AndAlso blnFound = False
If sngTaxable <= sngTaxTable(intRow, 0) Then
'calculate the fwt
sngFwt = sngTaxTable(intRow, 1) _
+ sngTaxTable(intRow, 2) _
* (sngTaxable - sngTaxTable(intRow, 3))
blnFound = True
Else
intRow = intRow + 1
End If
Loop
'display the fwt
Me.FwtLabel.Text = Format(sngFwt, "currency")
End Sub
End Class
I tried the code for myself and found some mistake: You forgot the letter "T"
If Me.SingleRadioButton.Checked = True Then
sngTaxable = msngSingle
Else
sngTaxable = msngMarried
End If
needs to be
If Me.SingleRadioButton.Checked = True Then
sngTaxTable = msngSingle
Else
sngTaxTable = msngMarried
End If
If I change this, the code will work and give some results, if I try to enter some numbers.
If they are too little or big, the program doesn't do anything. I don't know if this is intentional, but maybe a little error output (MsgBox etc) could be nice.

Unable To Make Front Control Transparent Over PictureBox

I am trying to place a custom user control over the top of a PictureBox control but I cannot seem for the life of me how to set the transparency of the user control so it doesn't chop out the PictureBox image.
My User Control consists of a RectangleShape with text in the middle to create a 'Badge' icon on top of an image (see pictures below). The PictureBox and User Control both sit inside a Panel control and I have set the PictureBox.SendToBack() property and UserControl.BringToFront() property.
What I am left with is this:
My Code looks like this:
Option Explicit On
Option Strict On
Imports Microsoft.VisualBasic.PowerPacks
Public Class BadgeIcon
Inherits UserControl
Private _value As Integer
Private canvas As New ShapeContainer
Private Badge_Icon As New RectangleShape
Private rect As New Rectangle
Private m_BorderColor As Color = Color.White
Private m_FillColor As Color = Color.Red
Private m_BorderThickness As Integer = 2
Private m_BadgeFont As New Font("Segoe UI", 7, FontStyle.Bold)
Private m_BadgeText As String
Private m_TextColor As New SolidBrush(Color.White)
Private m_TextSize As Size
Private m_TextPadding As Integer = 5
Public Property Value() As Integer
Get
Return _value
End Get
Set(value As Integer)
_value = value
m_BadgeText = CStr(_value)
m_TextSize = TextRenderer.MeasureText(m_BadgeText, m_BadgeFont)
rect.Width = m_TextSize.Width + m_TextPadding
rect.Height = m_TextSize.Height + m_TextPadding
Me.Refresh()
End Set
End Property
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = &H20
Return cp
End Get
End Property
Sub New()
' This call is required by the designer.
InitializeComponent()
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
SetStyle(ControlStyles.Opaque, False)
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.UserPaint, True)
Me.BackColor = Color.FromArgb(0, 0, 0, 0)
UpdateStyles()
' Add any initialization after the InitializeComponent() call.
canvas.Parent = Me
Badge_Icon.Parent = canvas
canvas.BackColor = Color.FromArgb(0, 0, 0, 0)
'Create Badge Icon
With Badge_Icon
.BackColor = Color.FromArgb(0, 0, 0, 0)
.BorderColor = m_BorderColor
.BorderWidth = m_BorderThickness
.BorderStyle = Drawing2D.DashStyle.Solid
.CornerRadius = 11
.FillColor = m_FillColor
.FillStyle = FillStyle.Solid
.SelectionColor = Color.Transparent
End With
AddHandler Badge_Icon.Paint, AddressOf BadgeIcon_Paint
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
DrawBadgeIcon(e)
End Sub
Public Sub DrawBadgeIcon(e As PaintEventArgs)
Try
'Alter the size of the icon to fix the text
With Badge_Icon
.Location = New Point(rect.Left + 1, rect.Top + 1)
.Size = New Size(rect.Width, rect.Height - 1)
End With
Catch ex As Exception
ErrorTrap(ex, "cls_NotificationBadgeIcon: DrawBadgeIcon()")
End Try
End Sub
Private Sub BadgeIcon_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim textRect As New Rectangle(2, 2, m_TextSize.Width + m_TextPadding - 1, m_TextSize.Height + m_TextPadding - 2)
'Draw the Text
Dim flags As New StringFormat
flags.Alignment = StringAlignment.Center
flags.LineAlignment = StringAlignment.Center
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
e.Graphics.DrawString(m_BadgeText, m_BadgeFont, m_TextColor, textRect, flags)
End Sub
End Class
Then to add everything to my main form I call the following:
Dim pic As New PictureBox
pic.Image = My.Resources.Notifications
pic.SizeMode = PictureBoxSizeMode.StretchImage
pic.Location = New Point(21, 221)
pic.Size = New Size(42, 29)
pnlLeftMenuBar.Controls.Add(pic)
pic.SendToBack()
Dim Counter_Notify As New BadgeIcon
Counter_Notify.Location = New Point(50, 240)
pnlLeftMenuBar.Controls.Add(Counter_Notify)
Counter_Notify.BringToFront()
And simply use Counter_Notify.Value = 1 to update the counter value.
How can I remove the square rectangle chopping out the background image? Or should I be setting this up an entirely different way? I'm a little new to User Controls.
Any help appreciated. Thanks
Using the paint event you can draw right on the picturebox itself.
Private Sub pb__Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles pb.Paint
Dim bgRect As New Rectangle({x,y,width,height})
Dim textRect As New Rectangle(bgRect.X - {?}, bgRect.Y = {?}, width, height)
e.Graphics.FillEllipse(New SolidBrush(Color.Red), bgRect)
e.Graphics.DrawEllipse(New Pen(Color.White, 10), bgRect)
Using sf As New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center
e.Graphics.DrawString("1", {your font}, {your brush}, textRect, sf)
End Using
End Sub

How to change image in picture box when clicked

I have used the following code in a program that I am designing to book seats. Each picturebox is a seat, and when each picturebox is clicked, the image should change from Seating_No_Person to Seating_With_Person to show that the seat has been selected. I am currently getting a problem with the changing image, as when clicked, none of the pictureboxes swap images. Anyone got any suggestions?
Thanks
Public Class Form1
Public Class Seating
Public SeatRow As Integer = 0
Public SeatColumn As Integer = 0
Public PB As PictureBox = Nothing
Public Occupied As Boolean = False
End Class
Private seatingList As New List(Of Seating)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim xPosition As Integer = -50
Dim yPosition As Integer = -25
For i As Integer = 1 To 5
'Number of rows
For j As Integer = 1 To 10
Dim pb As New PictureBox
With pb
.Name = "PictureBox" & i.ToString & j.ToString
'Name of Picture box i.e. if i = 1 (row 1), j = 3 (column 3), name is PictureBox13
.SizeMode = PictureBoxSizeMode.Zoom
.Size = New Size(60, 60)
'Size of seat is 60 by 60
.Location = New Point(xPosition + (j * 70), yPosition + (i * 70))
'Location of picture box is: -50 + (columnnumber * 70), -25 + (rownumber * 70)
.Image = My.Resources.Seating_No_Person
Me.Controls.Add(pb)
AddHandler pb.Click, AddressOf PictureBox_Click
Dim thisSeating As New Seating
With thisSeating
.SeatRow = i
.SeatColumn = j
.PB = pb
.Occupied = True
End With
seatingList.Add(thisSeating)
End With
Next
Next
End Sub
Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim pb As PictureBox = DirectCast(sender, PictureBox)
Dim seatRowNum As Integer = CInt(pb.Name.Replace("PictureBox", ""))
Dim seatColumnNum As Integer = CInt(pb.Name.Replace("PictureBox", ""))
Dim qry = From seat As Seating In seatingList Where seat.SeatRow = seatRowNum And seat.SeatColumn = SeatColumnNum
If qry.Count = 1 Then
If qry.First.Occupied = True Then
pb.Image = My.Resources.Seating_No_Person
qry.First.Occupied = False
Else
pb.Image = My.Resources.Seating_With_Person
qry.First.Occupied = True
End If
End If
End Sub
End Class
I would suggest setting a breakpoint and debugging to see where you're going wrong. If you just call DirectCast(sender, PictureBox).Image = My.Resources.Seating_With_Person inside Private Sub PictureBox_Click it works, which suggests that there is problem with the logic inside your If block.

Print multiple pages

I'm converting from VB5 and am trying to get the equivalent of printer.NewPage in VB.NET.
My code is given below, but it simply prints the two lines on a single page.
The program prints two pages of calculated results (arrays etc), it is not reading and printing a file.
How do I get a second page?
Private Sub PrintGeneralReport()
Dim PrintPreviewSelected As Boolean = True
'Set the doc to print
Dim pDoc As New PrintDocument
pDoc.PrintController = New StandardPrintController 'turns off the printing page x of y dialog
'Get the printer to use
If Me.PrintDialog1.ShowDialog() = DialogResult.OK Then
pDoc.PrinterSettings.PrinterName = Me.PrintDialog1.PrinterSettings.PrinterName
'pDoc.DefaultPageSettings.Margins = New Margins(75, 50, 50, 50)
pDoc.DefaultPageSettings.Margins = New Margins(40, 10, 10, 10)
pDoc.OriginAtMargins = True
Else
pDoc = Nothing
Exit Sub
End If
' Install the PrintPage event handler.
AddHandler pDoc.PrintPage, AddressOf PrintGenReport
If PrintPreviewSelected Then
''print preview
PrintPreviewDialog1.Document = pDoc
PrintPreviewDialog1.UseAntiAlias = True
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()
Else
'just print
pDoc.Print()
End If
RemoveHandler pDoc.PrintPage, AddressOf PrintGenReport
End Sub
Private Sub PrintGenReport(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim fnt10 As Font = New Font("Courier New", 10, FontStyle.Regular)
e.Graphics.DrawString("Page 1", fnt10, Brushes.Black, 20, 100)
'ROARK1.Print_GeneralReportRK(Me, e)
e.HasMorePages = True
e.Graphics.DrawString("Page 2", fnt10, Brushes.Black, 20, 200)
'ROARK1.Print_MemberActions(e)
e.HasMorePages = False
End Sub
Try this:
Private PageNum As Integer = 1
Private Sub PrintGenReport(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim fnt10 As Font = New Font("Courier New", 10, FontStyle.Regular)
e.Graphics.DrawString("Page " & PageNum.ToString(), fnt10, Brushes.Black, 20, 100 * PageNum)
e.HasMorePages = (PageNum < 2)
PageNum += 1
End Sub
Note the PageNum variable is defined at the class level. You should also add a line to the PrintGeneralReport() method to set it back to 1 at the beginning of each print job.