c#做小票打印机的应用程序,不知道安装了驱动,用的时usb001端口,不知道怎么连接,求大神帮助。。。

急用!!!谢谢了... 急用!!!谢谢了 展开
 我来答
匿名用户
2014-08-12
展开全部
将小票打印机设置成默认的打印机,然后用Stream 流,下面连接的就是小票打印机打印rdlc报表,完全可以使用,你可以自己改改用调用的是PPrint()就行

#region 报表自打印
public void PPrint()
{
try
{
LocalReport report = this.reportViewer1.LocalReport;
Export(report);
m_currentPageIndex = 0;
NBPrint();
if (m_streams != null)
{
foreach (Stream stream in m_streams)
stream.Close();
m_streams = null;
}
}
catch (Exception ex)
{
MessageBox.Show("在打印过程中出现异常! " + ex.Message.ToString());
}
}
private void Export(LocalReport report)
{
//7.5in 3.66in 0 0 0 0 当前设置为A4纵向
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>72.1mm</PageWidth>" +
" <PageHeight>250mm</PageHeight>" +
" <MarginTop>0in</MarginTop>" +
" <MarginLeft>0in</MarginLeft>" +
" <MarginRight>0in</MarginRight>" +
" <MarginBottom>0in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream, out warnings);

foreach (Stream stream in m_streams)
{
stream.Position = 0;
return;
}
}
private void NBPrint()
{
if (m_streams == null || m_streams.Count == 0)
return;
PrintDocument printDoc = new PrintDocument();

if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format("Can't find printer \"{0}\".", "默认打印机!");
MessageBox.Show(msg, "找不到默认打印机");
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
this.Close();
}
private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
{
string filenameext = DateTime.Now.Year.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
if (m_streams.Count > 1)
{
m_streams.RemoveAt((int)1);
}
return stream;
}
private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, ev.PageBounds);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
#endregion
追问
虽然还有试过,但是还是谢谢。。。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式