472,328 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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 3751
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael A. Covington | last post by:
By default, my PrintPreviewDialog is coming out too small. What is the best way to control its size and position? Ideally, I'd just like to...
2
by: Randy | last post by:
Hello all, I'm trying to print using PrintPreviewDialog. What's happening is that the PrintPreviewDialog shows the correct information to be...
3
by: sachin | last post by:
How to customize PrintPreviewDialog, such that, addition of a new button, change the functionality of existing button should be possible...
0
by: Harry J. Smith | last post by:
I am using the PrintPreviewDialog Window Form from the Toolbox. It displays my RichTextBox contents correctly, but when I click on the Print icon...
1
by: Jack E. Hardie | last post by:
When I call the PrintPreviewDialog, the resulting default window and zoom size are too small to read. I have figured out how to resize the window,...
1
by: Darrell Wesley | last post by:
Is there anyway to hook the PrintDialog to the printer icon on the PrintPreviewDialog? I know that you can print a document using the PrintDialog...
0
by: Nina | last post by:
Hi there, I use PrintPreviewDialog to preview text of a textbox. It shows pages of text very well in PrintpPreviewDialog. But when I click the...
2
by: Richard MSL | last post by:
I am using PrintPreviewDialog to preview a file. There is a button that the user can press, which seems to print the file to the default printer. I...
1
by: inpuarg | last post by:
I have a windows form, there are button , textbox label etc. controls on it. and i can programmatically get each of their names. and i also have a...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.