Click here to Skip to main content
16,004,919 members
Home / Discussions / Windows Forms
   

Windows Forms

 
QuestionSystem Tray Replacement Pin
Z-Human13-Apr-07 9:20
Z-Human13-Apr-07 9:20 
QuestionWord to XML Pin
tantoun12-Apr-07 20:22
tantoun12-Apr-07 20:22 
AnswerRe: Word to XML Pin
Pete O'Hanlon13-Apr-07 0:57
mvePete O'Hanlon13-Apr-07 0:57 
GeneralRe: Word to XML Pin
tantoun17-Apr-07 4:43
tantoun17-Apr-07 4:43 
GeneralRe: Word to XML Pin
Pete O'Hanlon17-Apr-07 5:10
mvePete O'Hanlon17-Apr-07 5:10 
GeneralRe: Word to XML Pin
tantoun22-Apr-07 22:10
tantoun22-Apr-07 22:10 
QuestionUse of delegates not solving the cross thread problems in .NET 2.0 Framework Pin
KKrista12-Apr-07 19:27
KKrista12-Apr-07 19:27 
QuestionHow to print a form in vb.net with multiple tab pages!! Pin
vinidimple10-Apr-07 2:55
vinidimple10-Apr-07 2:55 
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
<dllimport("gdi32.dll", entrypoint:="BitBlt" ,="" _
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
' MoveFileW in KERNEL32.DLL.
End Function


Hope this may b helpful for you sometimes.
Thanks
Vinidimple

dimp

Questionflash Pin
pratima17-Apr-07 0:00
pratima17-Apr-07 0:00 
AnswerRe: flash Pin
SlingBlade9-Apr-07 10:03
SlingBlade9-Apr-07 10:03 
AnswerRe: flash Pin
Thomas Stockwell12-Apr-07 14:01
professionalThomas Stockwell12-Apr-07 14:01 
QuestionIs it possible to modify InitializeComponent() safely? Pin
SlingBlade5-Apr-07 11:17
SlingBlade5-Apr-07 11:17 
AnswerRe: Is it possible to modify InitializeComponent() safely? Pin
Colin Angus Mackay7-Apr-07 0:36
Colin Angus Mackay7-Apr-07 0:36 
GeneralRe: Is it possible to modify InitializeComponent() safely? Pin
SlingBlade8-Apr-07 0:41
SlingBlade8-Apr-07 0:41 
GeneralRe: Is it possible to modify InitializeComponent() safely? Pin
Colin Angus Mackay8-Apr-07 1:11
Colin Angus Mackay8-Apr-07 1:11 
GeneralRe: Is it possible to modify InitializeComponent() safely? Pin
SlingBlade9-Apr-07 6:33
SlingBlade9-Apr-07 6:33 
GeneralRe: Is it possible to modify InitializeComponent() safely? Pin
Colin Angus Mackay9-Apr-07 6:56
Colin Angus Mackay9-Apr-07 6:56 
GeneralRe: Is it possible to modify InitializeComponent() safely? Pin
SlingBlade9-Apr-07 7:23
SlingBlade9-Apr-07 7:23 
QuestionHow to push submit button from code behind? Pin
nikjoh5-Apr-07 2:27
nikjoh5-Apr-07 2:27 
AnswerRe: How to push submit button from code behind? Pin
kubben5-Apr-07 2:45
kubben5-Apr-07 2:45 
GeneralRe: How to push submit button from code behind? Pin
nikjoh5-Apr-07 4:49
nikjoh5-Apr-07 4:49 
QuestionHow to enable & disable USB ports from .NET applications? Pin
abyclassic4-Apr-07 21:20
abyclassic4-Apr-07 21:20 
AnswerRe: How to enable & disable USB ports from .NET applications? Pin
Dave Kreskowiak5-Apr-07 6:25
mveDave Kreskowiak5-Apr-07 6:25 
QuestionComboBox and DataSet binding Pin
gotdablues2-Apr-07 14:39
gotdablues2-Apr-07 14:39 
AnswerRe: ComboBox and DataSet binding Pin
kubben9-Apr-07 16:50
kubben9-Apr-07 16:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.