Hi All..Im new to Visual Basic 2008 and I'm having a really hard time figuring out how to to print all my tabs in my application. I have 5 tabs which have text boxes, labels, and combo boxes. Is there a way to print the contents of each tab and have each tab print on a separate page? Any help greatly appreciated. Thanks
JohnnySpider 0 Newbie Poster
kvprajapati 1,826 Posting Genius Team Colleague
>Is there a way to print the contents of each tab and have each tab print on a separate page?
PrintForm control.
..
PrintForm1.PrintAction = Printing.PrintAction.PrintToPrinter
For i As Integer = 0 To Me.TabControl1.TabPages.Count - 1
Me.TabControl1.TabPages(i).Show()
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.FullWindow)
Next
..
JohnnySpider 0 Newbie Poster
Thanks a lot! It's a great start but I'm so new to VB can you tell me where that code goes :)
JohnnySpider 0 Newbie Poster
Is there a way to just pull the raw data from the tabs without a snapshot being taken because the quality looks bad when printed... thanks
kvprajapati 1,826 Posting Genius Team Colleague
>can you tell me where that code goes
Click event handler of button/menu.
>Is there a way to just pull the raw data from the tabs without a snapshot being taken because the quality looks bad when printed..
Read properties (Text or value) of controls.
JohnnySpider 0 Newbie Poster
Sorry but can you give me more detailed code, i cant figure out how to incorporate the code
kvprajapati 1,826 Posting Genius Team Colleague
>Sorry but can you give me more detailed code, i cant figure out how to incorporate the code
What did you expect it to do? Do you get any errors? Please, Show me your code.
JohnnySpider 0 Newbie Poster
I put the code at the bottom and changed it to to print preview to test it, I have a couple different types of printing code because I was experimenting but the code you gave me is at the bottom. It works but keeps looping and I just want to print the content of each tab. Thank you
Imports System.IO
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Printing
Public Class Form1
Inherits Form
Private WithEvents printButton As New Button
Private WithEvents printDocument1 As New PrintDocument
Public Sub Form1()
printButton.Text = "Print Form"
Me.Controls.Add(printButton)
End Sub
Dim memoryImage As Bitmap
Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
End Sub
Private Sub printDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
printDocument1.PrintPage
Dim bmp As Bitmap = New Bitmap(Me.TabControl1.TabPages(0).Width, Me.TabControl1.TabPages(0).Height)
Me.TabControl1.TabPages(0).DrawToBitmap(bmp, Me.TabControl1.TabPages(0).Bounds)
e.Graphics.DrawImage(bmp, 0, 0)
End Sub
Private Sub OpenToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripButton.Click
Dim IceCreamReader As StreamReader
Dim results As DialogResult
'Set the Open dialog properties
With OpenFileDialog1
.Filter = "Text Documents (*.tst)|*.tst|All Files (*.*)|*.*"
.FilterIndex = 1
.Title = "Demo Open File Dialog"
End With
results = OpenFileDialog1.ShowDialog
If results = DialogResult.OK Then
IceCreamReader = New StreamReader(OpenFileDialog1.FileName)
TextBox2.Text = IceCreamReader.ReadLine()
TextBox1.Text = IceCreamReader.ReadLine()
cboContainers.SelectedIndex = IceCreamReader.ReadLine()
cboIngredients.SelectedIndex = IceCreamReader.ReadLine()
IceCreamReader.Close()
End If
End Sub
Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
Dim IceCreamWriter As StreamWriter
Dim results As DialogResult
'Set the Save dialog properties
With SaveFileDialog1
.DefaultExt = "tst"
.Filter = "Text Documents (*.tst)|*.tst|All Files (*.*)|*.*"
.FilterIndex = 1
.OverwritePrompt = True
.Title = "Demo Save File Dialog"
End With
results = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
IceCreamWriter = New StreamWriter(SaveFileDialog1.FileName, False)
IceCreamWriter.WriteLine(TextBox2.Text)
IceCreamWriter.WriteLine(TextBox1.Text)
IceCreamWriter.WriteLine(cboContainers.SelectedIndex)
IceCreamWriter.WriteLine(cboIngredients.SelectedIndex)
IceCreamWriter.Close()
End If
End Sub
Private Sub NewToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripButton.Click
Dim intResult As DialogResult
intResult = _
MsgBox(("Do you want to save your document?"), MsgBoxStyle.YesNoCancel, "New Form")
Select Case intResult
Case Windows.Forms.DialogResult.No
TextBox1.Text = ""
TextBox2.Text = ""
cboContainers.SelectedIndex = 0
cboIngredients.SelectedIndex = 0
Case Windows.Forms.DialogResult.Yes
Dim IceCreamWriter As StreamWriter
Dim results As DialogResult
'Set the Save dialog properties
With SaveFileDialog1
.DefaultExt = "tst"
.Filter = "Text Documents (*.tst)|*.tst|All Files (*.*)|*.*"
.FilterIndex = 1
.OverwritePrompt = True
.Title = "Demo Save File Dialog"
End With
results = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
IceCreamWriter = New StreamWriter(SaveFileDialog1.FileName, False)
IceCreamWriter.WriteLine(TextBox2.Text)
IceCreamWriter.WriteLine(TextBox1.Text)
IceCreamWriter.WriteLine(cboContainers.SelectedIndex)
IceCreamWriter.WriteLine(cboIngredients.SelectedIndex)
IceCreamWriter.Close()
End If
End Select
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CaptureScreen()
printDocument1.Print()
End Sub
Public Shared Sub Main()
Application.Run(New Form1())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
End Sub
Private Sub PrintToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripButton.Click
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
For i As Integer = 0 To Me.TabControl1.TabPages.Count - 1
Me.TabControl1.TabPages(i).Show()
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.FullWindow)
Next
End Sub
End Class
Edited by JohnnySpider because: n/a
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.