如何让Designer.cs访问C#中的其他类



背景故事是要整理我的代码,我完成了一个名为printing.cs的新类,并将我的代码从我的main.cs.在我的Designer.cs中,我有一个:this.DVPrintDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.DVPrintDocument_PrintPage);我收到一条错误消息,说不包含定义,找不到扩展方法。我该如何制作它,以便Designer.cs可以访问其他类?

这是我想要设计师的类

using static TicketingSystem.TicketingSystem;
namespace TicketingSystem
{
   class Printing
   {
    TicketingSystem ticketingSystem;
        public Printing(TicketingSystem ticketingSystem) => 
this.ticketingSystem = ticketingSystem;

    public void DVPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        Bitmap r3tsLogo = Properties.Resources.rt3slogo;
        Image image1 = r3tsLogo; //image 1 is r3tsLogo
        e.Graphics.DrawImage(image1, 350, 0, image1.Width, image1.Height);
        // e.Graphics.DrawString("Employee Name:" + employee.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 200)); //Put to bottom of paper
        e.Graphics.DrawString("Address:", new Font("Impact", 12, FontStyle.Regular), Brushes.Black, new Point(300, 90));//change the new point to put text on different part of paper.
        e.Graphics.DrawString("Room 61", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(370, 94)); //This line of code connects to Code line 151   
        e.Graphics.DrawString("Email:", new Font("Impact", 12, FontStyle.Regular), Brushes.Black, new Point(300, 120));//change the new point to put text on different part of paper.
        e.Graphics.DrawString("email@email.com", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(350, 124)); //This line of code connects to Code line 154
        e.Graphics.DrawString("Date: " + DateTime.Now, new Font("Arial", 13, FontStyle.Regular), Brushes.Black, new Point(300, 150));
        e.Graphics.DrawString(ticketingSystem.dashes.Text, new Font("Arial", 12), Brushes.Black, new Point(0, 160));
      }

对不起,我仍在学习C#,但这是我学校课程的项目。任何帮助都将不胜感激!

winforms Designer生成了Formxxxx.designer.cs文件,以保持您的用户界面对象并使用您通过Winform Designer界面进行的设置来初始化其属性。

由于Winforms基础结构创建和维护此类文件,因此您不应该尝试添加自己的代码或在此处手动更改任何内容。
(此外,每次更改表单时,此文件都会重写)

因此,您只需要添加事件处理程序 dvprintdocument_printpage 像以前一样。但是,没有人会阻止您在活动处理程序中编写某些内容,以调用印刷类中的代码。

类似这样的东西

在您的主表单中。

public void DVPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
     Printing print = new Printing(ticketingSystem);
     print.PrintPageHandler(sender, e);
}

在您的打印类中

public class Printing
{
    TicketingSystem ticketingSystem;
    public Printing(TicketingSystem ticketingSystem) => 
                    this.ticketingSystem = ticketingSystem;

    public void PrintPageHandler(object sender, PrintPageEventArgs e)
    {
        Bitmap r3tsLogo = Properties.Resources.rt3slogo;
        Image image1 = r3tsLogo; //image 1 is r3tsLogo
        // remainder of your current code 
       .....
    }
}

相关内容

  • 没有找到相关文章

最新更新