473,810 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vbnet GDI+ Screen and Printer

2 New Member
Hello everyone!
I creating a document using VBNET's "graphics" object and show them in the PictureBox. Here is Sub CreateDoc which draw the document and shortened part of program (mistakes possible because of out IDE editing).
My intention is to call CreateDoc again through buttons PrintPreview or Print (I read that this is possible). But calling from PrintPreview Sub (PrnDoc_PrintPa ge) dont make any "picture" on PrintPreview control. As you can see, for testing purposes I add one string to page before creating a document and this string comes on the result page.
I am new in VB.Net and until now i programmed mostly in DOS, qb45:).
Logic of those namespaces, instances, withevents, marshalers, overrides etc, etc are real nightmare for me.
So I have two questions here:
1. What to do (without significant changes of program logic) that Print Preview appears on the "paper"? What I was doing wrong?
2. Where and how to put "g.PageUnit = GraphicsUnit.Mi llimeter" so I can use those measurement instead of "AllWidth". If I put PageUnit at the top of Sub programm breaks. Yet better would be How can I get size of
"C:\SomePic.gif " in millimeters to use this for reference in later calculations? In this case SomePic.gif is exactly 210*297mm (A4).
Please help...

Expand|Select|Wrap|Line Numbers
  1. Imports System.Drawing.Printing
  2. etc...
  3.  
  4. Public Class Dokument
  5.     Dim g As Graphics
  6.     Private PrnDoc As PrintDocument
  7. etc...
  8.  
  9. Public Sub Dokument_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10. ' This one CreateDoc works fine on PictureBox
  11. ' I can see the document "as should be"  
  12.     CreateDoc(g)
  13. End Sub
  14.  
  15. Public Sub CreateDoc(ByVal g As Graphics)
  16.  
  17.         Dim AllWidth = 800
  18.         Dim b As New Bitmap(AllWidth, 1100)
  19.  
  20.         g = Graphics.FromImage(b)
  21.         g.PageUnit = GraphicsUnit.Millimeter
  22.  
  23.         Dim img As Image = Image.FromFile("C:\SomePic.gif")
  24.         g.DrawImage(img, 0, 0, A4_Width, A4_Height)
  25.  
  26.                 cTabsIndex = 0
  27.                 Dim Rb As String = Format(z, "####")
  28.                 g.DrawString(Rb, f, Brushes.Black, LOdmak + cTabs(cTabsIndex) - g.MeasureString(Rb, f).Width, LineFromTop)
  29.  
  30.                 cTabsIndex += 1
  31.                 g.DrawString(OUTCHAR$(Sot.MJedO, InCode$, DeCode$), f, Brushes.Black, LOdmak + cTabs(cTabsIndex), LineFromTop)
  32.  
  33.                 cTabsIndex += 1
  34.                 Dim RKolic As String = Format(Sot.KolO, "#,##0.00")
  35.                 g.DrawString(RKolic, f, Brushes.Black, LOdmak + cTabs(cTabsIndex) - g.MeasureString(RKolic, f).Width, LineFromTop)
  36. ' ScreenPrint (boolean) is switch between outputs for PictureBox or PrintDocument object.
  37.  
  38.      If ScreenPrint Then
  39.         PictureBox1.Image = b
  40.         PictureBox1.Refresh()
  41.      Else
  42.         '?what else if something???
  43.      End If
  44.  
  45. g.Dispose()
  46. End Sub
  47.  
  48. Private Sub PrnDoc_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
  49.  
  50.         Dim FontName As String = "Microsoft Sans Serif"
  51.         Dim f As Font = New Font(FontName, 8, FontStyle.Regular)
  52.         ev.Graphics.DrawString("Only this visible", f, SomeBrush, 5, 5)
  53.  
  54. ' String "Only this visible" is visible on PrintPreview. CreateDoc should ' ' add whole document in PPreview but don't add nothing! What is wrong?
  55.  
  56.         CreateDoc(ev.Graphics)
  57.  
  58.     End Sub
  59.  
  60.     Private Sub ButtonPPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPPreview.Click
  61.  
  62.         PrnDoc = New PrintDocument
  63.         AddHandler PrnDoc.PrintPage, AddressOf PrnDoc_PrintPage
  64.         PrnDoc.PrinterSettings.PrinterName = "SomePDFPrinter"
  65.         PrnDoc.DocumentName = DocFileName
  66.         Dim PPDialog As New System.Windows.Forms.PrintPreviewDialog
  67.         With PPDialog
  68.             .Document = PrnDoc
  69.             .WindowState..., .ShowDialog(), .Dispose(), etc...
  70.         End With
  71.     End Sub
  72.  
  73.  
Apr 3 '09 #1
1 2577
crom
2 New Member
Ok, let me simplify question more.
How to fill PictureBox and PrintDocument from same graphics object what means how to use same code for both?
Apr 6 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1115
by: Jim Hubbard | last post by:
Can you use VB.Net to set a system-wide hook to intercept all GDI calls from GDI to the system's hardware? I want to intercept all GDI instructions sent to the system's hardware layer. As I understand it (and I may be missing something) GDI sends instructions to a DEVICE (which can be a printer or display unit or any device for which a device context can be obtained) and the device does the drawing. Also...if anyone can tell me how...
2
4132
by: Flare | last post by:
Hi. I have made a simple painting applcation. I have a mainform wich creates a class called drawingPanelwich inherit from Panel. In the drawingPaneli have overriden onPaint an the the painting. Now on my mainform i have a button called Print. I know how to print .....PrintPageEventArgs e (e.graphics......) But HOW do i get the things i ave painted on the drawingPanel? I cant see how i can access this temporary paint job. How is this...
5
4142
by: anonymous | last post by:
I'm writing a program that deals extensively with the printer. For the most part my application runs fine, but occasionally I run into some Exceptions. The most common exceptions I run into are NullReferenceException and InvalidOperationException : The object is currently in use elsewhere. Unfortunately this appears to be a race condition. These exceptions appear to ocurr while disposing GDI+ objects, the Graphics object seems to be the...
10
1639
by: Jim Hubbard | last post by:
Can you use VB.Net to set a system-wide hook to intercept all GDI calls from GDI to the system's hardware? I want to intercept all GDI instructions sent to the system's hardware layer. As I understand it (and I may be missing something) GDI sends instructions to a DEVICE (which can be a printer or display unit or any device for which a device context can be obtained) and the device does the drawing. Also...if anyone can tell me how...
7
5978
by: Marcin Rzeznicki | last post by:
Hello, Do you think it is legitimate practice to mix GDI+ and GDI calls (via Get/ReleaseHDC()) in paint event of a control? I've heard there is possibility of performance loss while "locking" Graphics object which is done as a side-effect to GetHDC() call - could you confirm? Another question that comes to my mind when planning mentioned operation is: if the control painted on uses double-buffering style, will GDI calls make use of "back...
0
1251
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
14
4116
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
0
2218
by: Alexey Zalivin | last post by:
Hi, I'm not sure, but reference MSDN ChangeDisplaySettingsEx can rotate screen if video driver support it. I try the third part products like IRotate and Pivot Pro and find that it really works. I have ATI (AMD) video and Catalist driver can rotate screen easy as well. I try to do in vb.net and ChangeDisplaySettingsEx can change resolution, frequancy and other setting exept rotation:-( Searching in Internet don't give any solution,...
2
3786
by: user | last post by:
Hi all... i am trying to print an image using GDI - but the only thing i get is a black rectangle. Does anybody know what is wrong, or how else to get the bitmap on the printer (GDI+ is not possible. it is a POS printer (for restaurants) and the printer internal fonts are a MUST for printing speed. as far as i know printer internal fonts are only accessable through GDI, so all my printing is GDI up to now)
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.