I am aware that the class PageSetupDialog can’t be inherited but according to the article I linked to in my initial question you can supply a custom template to add controls to the PageSetupDialog but it’s all C++ structures and I’m not used to working with them.
As to what I’m trying to do, here is a little test app I through together that demonstrates what I want to do. I haven’t provided code for 2 of the check boxes but I want all 4 to appear on the PageSetupDialog and not on the form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.IO;
using System.Collections;
namespace PrintingJPGsTestapp
{
public partial class frmPrintJPGsTestApp : Form
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem printToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem pageSetupToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem printPreviewToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem printToolStripMenuItem1;
private PrintDocument printDoc = new PrintDocument();
private PageSettings pgSettings = new PageSettings();
private Button btnBrowse;
private TextBox textBox1;
private CheckBox chkFitToPage;
private CheckBox chkCenter;
private CheckBox chkOrient;
private CheckBox chkSave;
private Button btnPrint;
private Button btnExit;
private OpenFileDialog openFileDialog1;
private PrinterSettings prtSettings = new PrinterSettings();
Image PicToPrint;
public frmPrintJPGsTestApp()
{
InitializeComponent();
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pageSetupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.printPreviewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.printToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.btnBrowse = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.chkFitToPage = new System.Windows.Forms.CheckBox();
this.chkCenter = new System.Windows.Forms.CheckBox();
this.chkOrient = new System.Windows.Forms.CheckBox();
this.chkSave = new System.Windows.Forms.CheckBox();
this.btnPrint = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.printToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(504, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.exitToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
this.fileToolStripMenuItem.Text = "&File";
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
this.exitToolStripMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
this.printToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.pageSetupToolStripMenuItem,
this.printPreviewToolStripMenuItem,
this.printToolStripMenuItem1});
this.printToolStripMenuItem.Name = "printToolStripMenuItem";
this.printToolStripMenuItem.Size = new System.Drawing.Size(41, 20);
this.printToolStripMenuItem.Text = "Print";
this.pageSetupToolStripMenuItem.Name = "pageSetupToolStripMenuItem";
this.pageSetupToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.pageSetupToolStripMenuItem.Text = "Page Set&up...";
this.pageSetupToolStripMenuItem.Click += new System.EventHandler(this.filePageSetupMenuItem_Click);
this.printPreviewToolStripMenuItem.Name = "printPreviewToolStripMenuItem";
this.printPreviewToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.printPreviewToolStripMenuItem.Text = "Print Pre&view";
this.printPreviewToolStripMenuItem.Click += new System.EventHandler(this.filePrintPreviewMenuItem_Click);
this.printToolStripMenuItem1.Name = "printToolStripMenuItem1";
this.printToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
this.printToolStripMenuItem1.Text = "&Print...";
this.printToolStripMenuItem1.Click += new System.EventHandler(this.filePrintMenuItem_Click);
this.btnBrowse.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnBrowse.Location = new System.Drawing.Point(456, 43);
this.btnBrowse.Name = "btnBrowse";
this.btnBrowse.Size = new System.Drawing.Size(31, 24);
this.btnBrowse.TabIndex = 1;
this.btnBrowse.Text = "...";
this.btnBrowse.UseVisualStyleBackColor = true;
this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
this.textBox1.Location = new System.Drawing.Point(15, 43);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(441, 20);
this.textBox1.TabIndex = 2;
this.chkFitToPage.AutoSize = true;
this.chkFitToPage.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.chkFitToPage.Location = new System.Drawing.Point(15, 77);
this.chkFitToPage.Name = "chkFitToPage";
this.chkFitToPage.Size = new System.Drawing.Size(83, 17);
this.chkFitToPage.TabIndex = 3;
this.chkFitToPage.Text = "Fit To Page";
this.chkFitToPage.UseVisualStyleBackColor = true;
this.chkCenter.AutoSize = true;
this.chkCenter.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.chkCenter.Location = new System.Drawing.Point(15, 100);
this.chkCenter.Name = "chkCenter";
this.chkCenter.Size = new System.Drawing.Size(63, 17);
this.chkCenter.TabIndex = 4;
this.chkCenter.Text = "Center";
this.chkCenter.UseVisualStyleBackColor = true;
this.chkOrient.AutoSize = true;
this.chkOrient.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.chkOrient.Location = new System.Drawing.Point(104, 77);
this.chkOrient.Name = "chkOrient";
this.chkOrient.Size = new System.Drawing.Size(183, 17);
this.chkOrient.TabIndex = 5;
this.chkOrient.Text = "Orient by Picture Dimensions";
this.chkOrient.UseVisualStyleBackColor = true;
this.chkSave.AutoSize = true;
this.chkSave.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.chkSave.Location = new System.Drawing.Point(104, 100);
this.chkSave.Name = "chkSave";
this.chkSave.Size = new System.Drawing.Size(150, 17);
this.chkSave.TabIndex = 6;
this.chkSave.Text = "Save as Default settings";
this.chkSave.UseVisualStyleBackColor = true;
this.btnPrint.Location = new System.Drawing.Point(293, 84);
this.btnPrint.Name = "btnPrint";
this.btnPrint.Size = new System.Drawing.Size(82, 32);
this.btnPrint.TabIndex = 7;
this.btnPrint.Text = "&Print";
this.btnPrint.UseVisualStyleBackColor = true;
this.btnPrint.Click += new System.EventHandler(this.filePrintMenuItem_Click);
this.btnExit.Location = new System.Drawing.Point(405, 85);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(82, 32);
this.btnExit.TabIndex = 8;
this.btnExit.Text = "E&xit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
this.openFileDialog1.FileName = "openFileDialog1";
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(504, 140);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnPrint);
this.Controls.Add(this.chkSave);
this.Controls.Add(this.chkOrient);
this.Controls.Add(this.chkCenter);
this.Controls.Add(this.chkFitToPage);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.btnBrowse);
this.Controls.Add(this.menuStrip1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MainMenuStrip = this.menuStrip1;
this.Name = "frmPrintJPGsTestApp";
this.Text = "Printing JPGs Test App";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)
{
int leftMargin = e.MarginBounds.Left;
int topMargin = e.MarginBounds.Top;
int PrintWidth = e.MarginBounds.Right - e.MarginBounds.Left;
int PrintHieght = e.MarginBounds.Bottom - e.MarginBounds.Top;
int lWidth = 0;
int lHeight = 0;
int lnewWidth = 0;
int lnewHeight = 0;
if (this.chkFitToPage.Checked)
{
try
{
lWidth = PicToPrint.Width;
lHeight = PicToPrint.Height;
lnewWidth = PrintWidth;
lnewHeight = (int)(lHeight * ((double)lnewWidth / (double)lWidth));
if (lnewHeight > PrintHieght)
{
lnewHeight = PrintHieght;
lnewWidth = (int)(lWidth * ((double)lnewHeight / (double)lHeight));
}
}
catch (Exception e2)
{
MessageBox.Show(e2.Message, "Error Resizing Image", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (this.chkCenter.Checked)
{
}
if (this.chkSave.Checked)
{
}
}
if (this.chkFitToPage.Checked)
{
try
{
e.Graphics.DrawImage(PicToPrint, leftMargin, topMargin, lnewWidth, lnewHeight);
}
catch (Exception e2)
{
MessageBox.Show(e2.Message, "Error Printing Image", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
else
{
try
{
e.Graphics.DrawImage(PicToPrint, leftMargin, topMargin);
}
catch (Exception e2)
{
MessageBox.Show(e2.Message, "Error Printing Image", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
}
private void LoadImage()
{
try
{
PicToPrint = Image.FromStream(new MemoryStream(System.IO.File.ReadAllBytes(this.textBox1.Text)));
}
catch (Exception e2)
{
MessageBox.Show(e2.Message, "Picture Load Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (this.chkOrient.Checked)
{
if (PicToPrint.Width > PicToPrint.Height)
{
pgSettings.Landscape = true;
}
else
{
pgSettings.Landscape = false;
}
}
}
private void filePrintMenuItem_Click(Object sender, EventArgs e)
{
LoadImage();
printDoc.DefaultPageSettings = pgSettings;
PrintDialog dlg = new PrintDialog();
dlg.Document = printDoc;
if (dlg.ShowDialog() == DialogResult.OK)
{
printDoc.Print();
}
}
private void filePrintPreviewMenuItem_Click(Object sender, EventArgs e)
{
LoadImage();
PrintPreviewDialog dlg = new PrintPreviewDialog();
printDoc.DefaultPageSettings = pgSettings;
dlg.Document = printDoc;
dlg.ShowDialog();
}
private void filePageSetupMenuItem_Click(Object sender, EventArgs e)
{
PageSetupDialog pageSetupDialog = new PageSetupDialog();
pageSetupDialog.PageSettings = pgSettings;
pageSetupDialog.PrinterSettings = prtSettings;
pageSetupDialog.AllowOrientation = true;
pageSetupDialog.AllowMargins = true;
pageSetupDialog.ShowDialog();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "JPGs (.jpg)|*.jpg";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
this.textBox1.Text = openFileDialog1.FileName;
}
}
}
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmPrintJPGsTestApp());
}
}
}