473,651 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PrintDocument

Ok, so I had a couple of minutes after lunch to play around a bit with the
System.Drawing. Printing namespace. I just wanted to print out a single line
of text. I had to work very hard to resist the urge to print out "Hello
World!" <g>

I got very excited as I pressed the button on my form and the printer
cranked up. It spit out the most beautiful blank white page that you've
ever seen. I'm going to read up and play with it some more this evening,
but does anyone see the problem off hand. Thanks!

private void printAccounts_P rintPage(object sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
printFont = new Font("Arial", 10);
float yPos = 0;
float leftMargin = e.MarginBounds. Left;
float topMargin = e.MarginBounds. Top;
yPos = topMargin;
e.Graphics.Draw String("Bobby C. Jones", printFont, Brushes.Black,
leftMargin, yPos, new StringFormat()) ;
e.HasMorePages = false;
}
--
Bobby C. Jones
http://code.AcadX.com
Nov 15 '05 #1
2 19572
I've been "having fun" trying to get printing to work as well. I
highly recommend this site:
http://msdn.microsoft.com/library/de...ntwinforms.asp

If you haven't already figured out your problem, give the following a
try. I belive your problem has to do with units, but not really sure.
(The following is kindof a mess, sorry. It's a lot of cut & paste
from a project I was working on).

private void printAccounts_P rintPage(object sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
Graphics g = e.Graphics;
g.PageUnit = GraphicsUnit.In ch;

// convert to inches
float leftMargin = e.MarginBounds. Left / 100F;
float rightMargin = e.MarginBounds. Right / 100F;
float topMargin = e.MarginBounds. Top / 100F;
float bottomMargin = e.MarginBounds. Bottom / 100F;
float width = e.MarginBounds. Width / 100F;
float height = e.MarginBounds. Height / 100F;
float currentPosition = topMargin;
e.HasMorePages = false;

string headerText = "Hello Bobby C. Jones";
RectangleF headerTextLayou t = new RectangleF (
leftMargin, topMargin, width, height );

float headerHeight;
StringFormat headerStringFor mat = new
StringFormat(St ringFormatFlags .LineLimit);
headerStringFor mat.Alignment = StringAlignment .Center;
headerStringFor mat.Trimming = StringTrimming. EllipsisWord;

Font printFont = new Font("Arial", 10);

headerHeight = g.MeasureString (headerText,
this.HeaderFont , headerTextLayou t.Size,
headerStringFor mat).Height;
headerTextLayou t.Height = headerHeight;

// do the actual drawing
g.FillRectangle (new SolidBrush(Colo r.AliceBlue),
headerTextLayou t);
g.DrawString(he aderText, printFont, Brushes.Black,
headerTextLayou t, headerStringFor mat);

}
"Bobby C. Jones" <bo****@acadx.c om> wrote in message
news:Od******** *****@TK2MSFTNG P09.phx.gbl...
Ok, so I had a couple of minutes after lunch to play around a bit with the System.Drawing. Printing namespace. I just wanted to print out a single line of text. I had to work very hard to resist the urge to print out "Hello World!" <g>

Nov 15 '05 #2
Yor code works fine for me, VS2003 + HP Laserjet2200. Perhaps you should
have a look at the PrintDocument object's PrinterSetting before you call
Print( ) to see if everything is as you expect.

Brendan
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1913
by: Jeffry van de Vuurst | last post by:
Hi, I have a PrintDocument that I preview in a PrintPreviewControl. Now I run the app on a pc without any printers installed and when I want to preview the PrintDocument I get an InvalidPrinterException exception saying "No Printers Installed". Is this a bug or behavior by design? Is there anything I can do about this or should I just make sure that there's a printer installed?
3
5310
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
3
12370
by: Randy | last post by:
Hello, I'm trying to print a dataGrid using PrintDocument control. My datagrid has about 23 columns so it is fairly wide. When I use the PrintControl, it prints only the part of the dataGrid that is visible on screen. I tried using PrintPreviewDialog too but it still only shows just what is visible in the dialog that houses the dataGrid. I want to get all the datagrid printed. Maybe wrapping it would be the only way to print all of...
2
8263
by: Robert Hooker | last post by:
Hi, I'm curious to know if I'm doing something wrong here, or if this is just mind-numbingly slow for a reason. In a simple WindowsFormsApplication: public Form1() { // Required for Windows Form Designer support
1
2411
by: Frank Rizzo | last post by:
Hello, I have an OCX control on my WinForm (don't ask, i have to use it) and it generally works well. One of the methods of the OCX prints to an hDC (device context handle for history buffs). Seeing how everything in ..NET prints to a PrintDocument object, I was wondering how I can retrieve the hDC of the PrintDocument? Or am I looking in the wrong place?
0
1407
by: active | last post by:
Dim mPD As PrintDocument Dim mPrinternameSaved As PrintDocument Public WriteOnly Property PrintDocument() As PrintDocument Set(ByVal value As PrintDocument) mPD = value mPrinternameSaved = mPD I wanted to do something like the above except that I wanted mPrinternameSaved to be an additional set of data identical to that stored
3
6293
by: Mika M | last post by:
Hi all! I have made an application for printing simple barcode labels using PrintDocument object, and it's working fine. Barcode printer that I use is attached to the computer, and this computer has drivers installed for this printer, and this printer is shared for the network. Question 1:
2
28476
by: Steve | last post by:
I'm trying real hard to set the printer resolution for a PrintDocument. It appears that the printer is already set to 300 x 300 dpi, which is JUST what I want. But the Margins and PrintableArea properties of the PageSettings in the Print handler are reporting values that indicate 100 dpi, for example it reports PaperSize as 850, 1100 (8.5" x 11") I'm passing these Rectangle properties into a method that is drawing thinking it's working...
2
6620
by: bp | last post by:
Hi, I try to use my own PreviewDialog with a PrinPreviewControl, to preview a document of type MyPrintDocument, and I want to implement the PrintRange functionnality (print some pages between 2 values). I noticed that we can specified the PrintRange, FromPage and ToPage properties of the PrintDocument.PrintSettings object, but, as said in MSDN : "The FromPage, ToPage and PrintRange can also be set programmatically,
1
11177
by: kig25 | last post by:
Hello, When using the VB.NET PrintDocument class, I seem to be encountering an issue where the sub pd_PrintPage handles PrintDocument.PrintPage (upon continuing if HasMorePages = true) will paint the next page on top of the original page. In a sample data case where the source is long enough to fill three pages, I end up with four calls to pd_PrintPage which render onto two printed sheets. Historical posts in this forum from 2003 and...
0
8347
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
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7294
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
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
5605
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
4143
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
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.