I am getting a few compile errors with my new Rectangle()
- I have a windows form with a few text boxes for user input, and a button to print preview. When the button is pressed to print preview, I want the current windows form to display on the page. I am trying to code the values from the text boxes to display in the top left directly above an image that prints at the bottom half of the page. This is the syntax that I have, but I am getting multiple compile errors. What have I set-up incorrectly? I feel like writing text form a win form to a print document should be fairly straightforward, but I am failing!
private void btnPreview_Click(object sender, EventArgs e)
{
PrintPreviewDialog PrintPreviewDlg = new PrintPreviewDialog();
PrintPreviewDlg.ClientSize = new System.Drawing.Size(400, 300);
PrintPreviewDlg.Location = new System.Drawing.Point(29, 29);
PrintPreviewDlg.Name = "PrintPreviewDlg";
PrintPreviewDlg.MinimumSize = new System.Drawing.Size(375, 250);
PrintPreviewDlg.WindowState = FormWindowState.Maximized;
PrintPreviewDlg.UseAntiAlias = true;
dynamic printData = CreatePrintDocument();
printData.DefaultPageSettings.Landscape = true;
PrintPreviewDlg.Document = printData;
PrintPreviewDlg.ShowDialog();
}
printData CreatePrintDocument()
{
printData document = new printData();
document.SetParentCtrl(this);
document.PrintData.txtAssignmentName = MainInstance.txtAssignmentName.Text;
document.PrintData.txtAssignmentNumber = MainInstance.txtAssignmentNumber.Text;
document.PrintData.txtPreparedBy = MainInstance.txtPreparedBy.Text;
document.PrintData.txtAssignmentSection = MainInstance.txtAssignmentSection.Text;
document.PrintData.DocumentName = "Testing Print Functionality";
return document;
}
class printData : PrintDocument
{
Size m_SubHeaderTextFieldSize;
int m_NormalRowHeight = 0;
class DataToPrintData
{
public string txtAssignmentName, txtAssignmentNumber, txtPreparedBy, txtAssignmentSection;
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
//More print specs here
int LeftSubHeadingWidth = 200;
m_SubHeaderTextFieldSize = new Size(LeftSubHeadingWidth, m_NormalRowHeight);
string printData = "Project Name: " + projectNumberTitle + System.Environment.NewLine +
"Prepared By: " + txtPreparedBy + System.Environment.NewLine +
"Assignment Section: " + txtAssignmentSection + System.Environment.NewLine;
e.Graphics.DrawString(e, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0,0, m_SubHeaderTextFieldSize, StringAlignment.Near);
}
}
Try this code: