clockwork3orange
Member
- Joined
- Oct 20, 2006
- Messages
- 21
- Programming Experience
- Beginner
I'm new to VB.NET and I'm not the best programmer so please don’t be too hard on me. The following is the code which is declared in the Public Class. Private Sub PrintMe_PrintPage is basically what is called when I want to print something in VB.NET. What I would like to do is move this code to the module where some other code is at. I have an idea of what needs to be done base on how the other code is being called but I 'm still lost. Private Sub PrintMe_PrintPage is called when the users clicks the print button.
VB.NET:
Public Class frmBarCode
Inherits System.Windows.Forms.Form
Private Sub PrintMe_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintMe.PrintPage
Dim MyGraphicsPage As Graphics = e.Graphics
MyGraphicsPage.PageUnit = GraphicsUnit.Pixel
'Dim myPen As New System.Drawing.Pen(Color.Black, 0.01)
'MyGraphicsPage.DrawLine(myPen, Convert.ToSingle(txtXS.Text), Convert.ToSingle(txtYS.Text), Convert.ToSingle(txtXE.Text), Convert.ToSingle(txtYE.Text))
'MyGraphicsPage.DrawImage(PictureBox1.Image)
'MyGraphicsPage.DrawImage(Me.PictureBox1.Image, 1, 1)
'start of modification
Dim strEANCode As String
'Dim objPicBox As PictureBox
Dim sngX1 As Single '= (-1)
Dim sngY1 As Single '= (-1)
Dim sngX2 As Single '= (-1)
Dim sngY2 As Single '= (-1)
Dim FontForText As Font = Nothing
Dim K As Single
Dim sngPosX As Single
Dim sngPosY As Single
Dim sngScaleX As Single
Dim strEANBin As String
Dim strFormat As New StringFormat()
sngY2 = txtY2.Text
sngX2 = txtX2.Text
sngY1 = txtY1.Text
sngX1 = txtX1.Text
'objPicBox = Me.PictureBox1
strEANCode = Me.txtEAN.Text
'*
'* Convert the code on its binary representation
'*
strEANBin = EAN2Bin(strEANCode)
'*
'* Define the font to be printed
'*
If (FontForText Is Nothing) Then
FontForText = New Font("Courier New", 8)
End If
'*
'* Defines the boundaries to the barcode
'*
' If sngX1 = (-1) Then sngX1 = 0
'If sngY1 = (-1) Then sngY1 = 0
'If sngX2 = (-1) Then sngX2 = 100
'If sngY2 = (-1) Then sngY2 = 100
'*
'* Defines the boundaries of the barcode
'*
sngPosX = sngX1
'sngPosY = sngY2 - CSng(1.5 * 1.5) 'FontForText.Height)
sngPosY = sngY2 - CSng(1.5 * FontForText.Height)
'*
'* Clears the area
'*
'MyGraphicsPage.FillRectangle(New System.Drawing.SolidBrush(Color.White), sngX1, sngY1, sngX2 - sngX1, sngY2 - sngY1)
'*
'* Calculates the scale
'*
sngScaleX = (sngX2 - sngX1) / strEANBin.Length
'*
'* Draw the BarCode
'*
For K = 1 To Len(strEANBin)
If Mid(strEANBin, K, 1) = "1" Then
MyGraphicsPage.FillRectangle(New System.Drawing.SolidBrush(Color.Black), sngPosX, sngY1, sngScaleX, sngPosY)
End If
sngPosX = sngX1 + (K * sngScaleX)
Next K
'*
'* Draw the human-friendly code
'*
strFormat.Alignment = StringAlignment.Center
strFormat.FormatFlags = StringFormatFlags.NoWrap
MyGraphicsPage.DrawString(strEANCode, FontForText, New System.Drawing.SolidBrush(Color.Black), CSng((sngX2 - sngX1) / 2), CSng(sngY2 - FontForText.Height), strFormat)
'end of modification
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
PrintMe.Print()
End Sub
Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
PreviewMe.ShowDialog()
End Sub
End Class