473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

print in c# the very somple way

I am new to c# and I made a form with different controls like textbox,
labals, groupboxes, radio buttons and so on... I would like to print out the
text of the textbox control and not the contol itself. How would I go about
printing the groupbox control and the readio buttons? Also how can I print
from a mdi form?

I have done the printform vb powerpack and that prints all the controls -
that is not what I want.
Oct 6 '08 #1
2 1247
Freddy. The .NET way is to use a reporting tool. I am use to using a RAD
database that prints out the content of a form without printing the
controls as
you suggest, but this is not the .NET way.

You can write your own print engine and extend the existing controls so
that
they know how to print themselves, even across page breaks. I would do
it for
you, but I am busy building an airplane at the moment :)

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Oct 6 '08 #2
Put on print Button and then write the click event for that
"m_richTextBox"

/// To print the contents of the documents.
public override void btnPrint_Click(object sender, EventArgs
e)
{
try
{
if (m_richTextBox.Text.Trim() != "")
{
m_printDialog.Document = m_printDocument;
string strText = this.m_richTextBox.Text;
m_SReader = new StringReader(strText);
if (m_printDialog.ShowDialog() == DialogResult.OK)
{
this.m_printDocument.Print();
}
base.btnPrint_Click(sender, e);
}
else
{
cusMessageBox.ShowBox("There are no records to
Print.");
}
}
catch (Exception Ex)
{
ErrorPublish(Ex);
cusMessageBox.ShowBox(Ex.Message);
}
}
/// To redirect the contents of the textbox to the window
printer service.
protected void m_printDocument_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs ev)
{
try
{
float linesPerPage = 0;
float yPosition = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
System.Drawing.Font printFont =
this.m_richTextBox.Font;
SolidBrush myBrush = new SolidBrush(Color.Black);
// Work out the number of lines per page, using the
MarginBounds.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
// Iterate over the string using the StringReader,
printing each line.
while (count < linesPerPage && ((line =
m_SReader.ReadLine()) != null))
{
// calculate the next line position based on
// the height of the font according to the
printing device
yPosition = topMargin + (count *
printFont.GetHeight(ev.Graphics));
// draw the next line in the rich edit control
ev.Graphics.DrawString(line, printFont, myBrush,
leftMargin, yPosition, new StringFormat());
count++;
}
// If there are more lines, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
myBrush.Dispose();
}
catch (Exception Ex)
{
ErrorPublish(Ex);
cusMessageBox.ShowBox(Ex.Message);
}
}
Oct 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn'...
5
by: Alan | last post by:
While not rs.eof <td><%=rs("InvoiceNo")%></td> <td><%=rs("Name")%></td> <td><a href="InvoicePrint.asp?WInv=<%=rs("InvoiceNo")%>"></a></td> <td>Print this invoice</td> rs.MoveNext Wend Now...
1
by: Evets Htims | last post by:
This is Access 2003. Have a report that includes three subreports stacked on top of one another (they display order items). In the report On Open I build a recordset (to get a value from a foreign...
4
by: Das | last post by:
Hi All, I want to have a link on the web form. On click it should print the web form. If I use javascript window.print then it displays the Title on the top of the page & URL at the bottom but i...
3
by: Guoqi Zheng | last post by:
Dear sir, Our E-commerce site needs to print out a few 100s invoice a day. I do not know what is the best way to print invoice. Those invoice has to be printed on a very precise position on our...
0
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html ...
7
by: pamela fluente | last post by:
hi, What is the cleanest and effective way to use the PrintDocument object to print directly to a pdf file "myfile.pdf" (with no prompt to the user: just print to file and make pdf) ? Does...
16
by: raylopez99 | last post by:
I am running out of printing paper trying to debug this...it has to be trivial, but I cannot figure it out--can you? Why am I not printing text, but just the initial string "howdy"? On the...
2
by: bob | last post by:
Hi, I have a page that has a collection of things which it passes to a second 'print' page using a session variable. The print page has buttons for moving though the collection and the user ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.