473,486 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3807
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
14267
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 maximize it. Thanks!
2
5838
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 printed, but when I click the print icon, it prints a...
3
22910
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 programatically. Sample code will help a lot. Moreover, what...
0
1569
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 on this form it prints one blank page and no text....
1
4389
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, but can someone help me with the call to preset...
1
5681
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 but it does not allow previewing and the...
0
1550
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 Print button on the dialog, it prints one blank...
2
9822
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 would like to capture a click on that button so...
1
1631
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 printPreviewDialog on a form. I cannot get it...
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
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
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
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
5439
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,...
1
4870
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...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.