473,406 Members | 2,619 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,406 software developers and data experts.

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_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
printFont = new Font("Arial", 10);
float yPos = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
yPos = topMargin;
e.Graphics.DrawString("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 19549
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_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics g = e.Graphics;
g.PageUnit = GraphicsUnit.Inch;

// 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 headerTextLayout = new RectangleF (
leftMargin, topMargin, width, height );

float headerHeight;
StringFormat headerStringFormat = new
StringFormat(StringFormatFlags.LineLimit);
headerStringFormat.Alignment = StringAlignment.Center;
headerStringFormat.Trimming = StringTrimming.EllipsisWord;

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

headerHeight = g.MeasureString (headerText,
this.HeaderFont, headerTextLayout.Size,
headerStringFormat).Height;
headerTextLayout.Height = headerHeight;

// do the actual drawing
g.FillRectangle(new SolidBrush(Color.AliceBlue),
headerTextLayout);
g.DrawString(headerText, printFont, Brushes.Black,
headerTextLayout, headerStringFormat);

}
"Bobby C. Jones" <bo****@acadx.com> wrote in message
news:Od*************@TK2MSFTNGP09.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
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...
3
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
3
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...
2
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...
1
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). ...
0
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...
3
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...
2
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...
2
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...
1
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.