【发布时间】:2017-09-02 22:20:11
【问题描述】:
背后的故事是,为了组织我的代码,我创建了一个名为 Printing.cs 的新类,并将我的代码从我的 main.cs 中转储到那里。
在我的designer.cs 我有这个:this.DVPrintDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.DVPrintDocument_PrintPage);我收到一条错误消息,说不包含定义并且没有找到扩展方法。我怎样才能让 Designer.cs 可以访问其他类?
这是我想让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#,但这是我学校班级的项目。任何帮助将不胜感激!
【问题讨论】:
-
你在printing.cs中添加了designer.cs的命名空间吗?
-
不,据我所知,我认为我做不到。如果我错了,请纠正我? @VijayanathViswanathan
-
如果你的两个类在同一个程序集中,请添加designer.cs的命名空间。如果不在同一个程序集中,请添加库引用并添加命名空间。
-
你能给我看一些代码吗?因为可视化帮助我更好地@VijayanathViswanathan
标签: c# winforms printing print-preview