i need to print the details from different textboxes on an open form.i dont know how to do it. Print button is on the same form.
what is to be done if details from textboxes of different tab pages need to be printed?
please help.
thankyou
i need to print the details from different textboxes on an open form.i dont know how to do it. Print button is on the same form.
what is to be done if details from textboxes of different tab pages need to be printed?
please help.
thankyou
As described, the usual WinForms way is to pull the Text values from the controls (even those on other TabPages) and render them with a PrintDocument in the PrintPage event. TabPages do not hide their child controls from code: you can read someTabPageTextBox.Text regardless of which tab is visible. As asked for more detail and as suggested, MSDN has full docs, but a minimal, practical pattern is below.
A short WinForms pattern — create a PrintDocument, hook its PrintPage event, collect the textbox values before printing, then draw strings onto the page (use PrintPreviewDialog for testing):
private PrintDocument pd = new PrintDocument();
public Form1()
{
InitializeComponent();
pd.PrintPage += Pd_PrintPage;
}
private void printButton_Click(object sender, EventArgs e)
{
// gather values from textboxes (even on other tabs)
pd.Print(); // or use PrintPreviewDialog with pd as Document
}
private void Pd_PrintPage(object sender, PrintPageEventArgs e)
{
var g = e.Graphics;
float y = e.MarginBounds.Top;
var font = new Font("Segoe UI", 10);
g.DrawString("Field1: " + textBox1.Text, font, Brushes.Black, e.MarginBounds.Left, y);
y += font.GetHeight(g) + 6;
g.DrawString("Field2: " + textBoxOnOtherTab.Text, font, Brushes.Black, e.MarginBounds.Left, y);
// handle wrapping/long text with MeasureString and set e.HasMorePages if needed
} If this is an ASP.NET page, printing is a browser action: produce a printable view (separate print-only page or CSS @media print) or generate a PDF for download. The server cannot directly send output to the client printer.
Quick troubleshooting tips: use PrintPreviewDialog while developing; call Graphics.MeasureString to wrap multiline text and implement paging with e.HasMorePages; respect e.MarginBounds; test DPI/font sizes; and if using WPF, use PrintDialog/PrintVisual instead. For API details see the PrintDocument docs and the WinForms printing overview: PrintDocument class and .
Jump to Post— bhagawatshinde 11need more explanation.....
need more explanation.....
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.