本文整理汇总了C#中System.Windows.Forms.PageSetupDialog.PageSettings属性的典型用法代码示例。如果您正苦于以下问题:C# PageSetupDialog.PageSettings属性的具体用法?C# PageSetupDialog.PageSettings怎么用?C# PageSetupDialog.PageSettings使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.PageSetupDialog
的用法示例。
在下文中一共展示了PageSetupDialog.PageSettings属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button1_Click
//This method displays a PageSetupDialog object. If the
// user clicks OK in the dialog, selected results of
// the dialog are displayed in ListBox1.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
// Initialize the dialog's PrinterSettings property to hold user
// defined printer settings.
PageSetupDialog1.PageSettings =
new System.Drawing.Printing.PageSettings();
// Initialize dialog's PrinterSettings property to hold user
// set printer settings.
PageSetupDialog1.PrinterSettings =
new System.Drawing.Printing.PrinterSettings();
//Do not show the network in the printer dialog.
PageSetupDialog1.ShowNetwork = false;
//Show the dialog storing the result.
DialogResult result = PageSetupDialog1.ShowDialog();
// If the result is OK, display selected settings in
// ListBox1. These values can be used when printing the
// document.
if (result == DialogResult.OK)
{
object[] results = new object[]{
PageSetupDialog1.PageSettings.Margins,
PageSetupDialog1.PageSettings.PaperSize,
PageSetupDialog1.PageSettings.Landscape,
PageSetupDialog1.PrinterSettings.PrinterName,
PageSetupDialog1.PrinterSettings.PrintRange};
ListBox1.Items.AddRange(results);
}
}
示例2: Font
//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
public class Form1 : Form {
private Font mainTextFont = new Font("Times New Roman", 14);
private Font subTextFont = new Font("Times New Roman", 12);
private PageSettings storedPageSettings;
public Form1() {
InitializeComponent();
}
private void PaintDocument(Graphics g) {
g.PageUnit = GraphicsUnit.Point;
g.DrawString("Simple Printing Sample",
this.mainTextFont,
Brushes.Black,
new Rectangle(10, 20, 180, 30));
g.DrawRectangle(Pens.Blue, new Rectangle(new Point(10, 100), new Size(100, 50)));
}
private void Form1_Paint(object sender, PaintEventArgs e) {
Graphics g = e.Graphics;
PaintDocument(g);
}
private void menuFilePageSetup_Click(object sender, EventArgs e) {
try {
PageSetupDialog psDlg = new PageSetupDialog();
if (this.storedPageSettings == null)
this.storedPageSettings = new PageSettings();
psDlg.PageSettings = this.storedPageSettings;
psDlg.ShowDialog();
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
protected void PrintPageEventHandler(Object obj, PrintPageEventArgs ev) {
Graphics g = ev.Graphics;
PaintDocument(g);
ev.HasMorePages = false;
}
private void menuFilePrint_Click(object sender, EventArgs e) {
try {
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.PrintPageEventHandler);
if (this.storedPageSettings != null)
pd.DefaultPageSettings = this.storedPageSettings;
PrintDialog dlg = new PrintDialog();
dlg.Document = pd;
DialogResult result = dlg.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
pd.Print();
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e) {
try {
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.PrintPageEventHandler);
if (this.storedPageSettings != null)
pd.DefaultPageSettings = this.storedPageSettings;
PrintPreviewDialog dlg = new PrintPreviewDialog();
dlg.Document = pd;
dlg.ShowDialog();
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void InitializeComponent() {
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.menuFilePrintPreview = new System.Windows.Forms.ToolStripMenuItem();
this.menuFilePageSetup = new System.Windows.Forms.ToolStripMenuItem();
this.printPreviewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuFilePrint = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuFilePrintPreview});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Size = new System.Drawing.Size(292, 25);
this.menuStrip1.Text = "menuStrip1";
this.menuFilePrintPreview.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuFilePageSetup,
this.printPreviewToolStripMenuItem,
this.menuFilePrint});
this.menuFilePrintPreview.Name = "menuFilePrintPreview";
this.menuFilePrintPreview.Text = "File";
this.menuFilePageSetup.Name = "menuFilePageSetup";
this.menuFilePageSetup.Text = "Page Setup";
this.menuFilePageSetup.Click += new System.EventHandler(this.menuFilePageSetup_Click);
this.printPreviewToolStripMenuItem.Name = "printPreviewToolStripMenuItem";
this.printPreviewToolStripMenuItem.Text = "Print Preview";
this.printPreviewToolStripMenuItem.Click += new System.EventHandler(this.printPreviewToolStripMenuItem_Click);
this.menuFilePrint.Name = "menuFilePrint";
this.menuFilePrint.Text = "Print";
this.menuFilePrint.Click += new System.EventHandler(this.menuFilePrint_Click);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(292, 268);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.menuStrip1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem menuFilePrintPreview;
private System.Windows.Forms.ToolStripMenuItem menuFilePageSetup;
private System.Windows.Forms.ToolStripMenuItem printPreviewToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem menuFilePrint;
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}