Click here to Skip to main content
15,918,596 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Close form form another one Pin
Dave Kreskowiak11-May-05 2:42
mveDave Kreskowiak11-May-05 2:42 
GeneralRe: Close form form another one Pin
johnjsm11-May-05 3:07
johnjsm11-May-05 3:07 
GeneralRe: Close form form another one Pin
Rizwan Bashir11-May-05 3:17
Rizwan Bashir11-May-05 3:17 
GeneralRe: Close form form another one Pin
Dave Kreskowiak11-May-05 5:46
mveDave Kreskowiak11-May-05 5:46 
GeneralRe: Close form form another one Pin
Dave Kreskowiak11-May-05 5:43
mveDave Kreskowiak11-May-05 5:43 
GeneralPrinting a form/page Pin
LAYEEQ AHMED KHAN10-May-05 23:14
LAYEEQ AHMED KHAN10-May-05 23:14 
GeneralRe: Printing a form/page Pin
Dave Kreskowiak11-May-05 2:42
mveDave Kreskowiak11-May-05 2:42 
GeneralRe: Printing a form/page Pin
Treacherous_112-May-05 5:20
Treacherous_112-May-05 5:20 
Also you're going to have to let us know what version of VB you are using, for 6.0 printing the form is really simple (Me.printform), but in VB NET 2003 it's much more complicated. I had to do a project for a class that printed the form in 2003, utter chaos. I'll post the source later.

Treacherous_1

Here's what I came up with, it enables print preview, page setup, and printing in .NET 2003:

_________________________ Printing Form _____________________________

Imports System.Drawing.Printing
Public Class frmMain
Inherits System.Windows.Forms.Form
' storage for form image
Dim formImage As Bitmap
' create API prototype
Private Declare Function BitBlt Lib "gdi32.dll" Alias "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 Long

#Region " Windows Form Designer generated code "

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.StartPosition = FormStartPosition.WindowsDefaultLocation
End Sub

Private Sub mnuFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFilePrint.Click
GetFormImage() 'Takes the screen shot to be printed
If pdbMgrReport.ShowDialog = DialogResult.OK Then
docMgrReport.Print()
End If
End Sub

Private Sub mnuFilePreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFilePreview.Click
GetFormImage() 'Takes the screen shot to be previewed
Try
ppdMgrReport.ShowDialog()
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub

Private Sub mnuFileSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileSetup.Click
With psdMgrReport
docMgrReport.DefaultPageSettings.Margins.Left = 0.5
docMgrReport.DefaultPageSettings.Margins.Top = 0.5
docMgrReport.DefaultPageSettings.Landscape = True
.PageSettings = docMgrReport.DefaultPageSettings
End With
Try
If psdMgrReport.ShowDialog = DialogResult.OK Then
docMgrReport.DefaultPageSettings = psdMgrReport.PageSettings
End If
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub

Private Sub mnuFileControl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileControl.Click
nextForm = "frmPreview"
End Sub

Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
nextForm = "Exit"
Me.Close()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles docMgrReport.PrintPage
e.Graphics.DrawImage(formImage, 50, 50)
End Sub

Private Sub GetFormImage()
Dim g As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
formImage = New Bitmap(s.Width, s.Height, g)
Dim mg As Graphics = Graphics.FromImage(formImage)
Dim dc1 As IntPtr = g.GetHdc
Dim dc2 As IntPtr = mg.GetHdc
' added code to compute and capture the form
' title bar and borders
Dim widthDiff As Integer = _
(Me.Width - Me.ClientRectangle.Width)
Dim heightDiff As Integer = _
(Me.Height - Me.ClientRectangle.Height)
Dim borderSize As Integer = widthDiff \ 2
Dim heightTitleBar As Integer = heightDiff - borderSize
BitBlt(dc2, 0, 0, _
Me.ClientRectangle.Width + widthDiff, _
Me.ClientRectangle.Height + heightDiff, dc1, _
0 - borderSize, 0 - heightTitleBar, 13369376)

g.ReleaseHdc(dc1)
mg.ReleaseHdc(dc2)
End Sub
End Class

_________________________ Print Preview ________________________________

Public Class frmPreview
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Private Sub ppcMgrReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ppcMgrReport.Click
Try
ppcMgrReport.Document = docMgrReport
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub
End Class

__________________________ Global Variables ____________________________

Module GlobalVariables
Public nextForm As String 'Which form should be displayed next?
Friend WithEvents docMgrReport As System.Drawing.Printing.PrintDocument


Public Sub main()
Dim frmCurrentForm As Form

frmCurrentForm = New frmMain
Do While nextForm <> "Exit"
Select Case nextForm
Case "Preview" : frmCurrentForm = New frmPreview
End Select
frmCurrentForm.ShowDialog()
Loop
End Sub
End Module
GeneralForms Pin
gone8310-May-05 21:19
gone8310-May-05 21:19 
GeneralRe: Forms Pin
Rizwan Bashir10-May-05 23:10
Rizwan Bashir10-May-05 23:10 
GeneralRe: Forms Pin
gone8311-May-05 16:47
gone8311-May-05 16:47 
GeneralRe: Forms Pin
Dave Kreskowiak12-May-05 7:15
mveDave Kreskowiak12-May-05 7:15 
GeneralDetails of Users connecting to a Network Share Pin
Paul T.10-May-05 20:25
sussPaul T.10-May-05 20:25 
GeneralREGISTRY Pin
Aunalisiraj10-May-05 19:45
Aunalisiraj10-May-05 19:45 
GeneralRe: REGISTRY Pin
Dave Kreskowiak11-May-05 5:38
mveDave Kreskowiak11-May-05 5:38 
GeneralStartup Form Pin
Madni Abbasi10-May-05 19:40
Madni Abbasi10-May-05 19:40 
GeneralRe: Startup Form Pin
Paul T.10-May-05 20:33
sussPaul T.10-May-05 20:33 
GeneralOmnipass password recognition Pin
Pugman81210-May-05 19:24
Pugman81210-May-05 19:24 
GeneralRe: Omnipass password recognition Pin
Dave Kreskowiak11-May-05 2:27
mveDave Kreskowiak11-May-05 2:27 
GeneralRe: Omnipass password recognition Pin
Pugman81211-May-05 5:47
Pugman81211-May-05 5:47 
GeneralRe: Omnipass password recognition Pin
Dave Kreskowiak11-May-05 6:00
mveDave Kreskowiak11-May-05 6:00 
GeneralAvalon Pin
nitin_ion10-May-05 19:06
nitin_ion10-May-05 19:06 
GeneralRe: Avalon Pin
Dave Kreskowiak11-May-05 2:23
mveDave Kreskowiak11-May-05 2:23 
QuestionHow to work with Medical Equipments Pin
monica2k10-May-05 18:49
monica2k10-May-05 18:49 
AnswerRe: How to work with Medical Equipments Pin
Colin Angus Mackay10-May-05 22:27
Colin Angus Mackay10-May-05 22:27 

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.