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... -
Imports System.Drawing.Printing
-
etc...
-
-
Public Class Dokument
-
Dim g As Graphics
-
Private PrnDoc As PrintDocument
-
etc...
-
-
Public Sub Dokument_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
' This one CreateDoc works fine on PictureBox
-
' I can see the document "as should be"
-
CreateDoc(g)
-
End Sub
-
-
Public Sub CreateDoc(ByVal g As Graphics)
-
-
Dim AllWidth = 800
-
Dim b As New Bitmap(AllWidth, 1100)
-
-
g = Graphics.FromImage(b)
-
g.PageUnit = GraphicsUnit.Millimeter
-
-
Dim img As Image = Image.FromFile("C:\SomePic.gif")
-
g.DrawImage(img, 0, 0, A4_Width, A4_Height)
-
-
cTabsIndex = 0
-
Dim Rb As String = Format(z, "####")
-
g.DrawString(Rb, f, Brushes.Black, LOdmak + cTabs(cTabsIndex) - g.MeasureString(Rb, f).Width, LineFromTop)
-
-
cTabsIndex += 1
-
g.DrawString(OUTCHAR$(Sot.MJedO, InCode$, DeCode$), f, Brushes.Black, LOdmak + cTabs(cTabsIndex), LineFromTop)
-
-
cTabsIndex += 1
-
Dim RKolic As String = Format(Sot.KolO, "#,##0.00")
-
g.DrawString(RKolic, f, Brushes.Black, LOdmak + cTabs(cTabsIndex) - g.MeasureString(RKolic, f).Width, LineFromTop)
-
' ScreenPrint (boolean) is switch between outputs for PictureBox or PrintDocument object.
-
-
If ScreenPrint Then
-
PictureBox1.Image = b
-
PictureBox1.Refresh()
-
Else
-
'?what else if something???
-
End If
-
-
g.Dispose()
-
End Sub
-
-
Private Sub PrnDoc_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
-
-
Dim FontName As String = "Microsoft Sans Serif"
-
Dim f As Font = New Font(FontName, 8, FontStyle.Regular)
-
ev.Graphics.DrawString("Only this visible", f, SomeBrush, 5, 5)
-
-
' String "Only this visible" is visible on PrintPreview. CreateDoc should ' ' add whole document in PPreview but don't add nothing! What is wrong?
-
-
CreateDoc(ev.Graphics)
-
-
End Sub
-
-
Private Sub ButtonPPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPPreview.Click
-
-
PrnDoc = New PrintDocument
-
AddHandler PrnDoc.PrintPage, AddressOf PrnDoc_PrintPage
-
PrnDoc.PrinterSettings.PrinterName = "SomePDFPrinter"
-
PrnDoc.DocumentName = DocFileName
-
Dim PPDialog As New System.Windows.Forms.PrintPreviewDialog
-
With PPDialog
-
.Document = PrnDoc
-
.WindowState..., .ShowDialog(), .Dispose(), etc...
-
End With
-
End Sub
-
-
1 2577
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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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,...
|
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)
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |