| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2298 人关注过本帖
标题:ASP.NET ,用C#语言如何实现打印功能,请教高手
只看楼主 加入收藏
dyj05
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-10-24
收藏
 问题点数:0 回复次数:15 
ASP.NET ,用C#语言如何实现打印功能,请教高手
我在编写图纸管理系统中,想要实现相关管理信息及图纸的打印功能,
用的是技术与C#语言
有高手能提供 原代码
拜托拜托!!!!
搜索更多相关主题的帖子: NET 语言 ASP 功能 
2005-10-24 17:13
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
是不是和c#中的print功能一样?

<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2005-10-24 22:52
dyj05
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-10-24
收藏
得分:0 
是,但我不知道如何实现,能否给段代码看看
谢谢!
2005-10-25 10:45
梦幻情缘
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:769
专家分:20
注 册:2005-4-4
收藏
得分:0 
现在网上有很多的类库,你不必去编写代码,只需要引用类库就行了。

打印也有这样的控件,你可以到网上去看一看
2005-10-25 22:03
dyj05
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-10-24
收藏
得分:0 
谢了,不过还是不会 在问一个郁闷的问题,改了好几天了,找不到答案,帮看看,谢谢!

“/工程图纸档案管理系统”应用程序中的服务器错误。

指定的转换无效。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 指定的转换无效。 源错误:
行 128:            //sqlCmd.Parameters .Add ("userName",SqlDbType.VarChar  ,16);
行 129:        
行 130:            sqlCmd.Parameters ["@工程名称"].Value = ((TextBox)e.Item .Cells [1].Controls [0]).Text ;
行 131:            
行 132:            
源文件: c:\inetpub\wwwroot\工程图纸档案管理系统\图纸管理\editproject.aspx.cs 行: 130 堆栈跟踪:
[InvalidCastException: 指定的转换无效。]
   工程图纸档案管理系统.图纸管理.EditProject.DataGrid1_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\工程图纸档案管理系统\图纸管理\editproject.aspx.cs:130
   System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +109
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +507
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +106
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
   System.Web.UI.Page.ProcessRequestMain() +1277

版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
<!-- [InvalidCastException]: 指定的转换无效。 at 工程图纸档案管理系统.图纸管理.EditProject.DataGrid1_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\工程图纸档案管理系统\图纸管理\editproject.aspx.cs:line 130 at System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) at System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain() [HttpUnhandledException]: 发生类型为 System.Web.HttpUnhandledException 的异常。 at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain() at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
2005-10-25 22:57
dyj05
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-10-24
收藏
得分:0 
新手,请多多关照,一定回答哟!
2005-10-25 23:00
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
以下是引用dyj05在2005-10-25 10:45:19的发言: 是,但我不知道如何实现,能否给段代码看看 谢谢!
using System ; using System.Drawing ; using System.Collections ; using System.ComponentModel ; using System.Windows.Forms ; using System.Data ; using System.IO ; using System.Drawing.Printing ; public class Form1 : Form { private RichTextBox richTextBox1 ; private Button button1 ; private Button button2 ; private Button button3 ; private Button button4 ; private Button button5 ; private OpenFileDialog openFileDialog1 ; private SaveFileDialog saveFileDialog1 ; private PrintDialog printDialog1 ; private PrintDocument ThePrintDocument ; private PrintPreviewDialog printPreviewDialog1 ; private StringReader myReader ; private System.ComponentModel.Container components = null ; public Form1 ( ) { //初始化窗体中的各个组件 InitializeComponent ( ) ; } //清除程序中使用多的资源 protected override void Dispose ( bool disposing ) { if ( disposing ) { if ( components != null ) { components.Dispose ( ) ; } } base.Dispose ( disposing ) ; } private void InitializeComponent ( ) { richTextBox1 = new RichTextBox ( ) ; button1 = new Button ( ) ; button2 = new Button ( ) ; button3 = new Button ( ) ; button4 = new Button ( ) ; button5 = new Button ( ) ; saveFileDialog1 = new SaveFileDialog ( ) ; openFileDialog1 = new OpenFileDialog ( ) ; printPreviewDialog1 = new PrintPreviewDialog ( ) ; printDialog1 = new PrintDialog ( ) ; ThePrintDocument = new PrintDocument ( ) ; ThePrintDocument.PrintPage += new PrintPageEventHandler ( ThePrintDocument_PrintPage ) ; SuspendLayout ( ) ; richTextBox1.Anchor = AnchorStyles.None ; richTextBox1.Name = "richTextBox1" ; richTextBox1.Size = new Size ( 448 , 280 ) ; richTextBox1.TabIndex = 0 ; richTextBox1.Text = "" ; button1.Anchor = AnchorStyles.None ; button1.Location = new Point ( 41 , 289 ) ; button1.Name = "button1" ; button1.Size = new Size ( 48 , 30 ) ; button1.TabIndex = 1 ; button1.Text = "打开" ; button1.Click += new System.EventHandler ( button1_Click ) ; button2.Anchor = AnchorStyles.None ; button2.Location = new Point ( 274 , 288 ) ; button2.Name = "button2" ; button2.Size = new Size ( 48 , 30 ) ; button2.TabIndex = 4 ; button2.Text = "预览" ; button2.Click += new System.EventHandler ( button2_Click ) ; button3.Anchor = AnchorStyles.None ; button3.Location = new Point ( 108 , 288 ) ; button3.Name = "button3" ; button3.Size = new Size ( 48 , 30 ) ; button3.TabIndex = 2 ; button3.Text = "保存" ; button3.Click += new System.EventHandler ( button3_Click ) ; button4.Anchor = AnchorStyles.None ; button4.Location = new Point ( 174 , 288 ) ; button4.Name = "button4" ; button4.Size = new Size ( 80 , 30 ) ; button4.TabIndex = 3 ; button4.Text = "打印机设置" ; button4.Click += new System.EventHandler ( button4_Click ) ; button5.Anchor = AnchorStyles.None ; button5.Location = new Point ( 345 , 288 ) ; button5.Name = "button5" ; button5.Size = new Size ( 48 , 30 ) ; button5.TabIndex = 5 ; button5.Text = "打印" ; button5.Click += new System.EventHandler ( button5_Click ) ; saveFileDialog1.DefaultExt = "*.txt" ; saveFileDialog1.FileName = "file.txt" ; saveFileDialog1.InitialDirectory = "c:\\" ; saveFileDialog1.Title = "另存为!" ; openFileDialog1.DefaultExt = "*.txt" ; openFileDialog1.FileName = "file.txt" ; openFileDialog1.InitialDirectory = "c:\\" ; openFileDialog1.Title = "打开文本文件!" ; AutoScaleBaseSize = new Size ( 6 , 14 ) ; ClientSize = new Size ( 448 , 325 ) ; this.Controls.Add ( button1 ) ; this.Controls.Add ( button2 ) ; this.Controls.Add ( button3 ) ; this.Controls.Add ( button4 ) ; this.Controls.Add ( button5 ) ; this.Controls.Add ( richTextBox1 ) ; this.MaximizeBox = false ; this.Name = "Form1" ; this.Text = "C#来操作文本文件" ; this.ResumeLayout ( false ) ; } static void Main ( ) { Application.Run ( new Form1 ( ) ) ; } private void button1_Click ( object sender , System.EventArgs e ) { try { if ( openFileDialog1.ShowDialog ( ) == DialogResult.OK ) { FileStream fs = new FileStream ( openFileDialog1.FileName , FileMode.Open , FileAccess.Read ) ; StreamReader m_streamReader = new StreamReader ( fs ) ; //使用StreamReader类来读取文件 m_streamReader.BaseStream.Seek ( 0 , SeekOrigin.Begin ) ; // 从数据流中读取每一行,直到文件的最后一行,并在richTextBox1中显示出内容 this.richTextBox1.Text = "" ; string strLine = m_streamReader.ReadLine ( ) ; while ( strLine != null ) { this.richTextBox1.Text += strLine + "\n" ; strLine = m_streamReader.ReadLine ( ) ; } //关闭此StreamReader对象 m_streamReader.Close ( ) ; } } catch ( Exception em ) { Console.WriteLine ( em.Message.ToString ( ) ) ; } } private void button3_Click ( object sender , System.EventArgs e ) { try { //获得另存为的文件名称 if ( saveFileDialog1.ShowDialog ( ) == DialogResult.OK ) { //创建一个文件流,用以写入或者创建一个StreamWriter FileStream fs = new FileStream ( @saveFileDialog1.FileName , FileMode.OpenOrCreate , FileAccess.Write ) ; StreamWriter m_streamWriter = new StreamWriter ( fs ) ; m_streamWriter.Flush ( ) ; // 使用StreamWriter来往文件中写入内容 m_streamWriter.BaseStream.Seek ( 0 , SeekOrigin.Begin ) ; // 把richTextBox1中的内容写入文件 m_streamWriter.Write ( richTextBox1.Text ) ; //关闭此文件 m_streamWriter.Flush ( ) ; m_streamWriter.Close ( ) ; } } catch ( Exception em ) { Console.WriteLine ( em.Message.ToString ( ) ) ; } } private void button4_Click ( object sender , System.EventArgs e ) { printDialog1.Document = ThePrintDocument ; printDialog1.ShowDialog ( ) ; } //预览打印文档 private void button2_Click ( object sender , System.EventArgs e ) { try { string strText = richTextBox1.Text ; myReader = new StringReader ( strText ) ; PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog ( ) ; printPreviewDialog1.Document = ThePrintDocument ; printPreviewDialog1.FormBorderStyle = FormBorderStyle.Fixed3D ; printPreviewDialog1.ShowDialog ( ) ; } catch ( Exception exp ) { Console.WriteLine ( exp.Message.ToString ( ) ) ; } } //打印richTextBox1中的内容 private void button5_Click ( object sender , System.EventArgs e ) { printDialog1.Document = ThePrintDocument ; string strText = richTextBox1.Text ; myReader = new StringReader ( strText ) ; if ( printDialog1.ShowDialog ( ) == DialogResult.OK ) { ThePrintDocument.Print ( ) ; } } protected void ThePrintDocument_PrintPage ( object sender , PrintPageEventArgs ev ) { float linesPerPage = 0 ; float yPosition = 0 ; int count = 0 ; float leftMargin = ev.MarginBounds.Left ; float topMargin = ev.MarginBounds.Top ; string line = null ; Font printFont = richTextBox1.Font ; SolidBrush myBrush = new SolidBrush ( Color.Black ) ; //计算每一页打印多少行 linesPerPage = ev.MarginBounds.Height / printFont.GetHeight ( ev.Graphics ) ; //重复使用StringReader对象 ,打印出richTextBox1中的所有内容 while ( count < linesPerPage && ( ( line = myReader.ReadLine ( ) ) != null ) ) { // 计算出要打印的下一行所基于页面的位置 yPosition = topMargin + ( count * printFont.GetHeight ( ev.Graphics ) ) ; // 打印出richTextBox1中的下一行内容 ev.Graphics.DrawString ( line , printFont , myBrush , leftMargin , yPosition , new StringFormat ( ) ) ; count++ ; } // 判断如果还要下一页,则继续打印 if ( line != null ) ev.HasMorePages = true ; else ev.HasMorePages = false ; myBrush.Dispose ( ) ; } }

[此贴子已经被作者于2005-10-26 13:58:15编辑过]


<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2005-10-26 13:56
dyj05
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-10-24
收藏
得分:0 
谢谢,但我的是Web Form 这个好象不行把
能否帮我看看上面的问题,我急用,先谢了
2005-10-26 16:50
5151591
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2005-9-28
收藏
得分:0 
学习.

2005-10-26 17:40
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
以下是引用dyj05在2005-10-26 16:50:59的发言: 谢谢,但我的是Web Form 这个好象不行把 能否帮我看看上面的问题,我急用,先谢了

<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2005-10-26 19:05
快速回复:ASP.NET ,用C#语言如何实现打印功能,请教高手
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013852 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved