http://www.c-sharpcorner.com/uploadfile/mgold/printingw2form09162005061136am/printingw2form.aspx
for (int i = 0; i < this.Controls.Count; i++)
{
// Check if its a TextBox type by comparing to the type of one of the textboxes
if (Controls[i].GetType() == this.Wages.GetType())
{
// Unbox the Textbox
TextBox theText = (TextBox)Controls[i];
// Draw the textbox string at the position of the textbox on the form, scaled to the print page
g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex, theText.Bounds.Top * scaley, new StringFormat());
}
if (Controls[i].GetType() == this.RetirementPlanCheck.GetType())
{
// Unbox the Checkbox
CheckBox theCheck = (CheckBox)Controls[i];
// Draw the checkbox rectangle on the form scaled to the print page
Rectangle aRect = theCheck.Bounds;
g.DrawRectangle(aPen, aRect.Left * scalex, aRect.Top * scaley, aRect.Width * scalex, aRect.Height * scaley);
// If the checkbox is checked, Draw the x inside the checkbox on the form scaled to the print page
if (theCheck.Checked)
{
g.DrawString("x", theCheck.Font, Brushes.Black, theCheck.Left * scalex + 1, theCheck.Top * scaley + 1, new StringFormat());
}
}
}
我将此代码用于打印预览,但它给出了一个错误
if (Controls[i].GetType() == this.RetirementPlanCheck.GetType())//RetirementPlanCheck
和
if (Controls[i].GetType() == this.Wages.GetType())// wages
错误说缺少参考,那么这些参考是什么类型的?请帮我解决这个问题。
错误消息 1.“WindowsFormsApplication1.Sinhala”不包含“Wages”的定义,并且找不到接受“WindowsFormsApplication1.Sinhala”类型的第一个参数的扩展方法“Wages”(您是否缺少 using 指令或程序集引用?) D:\yashpppp_modi\WindowsFormsApplication1\Sinhala.cs 825 51 WindowsFormsApplication1
2.“WindowsFormsApplication1.Sinhala”不包含“RetirementPlanCheck”的定义,并且找不到接受“WindowsFormsApplication1.Sinhala”类型的第一个参数的扩展方法“RetirementPlanCheck”(您是否缺少 using 指令或程序集引用?) D:\yashpppp_modi\WindowsFormsApplication1\Sinhala.cs WindowsFormsApplication1