Dobrý deň. Potreboval by som poradiť s týmto problémom. V programe mám tento kód na tlačenie dokumentu.
*********************************************************************************************
'táto časť programu generuje tlačovú zostavu z aktuálne nastaveného záznamu v recordsete TOOLS
'*********************************************************************************************
'udalosť kliknutie na print tlačidlo
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'skok na výber dát pre tlač
subSelectPrintData()
End Sub
'udalosť kliknutia na položku Tlač v menu
Private Sub TlačToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TlačToolStripMenuItem1.Click
'skok na výber dát pre tlač
subSelectPrintData()
End Sub
'výber dát pre tlač
Private Sub subSelectPrintData()
Select Case TabControl1.TabIndex
Case 0
subGeneratePrintToolsDocument()
End Select
End Sub
Private Sub subGeneratePrintToolsDocument()
'uloží do premennej strPrintString všetky hodnoty, ktoré sa vytlačia
'(nl = Next Line = konštanta vbcrlf = zalomenie riadku -> definované na začiatku programu)
strPrintString = "HLAVNÉ INFO / GENERAL INFO" & nl & _
"Číslo formy / Tool Number: " & TextBox1.Text & nl & _
"Názov projektu / Project Name: " & TextBox3.Text & nl & _
"Názov výrobku / Product Name: " & TextBox2.Text & nl & nl & _
"ČÍSLA DIELOV / PART NUMBERS" & nl & _
"Diel 1 / Part 1: " & TextBox6.Text & nl & _
"Diel 2 / Part 2: " & TextBox4.Text & nl & nl & _
"STAV / STATUS" & nl & _
"Dátum / Date: " & TextBox7.Text & nl & _
"Aktívny / Neaktívny / Active / Inactive: " & TextBox5.Text & nl & nl & _
"ROZMERY / DIMENSIONS" & nl & _
"DOSKA / TABLE" & nl & _
"Horizontálne / Horizontal: " & TextBox8.Text & nl & _
"Vertikálne / Vertical: " & TextBox9.Text & nl & _
"Výška / Height: " & TextBox10.Text & nl & _
"CELKOM / TOTAL" & nl & _
"Horizontálne / Horizontal: " & TextBox11.Text & nl & _
"Vertikálne / Vertical: " & TextBox12.Text & nl & _
"Výška / Height: " & TextBox13.Text & nl & nl & _
"VYHADOVAČ / EJECTOR" & nl & _
"Dráha / Trajectory: " & TextBox16.Text & nl & _
"Prázdny zdvih / Blank Uplift: " & TextBox15.Text & nl & _
"Typ / Type" & nl & _
"Mechanický / Mechanic: " & CheckBox1.Checked.ToString & nl & _
"Hydraulický / Hydraulic: " & CheckBox2.Checked.ToString & nl & nl & _
"DELIACA DRÁHA (FS/BS) / DIVIDING TRACK (FS/BS)" & nl & _
"Deliaca dráha (mm) / Dividing Track (mm): " & TextBox17.Text & nl & nl & _
"TRYSKA / JET" & nl & _
"Hladina uloženia / Arrangement Level: " & TextBox18.Text & nl & _
"Typ / Type: " & TextBox14.Text & nl & nl & _
"VSTREKOLIS / MOULD MACHINE" & nl & _
"Typ / Type: " & TextBox20.Text & nl & _
"Uzatváracia sila (kN) / Closing Power (kN): " & TextBox19.Text & nl & nl & _
"TYP VSTREKOVANÉHO MATERIÁLU / INJECTION MATERIAL TYPE" & nl & _
"Plánovaný / Planned: " & TextBox24.Text & nl & _
"Použitý / Used: " & TextBox23.Text & nl & nl & _
"STREDENIE / CENTERING" & nl & _
"BS priemer (mm) / BS Diameter (mm): " & TextBox22.Text & nl & _
"FS priemer (mm) / FS Diameter (mm): " & TextBox21.Text & nl & nl & _
"TYP VTOKU / INFLOW TYPE: " & TextBox27.Text & nl & nl & _
"HORÚCI KANÁL / HOT CHANNEL: " & TextBox25.Text & nl & nl & _
"VTOKOVÁ VLOŽKA / INFLOW PLUG" & nl & _
"Tryska polomer (mm) / Jet Radius (mm): " & TextBox26.Text & nl & _
"Otvor priemer (mm) / Hole Diameter (mm): " & TextBox28.Text & nl & _
"Číslo normy / Specification Number: " & TextBox29.Text & nl & nl & _
"HMOTNOSŤ FORMY / TOOL WEIGHT" & nl & _
"BS (kg): " & TextBox31.Text & nl & _
"FS (kg): " & TextBox32.Text & nl & _
"Celkom (kg) / Total (kg): " & TextBox30.Text & nl & nl & _
"HMOTNOSŤ / WEIGHT" & nl & _
"Vtok (g) / Inflow (g): " & TextBox34.Text & nl & _
"Zdvih (g) / Uplift (g): " & TextBox33.Text & nl & nl & _
"VÝROBCA / PRODUCER: " & TextBox35.Text & nl & nl & _
"GREIFER: " & CheckBox3.Checked.ToString & nl & nl & _
"ČAS CYKLU (s) / CYCLE TIME (s): " & TextBox36.Text & nl & nl & _
"UMIESTNENIE FORMY / TOOL LOCATION: " & TextBox37.Text & nl & nl & _
"CYKLUS ÚDRŽBY / MAINTENANCE INTERVAL: " & TextBox38.Text & nl & nl & _
"INDEXOVÝ STAV / INDEXED STATUS: " & TextBox39.Text & nl & nl & _
"NÁKUPNÁ CENA / BUYING PRICE: " & TextBox40.Text & nl & nl & _
"TVRDOSŤ MATERIÁLU / MATERIAL HARDNESS" & nl & _
"Pevná vložka / Fix Plug: " & TextBox41.Text & nl & _
"Pohyblivá vložka / Move Plug: " & TextBox42.Text & nl & _
"Šíber / Shifter: " & TextBox43.Text & nl & nl & _
"POČET KAVÍT / CAVITAS NUMBER: " & TextBox44.Text & nl & nl & _
"NÁSTROJ LPP/TPP / LPP/TPP TOOL: " & TextBox45.Text & nl & nl & _
"STROJ / MACHINE" & nl
If bolPrintPreview = True Then
Exit Sub
Else
subPrint()
End If
End Sub
Private Sub subPrint()
Try
PrintDocument.DefaultPageSettings = PrintPageSettings
strPrintString = strPrintString
PrintDialog.Document = PrintDocument
Dim result As [DialogResult] = PrintDialog.ShowDialog
If result = Windows.Forms.DialogResult.OK Then
PrintDocument.Print()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub PrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument.PrintPage
Dim NumOfChars As Integer
Dim NumOfLines As Integer
Dim strForPage As String
Dim strFormat As New StringFormat
Dim defRect As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, _
e.MarginBounds.Width, e.MarginBounds.Height)
Dim defSize As New SizeF(e.MarginBounds.Width, e.MarginBounds.Height _
- PrintFont.GetHeight(e.Graphics))
strFormat.Trimming = StringTrimming.Word
e.Graphics.MeasureString(strPrintString, PrintFont, defSize, strFormat, _
NumOfChars, NumOfLines)
strForPage = strPrintString.Substring(0, NumOfChars)
e.Graphics.DrawString(strForPage, PrintFont, Brushes.Black, defRect, strFormat)
If NumOfChars < strPrintString.Length Then
strPrintString = strPrintString.Substring(NumOfChars)
e.HasMorePages = True
Else
e.HasMorePages = False
strPrintString = strPrintString
End If
End Sub
Private Sub NastavenieStranyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NastavenieStranyToolStripMenuItem.Click
Try
PageSetupDialog.PageSettings = PrintPageSettings
PageSetupDialog.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub NahladTlaceToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NahladTlaceToolStripMenuItem1.Click
Try
PrintDocument.DefaultPageSettings = PrintPageSettings
bolPrintPreview = True
subGeneratePrintToolsDocument()
PrintPreviewDialog.Document = PrintDocument
PrintPreviewDialog.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
bolPrintPreview = False
End Sub
End Class
Keď tlačím priamo, bez náhľadu, všetko je v poriadku a dokument sa vytlačí celý. Ale keď si zvolím možnosť náhľadu tlače a potom dám tlačiť z tohto náhľadu ( v náhľade je vidieť celý dokument na dvoch stranách), tak sa vytlačí iba posledná (druhá) strana dokumentu. Môžete poradiť, kde mám chybu? Ďakujem.
|