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
エラーは参照が欠落していることを示していますが、それらはどのタイプの参照ですか?この問題を解決するのを手伝ってください。
エラーMSG1.「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