本文整理匯總了C#中System.Drawing.Printing.PrintDocument類的典型用法代碼示例。如果您正苦於以下問題:C# PrintDocument類的具體用法?C# PrintDocument怎麽用?C# PrintDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PrintDocument類屬於System.Drawing.Printing命名空間,在下文中一共展示了PrintDocument類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: PrintClass
/// <summary>
/// 打印信息的初始化
/// </summary>
/// <param datagrid="DataGridView">打印數據</param>
/// <param PageS="int">紙張大小</param>
/// <param lendscape="bool">是否橫向打印</param>
public PrintClass(DataGridView datagrid, int PageS, bool lendscape)
{
this.datagrid = datagrid;//獲取打印數據
this.PageSheet = PageS;//紙張大小
printdocument = new PrintDocument();//實例化PrintDocument類
pagesetupdialog = new PageSetupDialog();//實例化PageSetupDialog類
pagesetupdialog.Document = printdocument;//獲取當前頁的設置
printpreviewdialog = new PrintPreviewDialog();//實例化PrintPreviewDialog類
printpreviewdialog.Document = printdocument;//獲取預覽文檔的信息
printpreviewdialog.FormBorderStyle = FormBorderStyle.Fixed3D;//設置窗體的邊框樣式
//橫向打印的設置
if (PageSheet >= 0)
{
if (lendscape == true)
{
printdocument.DefaultPageSettings.Landscape = lendscape;//橫向打印
}
else
{
printdocument.DefaultPageSettings.Landscape = lendscape;//縱向打印
}
}
pagesetupdialog.Document = printdocument;
printdocument.PrintPage += new PrintPageEventHandler(this.printdocument_printpage);//事件的重載
}
示例2: bPay_Click
private void bPay_Click(object sender, EventArgs e)
{
DB.Instance.Insert("order", new Parameter("customer_id", cid), new Parameter("dt", DateTime.Now), new Parameter("status", OrderStatus.New));
uint oid = 0;
using (MySqlDataReader reader = DB.Instance.SelectReader("select max(id) from order"))
{
if(reader != null && reader.Read()){
oid = reader.GetUInt32(0);
}
}
foreach (var item in Role.Instance.ShopCart)
{
DB.Instance.Insert("order_inventory", new Parameter("order_id", oid), new Parameter("inventory_id", item.ID), new Parameter("amount", item.Qty));
}
var dr = MessageBox.Show("Order Placed. Would you like to pay now?", "Payment", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
new Payment().ShowDialog();
}
else if(dr == DialogResult.No)
{
var ppd = new PrintPreviewDialog();
PrintDocument pd = new PrintDocument();
ppd.Document = pd;
pd.PrintPage += Pd_PrintPage;
ppd.ShowDialog();
}
}
示例3: PrintOrder
public static void PrintOrder()
{
var doc = new PrintDocument();
doc.PrinterSettings.PrinterName = System.Configuration.ConfigurationManager.AppSettings["PrinterName"];
doc.PrintPage += new PrintPageEventHandler(PrintPage);
doc.Print();
}
示例4: OnEndPage
public override void OnEndPage(
PrintDocument document,
PrintPageEventArgs e
)
{
this.OriginController.OnEndPage(document, e);
}
示例5: PrintClicked
private void PrintClicked(object sender, System.EventArgs e)
{
if (Viewer == null)
{
return;
}
PrintDocument pd = new PrintDocument();
pd.DocumentName = Viewer.SourceFile.LocalPath;
pd.PrinterSettings.FromPage = 1;
pd.PrinterSettings.ToPage = Viewer.PageCount;
pd.PrinterSettings.MaximumPage = Viewer.PageCount;
pd.PrinterSettings.MinimumPage = 1;
pd.DefaultPageSettings.Landscape = Viewer.PageWidth > Viewer.PageHeight ? true : false;
using (PrintDialog dlg = new PrintDialog())
{
dlg.Document = pd;
dlg.AllowSelection = true;
dlg.AllowSomePages = true;
if (dlg.ShowDialog() == DialogResult.OK)
{
Viewer.Print(pd);
}
}
}
示例6: Print
public void Print()
{
try {
_current = 0;
PrintDocument document = new PrintDocument();
document.PrinterSettings = _config.PrinterSettings;
document.PrinterSettings.Collate = true;
document.PrinterSettings.Copies = (short)_session.NumberOfCopies;
//document.DefaultPageSettings.Margins = new Margins(100, 100, 100, 100);
document.DefaultPageSettings.Margins = new Margins(25, 25, 25, 25);
document.QueryPageSettings += OnQueryPageSettings;
document.PrintPage += OnPrintPage;
if (!String.IsNullOrEmpty(_config.PaperSource)) {
foreach (PaperSource source in document.PrinterSettings.PaperSources) {
if (source.SourceName == _config.PaperSource)
document.DefaultPageSettings.PaperSource = source;
}
}
if (_config.PreviewOnly) {
if (Application.OpenForms.Count > 0)
Application.OpenForms[0].BeginInvoke(new WaitCallback(PreviewProc), document);
} else {
document.Print();
}
} catch (Exception ex) {
#if DEBUG
Dicom.Debug.Log.Error("DICOM Print Error: " + ex.ToString());
#else
Dicom.Debug.Log.Error("DICOM Print Error: " + ex.Message);
#endif
}
}
示例7: InitializeComponent
private void InitializeComponent()
{
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
//
//Main DataSet Initialization
//
this.printPreviewDialog1 = new PrintPreviewDialog();
this.maindataset = new SupremeTransport.maindataset();
//
//Table Adapter Initialization
//
this.mainbillTableAdapter = new SupremeTransport.maindatasetTableAdapters.mainbillTableAdapter();
this.billTableAdapter = new SupremeTransport.maindatasetTableAdapters.billTableAdapter();
//
// printDocument1
//
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// printPreviewDialog1
//
this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
this.printPreviewDialog1.Enabled = true;
this.printPreviewDialog1.Name = "printPreviewDialog1";
this.printPreviewDialog1.Visible = false;
}
示例8: Execute
public override void Execute()
{
printDocument = new PrintDocument();
printDocument.OriginAtMargins = true;
printDocument.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
Dictionary<String, Object> paperSettings = Printing.getPaperSettings(grtArguments);
printDocument.DefaultPageSettings.Landscape = (string)paperSettings["orientation"] == "landscape";
// Sizes must be given in inch * 100 (sigh).
int paperWidth = (int)Math.Round((double)paperSettings["width"] / 0.254);
int paperHeight = (int)Math.Round((double)paperSettings["height"] / 0.254);
PaperSize paperSize = new PaperSize("Doesn't matter", paperWidth, paperHeight);
printDocument.DefaultPageSettings.PaperSize = paperSize;
if ((bool)paperSettings["marginsSet"])
printDocument.DefaultPageSettings.Margins =
new Margins((int)paperSettings["marginLeft"], (int)paperSettings["marginRight"],
(int)paperSettings["marginTop"], (int)paperSettings["marginBottom"]);
printDialog = new System.Windows.Forms.PrintDialog();
printDialog.Document = printDocument;
printDialog.AllowPrintToFile = true;
pageNumber = 0;
pageCount = -1;
if (printDialog.ShowDialog() == DialogResult.OK)
{
printDocument.Print();
}
}
示例9: OnStartPrint
public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {
Debug.Assert(dc == null && graphics == null, "PrintController methods called in the wrong order?");
// For security purposes, don't assume our public methods methods are called in any particular order
CheckSecurity(document);
base.OnStartPrint(document, e);
// the win32 methods below SuppressUnmanagedCodeAttributes so assertin on UnmanagedCodePermission is redundant
if (!document.PrinterSettings.IsValid)
throw new InvalidPrinterException(document.PrinterSettings);
dc = document.PrinterSettings.CreateDeviceContext(modeHandle);
SafeNativeMethods.DOCINFO info = new SafeNativeMethods.DOCINFO();
info.lpszDocName = document.DocumentName;
if (document.PrinterSettings.PrintToFile)
info.lpszOutput = document.PrinterSettings.OutputPort; //This will be "FILE:"
else
info.lpszOutput = null;
info.lpszDatatype = null;
info.fwType = 0;
int result = SafeNativeMethods.StartDoc(new HandleRef(this.dc, dc.Hdc), info);
if (result <= 0) {
int error = Marshal.GetLastWin32Error();
if (error == SafeNativeMethods.ERROR_CANCELLED) {
e.Cancel = true;
}
else {
throw new Win32Exception(error);
}
}
}
示例10: Print_button_Click
/* Events to execute when the "Print" button is clicked */
private void Print_button_Click(object sender, EventArgs e)
{
/* Creates a new instance of printDocument, appends the result from PrintDocumentOnPrintPage and prints the result */
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += PrintDocumentOnPrintPage;
printDocument.Print();
}
示例11: axWindowsMediaPlayer1_PlayStateChange
private void axWindowsMediaPlayer1_PlayStateChange(object sender, _WMPOCXEvents_PlayStateChangeEvent e)
{
//QUANDO VIDEO FOR PARADO
if ( axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused )
{
//O VIDEO FOI PARADO, PARA CONTINUAR PRECISA CLICAR EM OK
if ( MessageBox.Show("Video Parado. Clique aqui para continuar!", "",
MessageBoxButtons.OK , MessageBoxIcon.Information) == DialogResult.OK )
{
axWindowsMediaPlayer1.Ctlcontrols.play();
}
}
//QUANDO O VIDEO ACABAR
if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
//IMPRIME
PrintDocument document = new PrintDocument();
document.PrintPage += new PrintPageEventHandler(impressaoConf);
document.Print();
this.Hide();
}
}
示例12: Imprimir
public static void Imprimir(Entidades.Álbum.Álbum álbum, ItensImpressão itens)
{
using (PrintDocument documento = new PrintDocument())
{
documento.DocumentName = "Álbum " + álbum.Nome;
using (PrintDialog dlg = new PrintDialog())
{
dlg.AllowCurrentPage = false;
dlg.AllowSelection = false;
dlg.AllowSomePages = true;
dlg.UseEXDialog = true;
dlg.Document = documento;
if (dlg.ShowDialog() == DialogResult.OK)
{
ControleImpressão ctrl = new ControleImpressão(álbum, itens);
ctrl.página = new Página(
documento.PrinterSettings.DefaultPageSettings.PrintableArea.Width / 100f,
documento.PrinterSettings.DefaultPageSettings.PrintableArea.Height / 100f,
4, 5);
ctrl.daPágina = dlg.PrinterSettings.FromPage;
ctrl.atéPágina = dlg.PrinterSettings.ToPage != 0 ?
dlg.PrinterSettings.ToPage : int.MaxValue;
documento.PrintPage += new PrintPageEventHandler(ctrl.ImprimirPágina);
documento.Print();
}
}
}
}
示例13: button1_Click
private void button1_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += PrintPage;
pd.Print();
this.Close();
}
示例14: createXmlApp
//如下的這個方法可以注釋掉,沒有任何的作用
public void createXmlApp()
{
// 首先創建文件
FileStream fs = File.Create(Application.StartupPath + "\\xmlAPP.xml");
fs.Close();//關閉文件
//創建 XmlDocument 以便操作
XmlDocument xmlDoc = new XmlDocument();
//xml 唯一的根,我設置的根都是root
XmlElement xmlEleRoot = xmlDoc.CreateElement("root");
// 這個配置還有一個是必須的,就是打印機的DPI, 其他的都不是必要的
XmlElement xmlElePrinter = xmlDoc.CreateElement("printer");
//打印機名稱,這裏直接設置默認打印機
PrintDocument printDoc = new PrintDocument();
xmlElePrinter.SetAttribute("PrinterName", printDoc.PrinterSettings.PrinterName);
printDoc.Dispose();//釋放資源
//DPI有兩個
xmlElePrinter.SetAttribute("DPIX", "600");
xmlElePrinter.SetAttribute("DPIY", "600");
//如下是兩個添加操作了
xmlEleRoot.AppendChild(xmlElePrinter);
xmlDoc.AppendChild(xmlEleRoot);
//保存操作
xmlDoc.Save(Application.StartupPath + "\\xmlAPP.xml");
}
示例15: butPrint_Click
private void butPrint_Click(object sender,EventArgs e) {
PrintDocument pd2=new PrintDocument();
pd2.PrintPage+=new PrintPageEventHandler(this.pd2_PrintPage);
pd2.OriginAtMargins=true;
pd2.DefaultPageSettings.Margins=new Margins(0,0,0,0);
pd2.Print();
}