主要有哪些方法实现打印?
打印控件? 报表?
打印控件? 报表?
解决方案 »
- C#正则表达式问题
- win2003 无法访问asmx文件
- winForm界面的事件优先顺序?
- 如何使GridView实现鼠标悬停的时显示全部内容?
- winfrom 调用web service ,如果网络不可用或服务器关闭时。调用将出错,如果捕获异常
- vs2010 DataSet取数来源是存储过程时,无法取到临时表的列信息
- listview 15000条item 对CheckedItems的计算很慢(只check了一条)
- c#
- 如何删除datgrid 的binding
- 一个奇怪的.net的安装问题。安装过程中无任何报错,但运行时,报“该应用程序无法启动。”不知为何。望大虾指教,小第不胜感激。
- 在 c#中把自定义的结构消息体通过udp协议发送到服务器端,如何写这段代码呀? 急!!!
- C# 中,我使用动态在panel上添加按钮,但是效果,总是,按钮被panel覆盖了,请问,
PrintDocument,你想怎么打就怎么打!
就像Delphi下的FastReport
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
//导入在程序中使用到的名称空间
public class Tray : Form
{
private System.ComponentModel.Container components = null ;
private Icon mNetTrayIcon = new Icon ( "Tray.ico" ) ;
private NotifyIcon TrayIcon ;
private ContextMenu notifyiconMnu ; public Tray()
{
//初始化窗体中使用到的组件
InitializeComponent ( ) ;
//初始化托盘程序的各个要素
Initializenotifyicon ( ) ;
}private void Initializenotifyicon ( )
{
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon ( ) ;
TrayIcon.Icon = mNetTrayIcon ;
TrayIcon.Text = "用Visual C#做托盘程序" + "\n" + "作者:马金虎于2001.12.08" ;
TrayIcon.Visible = true ;
TrayIcon.Click += new System.EventHandler ( this.click ) ; //定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;
mnuItms [ 0 ] = new MenuItem ( ) ;
mnuItms [ 0 ] .Text = "用Visual C#做托盘程序!" ;
mnuItms [ 0 ] .Click += new System.EventHandler ( this.showmessage ) ; mnuItms [ 1 ] = new MenuItem ( "-" ) ; mnuItms [ 2 ] = new MenuItem ( ) ;
mnuItms [ 2 ] .Text = "退出系统" ;
mnuItms [ 2 ] .Click += new System.EventHandler ( this.ExitSelect ) ;
mnuItms [ 2 ] .DefaultItem = true ; notifyiconMnu = new ContextMenu ( mnuItms ) ;
TrayIcon.ContextMenu = notifyiconMnu ;
//为托盘程序加入设定好的ContextMenu对象
}
public void click ( object sender , System.EventArgs e )
{
MessageBox.Show ( "Visual C#编写托盘程序中的事件响应" ) ;
}public void showmessage ( object sender , System.EventArgs e )
{
MessageBox.Show ( "你点击了菜单的第一个选项" ) ;
}public void ExitSelect ( object sender , System.EventArgs e )
{
//隐藏托盘程序中的图标
TrayIcon.Visible = false ;
//关闭系统
this.Close ( ) ;
}
//清除程序中使用过的资源
public override void Dispose ( )
{
base.Dispose ( ) ;
if ( components != null )
components.Dispose ( ) ;
}private void InitializeComponent ( )
{
this.SuspendLayout ( ) ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;
this.ClientSize = new System.Drawing.Size ( 320 , 56 ) ;
this.ControlBox = false ;
this.MaximizeBox = false ;
this.MinimizeBox = false ;
this.WindowState = System.Windows.Forms.FormWindowState.Minimized ; this.Name = "tray" ;
this.ShowInTaskbar = false ;
this.Text = "用Visual C#做托盘程序!" ;
this.ResumeLayout ( false ) ;}
static void Main ( )
{
Application.Run ( new Tray ( ) ) ;
}
}
或者在网页上直接打印
导到文件中代码:
Page.Response.Clear();
Page.Response.Buffer= true;
Page.Response.Charset="GB2312";
Page.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
//下面这行很重要, attachment 参数表示作为附件下载,您可以改成 online在线打开
//filename=FileFlow.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc .xls .txt .htm
Page.Response.AppendHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode("DataReport.xls",System.Text.Encoding.GetEncoding("GB2312")));
//System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
//Response.ContentType指定文件类型 可以为application/ms-excel application/ms-word application/ms-txt application/ms-html 或其他浏览器可直接支持文档
Page.Response.ContentType = "application/ms-excel";
Page.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
(控件).RenderControl(oHtmlTextWriter);
Page.Response.Write(oStringWriter.ToString());
Page.Response.End();