引用C#的自定义类老报错,请指教? 先添加引用你自定义类(dll文件)然后在代码中添加using Pint; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 添加引用了吗,就是把你的写类库生成的dll引入。 没有这个一般是Console.WirteLine() 如果你的自定义类与你的页面不属同一命名空间的话,必须先using,然后才能调用方法和属性 我创建了一个Print类,要在另一个类中引用Print类,但用USING 试了还是报错 如果你没有用using pint的话就用上则可进行引用,如用了的话,具体什么原因将代码贴出来 我的意思是对dll文件添加引用了吗,就是把你的写类库生成的dll引入。 第一个类的代码:using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Data;using System.Windows.Forms;using System.Xml;using System.Drawing.Printing;namespace remoteprint{ /// <summary> /// UserControl1 的摘要说明。 /// </summary> public class PrintControl : System.Windows.Forms.UserControl { private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Label label1; private System.Drawing.Printing.PrintDocument printDocument1; private System.Windows.Forms.PageSetupDialog pageSetupDialog1; private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private void pd_PrintPage(object sender, PrintPageEventArgs ev) { Graphics g = ev.Graphics; bool HasMorePages = false; PrintElement printElement = null; foreach(XmlNode node in doc["root"]["reporttable"].ChildNodes) { printElement = Parser.CreateElement(node);//调用解析器生成相应的对象 try { HasMorePages = printElement.Draw(g);//是否需要分页 } catch(Exception ex) { this.label1.Text = ex.Message; } } //在页底中间输出页码 Font font = new Font("黑体", 12.0f); Brush brush = new SolidBrush(Color.Black); g.DrawString("第 " + Pages.ToString() + " 页", font,brush,ev.MarginBounds.Width / 2 + ev.MarginBounds.Left - 30, ev.PageBounds.Height - 60); if(HasMorePages) { Pages++; } ev.HasMorePages = HasMorePages; } }}第二个:using System;using System.Xml;using System.Drawing;namespace RemotePrint{ public class PrintElement { public PrintElement() { } public virtual bool Draw(Graphics g) { return false; } }}找不到类型或命名空间名称“PrintElement”(是否缺少 using 指令或程序集引用?) 第一个类:namespace remoteprint改成:namespace RemotePrint注意大小写 谢谢timmy3310(tim) ,正如你言 .net操作Excel实现打印预览问题 用C#如何登录QQ 代码设置windows 2003中的文件属性 关于2个XmlDocument 学习C#的几个层次 制作安装盘!!! winForm里面为什么点一个按纽的时构造一个Form实例,并调用show方法显示出来,.再点的话会再显示一个新的(构造一个.) 新年遇到不会的问题,郁闷,大家救命啊~~~ 接口?? C#中 运算符单个"& " 与双个"&&"符号有什么区别? 急急急!马上给分,如何连接一个DBF文件 我想把我家的机器做为WEB服务器,但我用的是ADSL上网没有固定IP地址,请问何解?
添加引用了吗,就是把你的写类库生成的dll引入。
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Xml;
using System.Drawing.Printing;namespace remoteprint
{
/// <summary>
/// UserControl1 的摘要说明。
/// </summary>
public class PrintControl : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label1;
private System.Drawing.Printing.PrintDocument printDocument1;
private System.Windows.Forms.PageSetupDialog pageSetupDialog1;
private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1; /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
Graphics g = ev.Graphics;
bool HasMorePages = false;
PrintElement printElement = null;
foreach(XmlNode node in doc["root"]["reporttable"].ChildNodes)
{
printElement = Parser.CreateElement(node);//调用解析器生成相应的对象
try
{
HasMorePages = printElement.Draw(g);//是否需要分页
}
catch(Exception ex)
{
this.label1.Text = ex.Message;
}
} //在页底中间输出页码
Font font = new Font("黑体", 12.0f);
Brush brush = new SolidBrush(Color.Black);
g.DrawString("第 " + Pages.ToString() + " 页",
font,brush,ev.MarginBounds.Width / 2 + ev.MarginBounds.Left - 30,
ev.PageBounds.Height - 60); if(HasMorePages)
{
Pages++;
}
ev.HasMorePages = HasMorePages;
}
}
}
第二个:
using System;
using System.Xml;
using System.Drawing;namespace RemotePrint
{
public class PrintElement
{
public PrintElement()
{
} public virtual bool Draw(Graphics g)
{
return false;
}
}
}
找不到类型或命名空间名称“PrintElement”(是否缺少 using 指令或程序集引用?)
namespace remoteprint
改成:
namespace RemotePrint注意大小写