Simple printing question

jimday1982

Member
Joined
Jul 30, 2003
Messages
22
Location
Va Beach
Hello-

I am having a lot of trouble printing anything to my printer from my program and even finding information on printing. Can anyone reply with a simple function that prints the word "Cover Page" on the top center of a page? Or anything similar would be great. It would really be helpful to me to see how this works. Thank you!
 
I found that printing is a pretty complicated thing. Here is an example method I made that is not complete yet. Look up PrintDocument on the net.
C#:
int NewLine=0;  int width=0;  int    =0;
			public void Print_text(PrintPageEventArgs e, ref string doc, Font TextFont, Brush TextColor)
			{
				width= e.MarginBounds.Width;
				StringBuilder SB=new StringBuilder(1000);
				SizeF strLength;  bool MorePs=true;
				float yPos=0;  string word="";
				Rectangle R=new Rectangle(e.MarginBounds.Left, e.MarginBounds.Top+Convert.ToInt32(yPos), e.MarginBounds.Width, e.MarginBounds.Height);			
		
				while(yPos < e.MarginBounds.Bottom-e.MarginBounds.Top)
				{
					if(word=="") word= GetWord(doc);  if(word=="") {MorePs=false; break;}
					strLength= e.Graphics.MeasureString(SB.ToString()+word, TextFont, e.MarginBounds.Width, new StringFormat());
					if(NewLine > 0) 
					{yPos= yPos+(TextFont.GetHeight(e.Graphics)*NewLine);  NewLine= 0;}
					if(strLength.Width > e.MarginBounds.Width) 
					{yPos= yPos+TextFont.GetHeight(e.Graphics);}
					else if(yPos < e.MarginBounds.Bottom-e.MarginBounds.Top)
					{SB.Append(word); word="";}
				}
			
				e.Graphics.DrawString(SB.ToString(), TextFont, TextColor, R);
				if(MorePs) e.HasMorePages=true;
				else    =0;
			}

			string GetWord(string doc)
			{
				StringBuilder sb=new StringBuilder(8);
				if(    >= doc.Length) return "";
				while(!Char.IsLetterOrDigit(doc[   ]))
				{
					if(doc[   ]==\n) ++NewLine;
					sb.Append(doc[   ]);
					++   ;
					if(    >= doc.Length || sb.ToString().Length==width) return sb.ToString();
				}
				while(!Char.IsWhiteSpace(doc[   ]))
				{
					if(doc[   ]==\n) ++NewLine;
					sb.Append(doc[   ]);
					++   ;
					if(    >= doc.Length || sb.ToString().Length==width) return sb.ToString();
				}
				return sb.ToString();
			}
		}
 
Back
Top