What the code is doing is reading from a text file and printing that out.
Here's a partially cleaned version of that. I'm not worrying about
multiple pages since it doesn't seem like you will run into that
situation. You'll have to clean this up. This is just a quick and
dirty.
//Example Form that Prints
public class PrintCtl : Form {
Private string[] printBuffer ;
Private Font printFont;
Private int startLine;
//Event fired when the user presses the print button
private void print_Click(object sender, EventArgs e) {
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument(); //Assumes the
default printer
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
}
//Event fired for each page to print
private void pd_PrintPage(object sender, PrintPageEventArgs ev) {
float lpp = 0 ;
float yPos = 0 ;
int count = 0 ;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
String line=null;
//Work out the number of lines per page
//Use the MarginBounds on the event to do this
lpp = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ;
yPos = topMargin + (count *
printFont.GetHeight(ev.Graphics));
//Print Preview control will not work.
ev.Graphics.DrawString (TextBoxVoornaam.Text, printFont,
Brushes.Black, leftMargin,
yPos, new StringFormat());
count++;
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (TextBoxAchternaam.Text, printFont,
Brushes.Black, leftMargin,
yPos, new StringFormat());
count++;
ev.HasMorePages = false ;
}
....
}
On Wed, 16 Mar 2005 19:55:43 +0100, Koen Willemse
<[EMAIL PROTECTED]> wrote:
>
> Well,
>
> I'm a bit of a newby when it comes to printing from an application.
> Unfortunately the code from this example isn't really clear for me... If
> anybody has a piece of simple code that just prints a few values from
> textboxes in lines below each other and makes it possible to add a bit of
> formatting to it, please send it to me... I don't know how to go further and
> I really need to print this data from the application.
>
> Thanks everybody,
> Koen
>
> -----Original Message-----
> From: Koen Willemse [mailto:[EMAIL PROTECTED]
> Sent: woensdag 16 maart 2005 19:03
> To: [email protected]
> Subject: RE: [Microsofts_C_Sharp] Re: printing from C#
>
> My apologies... I didn't look carefully... I found the C# source...
>
> Thanks again Chris
>
> -----Original Message-----
> From: Koen Willemse [mailto:[EMAIL PROTECTED]
> Sent: woensdag 16 maart 2005 18:54
> To: [email protected]
> Subject: RE: [Microsofts_C_Sharp] Re: printing from C#
>
> Anybody got examples in C#? Else I'll have to try to change the VB in C#....
>
> Thanks Chris.
>
> -----Original Message-----
> From: Chris Cottrell [mailto:[EMAIL PROTECTED]
> Sent: woensdag 16 maart 2005 18:37
> To: [email protected]
> Subject: Re: [Microsofts_C_Sharp] Re: printing from C#
>
> Try this...
>
> http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsPrinting.aspx
>
> On Wed, 16 Mar 2005 18:28:17 +0100, Koen Willemse
> <[EMAIL PROTECTED]> wrote:
> >
> > It's a form (winform) with these textboxes:
> > TextBoxVoornaam
> > TextBoxAchternaam
> > TextBoxAdres
> >
> > I would like to print the values below each other. The value from
> > TextBoxVoornaam must be printed in bold and 16 pts. The other values in 12
> > pts.
> >
> > I've got a button ButtonPrint which should cause the printaction to start.
> >
> > Is this enough information?
> >
> > Thanks,
> > Koen
> >
> > -----Original Message-----
> > From: ariesim1983 [mailto:[EMAIL PROTECTED]
> > Sent: woensdag 16 maart 2005 17:59
> > To: [email protected]
> > Subject: [Microsofts_C_Sharp] Re: printing from C#
> >
> > --- In [email protected], "Koen Willemse" <K.F.
> > [EMAIL PROTECTED]> wrote:
> > > Hi guys,
> > >
> > > I've got a question. I want to print data that is in textboxes on my
> > form.
> > > Now I can't find a good tutorial or code example for it. Can anybody
> > of you
> > > help me how to do this with some code example on how to do it?
> > >
> > > Hope you can help me. I want to print when I click a certain button
> > on my
> > > form.
> > >
> > > Thanks in advance.
> > > Koen willemse
> >
> > Hi! Can u give me the details of the problems (eg: code,etc)
> >
> > Thanks.
> >
> > Aries
> >
> > Yahoo! Groups Links
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
>
> Yahoo! Groups Links
>
> Yahoo! Groups Links
>
> Yahoo! Groups Links
>
> Yahoo! Groups Links
>
>
>
>
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Microsofts_C_Sharp/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/