473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

vbnet GDI+ Screen and Printer

2
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_PrintPage) 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.Millimeter" 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 2558
crom
2
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
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...
2
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. ...
5
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...
10
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...
7
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"...
0
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:...
14
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:...
0
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....
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.