Printing a form in VB
-
martes, 13 de marzo de 2012 1:32
Hi,
I have a program that I wrote that prints checks. I had been placing the data fiels in the approiate place on a windows form, and using printform to send the form to the printer. We have had a change in our checks, and I now need to put some of the fields toward the bottom of the printed page. It seems that the printform control is limited to the screen resolution. In other words printform will only print what is on ythe screen.
Is there a method of forcing the form to larger than the screen size (I tried setting the properties, studio 2010 won't take it), orsome other method of getting my larger than screen size form to print in full?
Thanks,
Mike
Todas las respuestas
-
miércoles, 14 de marzo de 2012 8:30Moderador
Hi Mike,
Welcome to the MSDN forum.
To make a form that larger than screen resolution, you can try the following codes:
Private Declare Function MoveWindow Lib "User32.dll" (ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer, ByVal Repaint As Boolean) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MaximumSize = New Size(5000, 800)
Dim Result As Boolean = MoveWindow(Me.Handle, Me.Left, Me.Top, 5000, 500, True)
End Sub
If you need to print a form that is larger than the screen, or is only partially displayed, then the controls on the form must be placed in a PictureBox. This prints the bitmap that is contained in the PictureBox, instead of a screen capture of the form itself (which is what PrintForm does). Because the PictureBox's bitmap is stored in a device context in memory, you have access to the entire bitmap regardless of what is displayed. please take a look at this VB6 article: How To Print a Form That Is Too Large for the Screen or Page .
I hope this will be helpful.
Shanks Zen
MSDN Community Support | Feedback to us
- Editado Shanks ZenMicrosoft Contingent Staff, Moderator miércoles, 14 de marzo de 2012 8:30
-
miércoles, 14 de marzo de 2012 10:58
Shanks... Thanks for the reply. I had seen (and tried) the MS article you mentioned. It did not seem to work. I'm guessing it was something is was doing incorrectly, but I could not get the picturebox to 'contain' the information I wanted to print. Part of my trouble was that code seemed used statements that did not work for my version of VB.net.
It did however give me some ideas. I ended up placing a panel control on the form and putting all the data in it. I then drew the container to a bitmap and printing it.
- Marcado como respuesta Justhininabouti miércoles, 14 de marzo de 2012 10:58

