469,609 Members | 1,178 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Associating PrintPreviewDialog with TextBox

Hi!

I have a Textbox control on a form and a PrintPreviewDialog.

How on earth can I associate the Textbox control with the
PrintPreviewDialog, so that the text from the Textbox control will show
in the PrintPreviewControl when launching?

Anybody got a clue?

Me.Name

Nov 19 '05 #1
4 3655
Are you asking how to "print" to the print preview?

The simplest solution is to implement fixed position printing and
implement an IDraw interface. Extend the textbox control and add an
IDraw Draw method. At print preview create an array of IDraw objects and
iterate over the array calling Draw on each IDraw object. Each IDraw
object knows its position and prints itself.

http://www.geocities.com/jeff_louie/OOP/oop21.htm

So for a textbox you have a method as:

public bool Draw(IPrintEngine pe,
float xPos,
float yPos,
Graphics g,
RectangleF pageRect,
bool isSimulation)
{
Brush brush;
Font font;
StringFormat stringFormat;
if (this.isUseDocumentProperties)
{
brush= pe.Brush;
font= pe.Font;
stringFormat= pe.StringFormat;
stringFormat.SetTabStops(0.0f,pe.TabStops);
}
else
{
brush= new SolidBrush(this.ForeColor);
font= this.Font;
stringFormat= this.stringFormat;
stringFormat.SetTabStops(0.0f,pe.TabStops);
}
string text= this.Text;

if (this.isReplaceTokens)
{
text= pe.ReplaceTokens(text);
}
text= text.Trim();
if (!this.Multiline)
{
if (!isSimulation)
{
g.DrawString(text,
font,
brush,
new RectangleF(xPos+this.horizontalMargin,
yPos+this.verticalMargin,
(this.CalculateWidth(pe,g)-(this.horizontalMargin*2)),
this.Size.Height),
this.stringFormat);
}
}
else
{
if (!isSimulation)
{
g.DrawString(text,
font,
brush,
new RectangleF(xPos+this.horizontalMargin,
yPos+this.verticalMargin,
this.Size.Width,
this.Size.Height),
this.stringFormat);
}
}
return false;
}

If you are asking about the actual print dialog control, I plead
ignorance :).

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #2
Hi!

I really ment associating text from the Textbox with the PrintPreview
Control. However, I found a very clear and good answer in the given
url.

But, following the example on this page (Chapter 21) for the
PrintPreview control I still get the following message:

"object reference not set to an instance of the object".

Nov 20 '05 #3
Looks like you are just missing a line of code somewhere. What does the
code
look like that is causing the error.

Regards,
Jeff
following the example on this page (Chapter 21) for the

PrintPreview control I still get the following message:

"object reference not set to an instance of the object".<

*** Sent via Developersdex http://www.developersdex.com ***
Nov 20 '05 #4
Sorry it took so long...

ppdlg.Document = pDoc;
ppdlg.ShowDialog();

where ppdlg is the PrintPreview control, pDoc is the PrintDocument
control.

So what do you think I'm missing?

Me.Name

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael A. Covington | last post: by
reply views Thread by Harry J. Smith | last post: by
1 post views Thread by Jack E. Hardie | last post: by
2 posts views Thread by Richard MSL | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.