Hi This is to print a form which contains a tab control.For this you have to instal Microsoft.Visual Basic.PowerPacks.Printing.dll.Then add one command button and a tab control to your form.Then add some other controls to your tabpages.Drag PrintDocument1 control from the tool box to your form.After that paste the code in the code behind.Press F5 to run it.Click on the button1 to print the pages. Option Strict Off Imports System.Drawing Imports System.Drawing.Printing Imports System.Runtime.InteropServices Public Class Form1 Dim TabId As Integer Dim i As Integer Dim img As Bitmap Dim WithEvents pd As PrintDocument Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.TabControl1.SelectTab(0) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try TabId = Me.TabControl1.TabCount For i = 0 To TabId - 1 Me.TabControl1.TabIndex = i Me.TabControl1.SelectTab(i) 'MsgBox(i) Me.Refresh() img = CaptureForm1() pd = New PrintDocument pd.Print() Next Catch ex As Exception MsgBox(ex) End Try End Sub Function CaptureForm1() As Bitmap Dim g1 As Graphics = Me.CreateGraphics() Dim MyImage = New Bitmap(Me.ClientRectangle.Width, (Me.ClientRectangle.Height), g1) Dim g2 As Graphics = Graphics.FromImage(MyImage) Dim dc1 As IntPtr = g1.GetHdc() Dim dc2 As IntPtr = g2.GetHdc() BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, (Me.ClientRectangle.Height), dc1, 0, 0, 13369376) g1.ReleaseHdc(dc1) g2.ReleaseHdc(dc2) 'saves image to c drive just, u can comment it also MyImage.Save("c:\abc.bmp") Return MyImage End Function Sub pd_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles pd.PrintPage Dim x As Integer = e.MarginBounds.X Dim y As Integer = e.MarginBounds.Y e.Graphics.DrawImage(img, x, y) e.HasMorePages = False End Sub SetLastError:=True, CharSet:=CharSet.Unicode, _ ExactSpelling:=True, _ CallingConvention:=CallingConvention.StdCall)> _ Private Shared Function BitBlt(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean ' Leave function empty - DLLImport attribute forwards calls to MoveFile to ' MoveFil
vinidimple
Posts
-
print a form which contains a tab control -
How to print a form in vb.net with multiple tab pages!!Hi This is to print a form which contains a tab control.For this you have to instal Microsoft.Visual Basic.PowerPacks.Printing.dll.Then add one command button and a tab control to your form.Then add some other controls to your tabpages.Drag PrintDocument1 control from the tool box to your form.After that paste the code in the code behind.Press F5 to run it.Click on the button1 to print the pages. Option Strict Off Imports System.Drawing Imports System.Drawing.Printing Imports System.Runtime.InteropServices Public Class Form1 Dim TabId As Integer Dim i As Integer Dim img As Bitmap Dim WithEvents pd As PrintDocument Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.TabControl1.SelectTab(0) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try TabId = Me.TabControl1.TabCount For i = 0 To TabId - 1 Me.TabControl1.TabIndex = i Me.TabControl1.SelectTab(i) 'MsgBox(i) Me.Refresh() img = CaptureForm1() pd = New PrintDocument pd.Print() Next Catch ex As Exception MsgBox(ex) End Try End Sub Function CaptureForm1() As Bitmap Dim g1 As Graphics = Me.CreateGraphics() Dim MyImage = New Bitmap(Me.ClientRectangle.Width, (Me.ClientRectangle.Height), g1) Dim g2 As Graphics = Graphics.FromImage(MyImage) Dim dc1 As IntPtr = g1.GetHdc() Dim dc2 As IntPtr = g2.GetHdc() BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, (Me.ClientRectangle.Height), dc1, 0, 0, 13369376) g1.ReleaseHdc(dc1) g2.ReleaseHdc(dc2) 'saves image to c drive just, u can comment it also MyImage.Save("c:\abc.bmp") Return MyImage End Function Sub pd_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles pd.PrintPage Dim x As Integer = e.MarginBounds.X Dim y As Integer = e.MarginBounds.Y e.Graphics.DrawImage(img, x, y) e.HasMorePages = False End Sub
-
Error while opening projectHi Sorry i was trying to send the request through each forum but error page displays,so i go for multiple requests,yes thank you i got he answer through google thank you dimp dimp
-
Error While opening a Dot net ProjectHi I am facing one problem while opening my Dot net project ?Error is coming like there "There is error on 1 Line:Expected '<' but found Auto attach" and the corresponding project file is not a valid project. if anybody knows please help me out dimp
-
Error while opening projectHi I am facing one problem while opening my Dot net project ?Error is coming like there "There is error on 1 Line:Expected '<' but found Auto attach" and the corresponding project file is not a valid project. if anybody knows please help me out dimp dimp dimp
-
Error while opening DotNet projectHi I am facing one problem while opening my Dot net project ?Error is coming like there "There is error on 1 Line:Expected '<' but found Auto attach" and the corresponding project file is not a valid project. if anybody knows please help me out dimp dimp
-
Regarding Dot netHi I am facing one problem while opening my Dot net project ?Error is coming like there "There is error on 1 Line:Expected '<' but found Auto attach" and the corresponding project file is not a valid project. if anybody knows please help me out dimp