1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006 Novell, Inc.
23 // Jonathan Chambers (jonathan.chambers@ansys.com)
27 using System.ComponentModel;
28 using System.ComponentModel.Design;
29 using System.ComponentModel.Design.Serialization;
30 using System.Collections;
31 using System.Diagnostics;
33 using System.Drawing.Printing;
34 using System.Globalization;
35 using System.Reflection;
37 namespace System.Windows.Forms {
39 [DefaultProperty("Document")]
40 public sealed class PageSetupDialog : CommonDialog {
42 #region Local variables
43 private PrintDocument document;
44 private PageSettings page_settings;
45 private PrinterSettings printer_settings;
46 private Margins min_margins;
47 private bool allow_margins;
48 private bool allow_orientation;
49 private bool allow_paper;
50 private bool allow_printer;
51 private bool show_help;
52 private bool show_network;
54 private GroupBox groupbox_paper;
55 private Label label_source;
56 private Label label_size;
57 private GroupBox groupbox_orientation;
58 private RadioButton radio_landscape;
59 private RadioButton radio_portrait;
60 private GroupBox groupbox_margin;
61 private Label label_left;
62 private Button button_help;
63 private Button button_ok;
64 private Button button_cancel;
65 private Button button_printer;
66 private Label label_top;
67 private Label label_right;
68 private Label label_bottom;
69 private NumericTextBox textbox_left;
70 private NumericTextBox textbox_top;
71 private NumericTextBox textbox_right;
72 private NumericTextBox textbox_bottom;
73 private ComboBox combobox_source;
74 private ComboBox combobox_size;
75 private PagePreview pagePreview;
76 #endregion // Local variables
78 #region Public Constructors
79 public PageSetupDialog ()
81 InitializeComponent();
84 #endregion // Public Constructors
87 #region Public Instance Methods
88 public override void Reset ()
91 AllowOrientation = true;
96 MinMargins = new Margins (0, 0, 0, 0);
97 PrinterSettings = null;
101 #endregion // Public Instance Methods
103 #region Public Instance Properties
105 public bool AllowMargins {
106 get { return allow_margins; }
107 set { allow_margins = value; }
111 public bool AllowOrientation {
112 get { return allow_orientation; }
113 set { allow_orientation = value; }
117 public bool AllowPaper {
118 get { return allow_paper; }
119 set { allow_paper = value; }
123 public bool AllowPrinter {
124 get { return allow_printer; }
125 set { allow_printer = value; }
129 public PrintDocument Document {
130 get { return document; }
133 if (document != null) {
134 printer_settings = document.PrinterSettings;
135 page_settings = document.DefaultPageSettings;
140 public Margins MinMargins {
141 get { return min_margins; }
142 set { min_margins = value; }
147 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
148 public PageSettings PageSettings {
149 get { return page_settings; }
151 page_settings = value;
158 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
159 public PrinterSettings PrinterSettings {
160 get { return printer_settings; }
162 printer_settings = value;
167 [DefaultValue(false)]
168 public bool ShowHelp {
169 get { return show_help; }
171 if (value != show_help) {
179 public bool ShowNetwork {
180 get { return show_network; }
181 set { show_network = value; }
184 #endregion // Public Instance Properties
186 #region Protected Instance Methods
187 protected override bool RunDialog (IntPtr hwnd)
190 SetPrinterDetails ();
193 catch (Exception e) {
194 MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
198 #endregion // Protected Instance Methods
200 #region Private Helper
201 private void InitializeComponent()
203 this.groupbox_paper = new System.Windows.Forms.GroupBox();
204 this.combobox_source = new System.Windows.Forms.ComboBox();
205 this.combobox_size = new System.Windows.Forms.ComboBox();
206 this.label_source = new System.Windows.Forms.Label();
207 this.label_size = new System.Windows.Forms.Label();
208 this.groupbox_orientation = new System.Windows.Forms.GroupBox();
209 this.radio_landscape = new System.Windows.Forms.RadioButton();
210 this.radio_portrait = new System.Windows.Forms.RadioButton();
211 this.groupbox_margin = new System.Windows.Forms.GroupBox();
212 this.label_left = new System.Windows.Forms.Label();
213 this.button_ok = new System.Windows.Forms.Button();
214 this.button_cancel = new System.Windows.Forms.Button();
215 this.button_printer = new System.Windows.Forms.Button();
216 this.label_top = new System.Windows.Forms.Label();
217 this.label_right = new System.Windows.Forms.Label();
218 this.label_bottom = new System.Windows.Forms.Label();
219 this.textbox_left = new System.Windows.Forms.NumericTextBox();
220 this.textbox_top = new System.Windows.Forms.NumericTextBox();
221 this.textbox_right = new System.Windows.Forms.NumericTextBox();
222 this.textbox_bottom = new System.Windows.Forms.NumericTextBox();
223 this.pagePreview = new PagePreview ();
224 this.groupbox_paper.SuspendLayout();
225 this.groupbox_orientation.SuspendLayout();
226 this.groupbox_margin.SuspendLayout();
227 form.SuspendLayout();
231 this.groupbox_paper.Controls.Add(this.combobox_source);
232 this.groupbox_paper.Controls.Add(this.combobox_size);
233 this.groupbox_paper.Controls.Add(this.label_source);
234 this.groupbox_paper.Controls.Add(this.label_size);
235 this.groupbox_paper.Location = new System.Drawing.Point(12, 157);
236 this.groupbox_paper.Name = "groupbox_paper";
237 this.groupbox_paper.Size = new System.Drawing.Size(336, 90);
238 this.groupbox_paper.TabIndex = 0;
239 this.groupbox_paper.TabStop = false;
240 this.groupbox_paper.Text = "Paper";
244 this.combobox_source.Location = new System.Drawing.Point(84, 54);
245 this.combobox_source.Name = "combobox_source";
246 this.combobox_source.Size = new System.Drawing.Size(240, 21);
247 this.combobox_source.TabIndex = 3;
251 this.combobox_size.ItemHeight = 13;
252 this.combobox_size.Location = new System.Drawing.Point(84, 22);
253 this.combobox_size.Name = "combobox_size";
254 this.combobox_size.Size = new System.Drawing.Size(240, 21);
255 this.combobox_size.TabIndex = 2;
256 this.combobox_size.SelectedIndexChanged += new EventHandler(this.OnPaperSizeChange);
260 this.label_source.Location = new System.Drawing.Point(13, 58);
261 this.label_source.Name = "label_source";
262 this.label_source.Size = new System.Drawing.Size(48, 16);
263 this.label_source.TabIndex = 1;
264 this.label_source.Text = "&Source:";
268 this.label_size.Location = new System.Drawing.Point(13, 25);
269 this.label_size.Name = "label_size";
270 this.label_size.Size = new System.Drawing.Size(52, 16);
271 this.label_size.TabIndex = 0;
272 this.label_size.Text = "Si&ze:";
274 // groupbox_orientation
276 this.groupbox_orientation.Controls.Add(this.radio_landscape);
277 this.groupbox_orientation.Controls.Add(this.radio_portrait);
278 this.groupbox_orientation.Location = new System.Drawing.Point(12, 255);
279 this.groupbox_orientation.Name = "groupbox_orientation";
280 this.groupbox_orientation.Size = new System.Drawing.Size(96, 90);
281 this.groupbox_orientation.TabIndex = 1;
282 this.groupbox_orientation.TabStop = false;
283 this.groupbox_orientation.Text = "Orientation";
287 this.radio_landscape.Location = new System.Drawing.Point(13, 52);
288 this.radio_landscape.Name = "radio_landscape";
289 this.radio_landscape.Size = new System.Drawing.Size(80, 24);
290 this.radio_landscape.TabIndex = 7;
291 this.radio_landscape.Text = "L&andscape";
292 this.radio_landscape.CheckedChanged += new EventHandler(this.OnLandscapeChange);
296 this.radio_portrait.Location = new System.Drawing.Point(13, 19);
297 this.radio_portrait.Name = "radio_portrait";
298 this.radio_portrait.Size = new System.Drawing.Size(72, 24);
299 this.radio_portrait.TabIndex = 6;
300 this.radio_portrait.Text = "P&ortrait";
304 this.groupbox_margin.Controls.Add(this.textbox_bottom);
305 this.groupbox_margin.Controls.Add(this.textbox_right);
306 this.groupbox_margin.Controls.Add(this.textbox_top);
307 this.groupbox_margin.Controls.Add(this.textbox_left);
308 this.groupbox_margin.Controls.Add(this.label_bottom);
309 this.groupbox_margin.Controls.Add(this.label_right);
310 this.groupbox_margin.Controls.Add(this.label_top);
311 this.groupbox_margin.Controls.Add(this.label_left);
312 this.groupbox_margin.Location = new System.Drawing.Point(120, 255);
313 this.groupbox_margin.Name = "groupbox_margin";
314 this.groupbox_margin.Size = new System.Drawing.Size(228, 90);
315 this.groupbox_margin.TabIndex = 2;
316 this.groupbox_margin.TabStop = false;
317 this.groupbox_margin.Text = LocalizedLengthUnit ();
321 this.label_left.Location = new System.Drawing.Point(11, 25);
322 this.label_left.Name = "label_left";
323 this.label_left.Size = new System.Drawing.Size(40, 23);
324 this.label_left.TabIndex = 0;
325 this.label_left.Text = "&Left:";
329 this.button_ok.Location = new System.Drawing.Point(120, 358);
330 this.button_ok.Name = "button_ok";
331 this.button_ok.Size = new System.Drawing.Size(72, 23);
332 this.button_ok.TabIndex = 3;
333 this.button_ok.Text = "OK";
334 this.button_ok.Click += new EventHandler (OnClickOkButton);
338 this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
339 this.button_cancel.Location = new System.Drawing.Point(198, 358);
340 this.button_cancel.Name = "button_cancel";
341 this.button_cancel.Size = new System.Drawing.Size(72, 23);
342 this.button_cancel.TabIndex = 4;
343 this.button_cancel.Text = "Cancel";
347 this.button_printer.Location = new System.Drawing.Point(276, 358);
348 this.button_printer.Name = "button_printer";
349 this.button_printer.Size = new System.Drawing.Size(72, 23);
350 this.button_printer.TabIndex = 5;
351 this.button_printer.Text = "&Printer...";
352 this.button_printer.Click += new EventHandler (OnClickPrinterButton);
356 this.label_top.Location = new System.Drawing.Point(11, 57);
357 this.label_top.Name = "label_top";
358 this.label_top.Size = new System.Drawing.Size(40, 23);
359 this.label_top.TabIndex = 1;
360 this.label_top.Text = "&Top:";
364 this.label_right.Location = new System.Drawing.Point(124, 25);
365 this.label_right.Name = "label_right";
366 this.label_right.Size = new System.Drawing.Size(40, 23);
367 this.label_right.TabIndex = 2;
368 this.label_right.Text = "&Right:";
372 this.label_bottom.Location = new System.Drawing.Point(124, 57);
373 this.label_bottom.Name = "label_bottom";
374 this.label_bottom.Size = new System.Drawing.Size(40, 23);
375 this.label_bottom.TabIndex = 3;
376 this.label_bottom.Text = "&Bottom:";
380 this.textbox_left.Location = new System.Drawing.Point(57, 21);
381 this.textbox_left.Name = "textbox_left";
382 this.textbox_left.Size = new System.Drawing.Size(48, 20);
383 this.textbox_left.TabIndex = 4;
384 this.textbox_left.TextChanged +=new EventHandler(OnMarginChange);
388 this.textbox_top.Location = new System.Drawing.Point(57, 54);
389 this.textbox_top.Name = "textbox_top";
390 this.textbox_top.Size = new System.Drawing.Size(48, 20);
391 this.textbox_top.TabIndex = 5;
392 this.textbox_top.TextChanged +=new EventHandler(OnMarginChange);
396 this.textbox_right.Location = new System.Drawing.Point(171, 21);
397 this.textbox_right.Name = "textbox_right";
398 this.textbox_right.Size = new System.Drawing.Size(48, 20);
399 this.textbox_right.TabIndex = 6;
400 this.textbox_right.TextChanged +=new EventHandler(OnMarginChange);
404 this.textbox_bottom.Location = new System.Drawing.Point(171, 54);
405 this.textbox_bottom.Name = "textbox_bottom";
406 this.textbox_bottom.Size = new System.Drawing.Size(48, 20);
407 this.textbox_bottom.TabIndex = 7;
408 this.textbox_bottom.TextChanged +=new EventHandler(OnMarginChange);
412 this.pagePreview.Location = new System.Drawing.Point (130, 10);
413 this.pagePreview.Name = "pagePreview";
414 this.pagePreview.Size = new System.Drawing.Size (150, 150);
415 this.pagePreview.TabIndex = 6;
419 form.AcceptButton = this.button_ok;
420 form.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
421 form.CancelButton = this.button_cancel;
422 form.ClientSize = new System.Drawing.Size(360, 390);
423 form.Controls.Add (this.pagePreview);
424 form.Controls.Add (this.button_printer);
425 form.Controls.Add(this.button_cancel);
426 form.Controls.Add(this.button_ok);
427 form.Controls.Add(this.groupbox_margin);
428 form.Controls.Add(this.groupbox_orientation);
429 form.Controls.Add(this.groupbox_paper);
430 form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
431 form.HelpButton = true;
432 form.MaximizeBox = false;
433 form.MinimizeBox = false;
435 form.ShowInTaskbar = false;
436 form.Text = "Page Setup";
437 this.groupbox_paper.ResumeLayout(false);
438 this.groupbox_orientation.ResumeLayout(false);
439 this.groupbox_margin.ResumeLayout(false);
440 form.ResumeLayout(false);
444 static bool UseYardPound {
445 get { return !RegionInfo.CurrentRegion.IsMetric; } }
447 // .Net uses PrinterSettings property if it is not null.
448 // Otherwise, it uses PageSettings.PrinterSettings to set values.
449 // We use this property internally to automatically select the available one.
450 PrinterSettings InternalPrinterSettings {
452 return (printer_settings == null ? page_settings.PrinterSettings :
457 private double ToLocalizedLength (int marginsUnit)
459 return UseYardPound ?
460 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.ThousandthsOfAnInch, PrinterUnit.Display) :
461 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.ThousandthsOfAnInch, PrinterUnit.TenthsOfAMillimeter);
464 private int FromLocalizedLength (double marginsUnit)
466 return (int)(UseYardPound ?
467 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.Display, PrinterUnit.ThousandthsOfAnInch) :
468 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.ThousandthsOfAnInch));
471 private string LocalizedLengthUnit ()
473 return UseYardPound ? "Margins (inches)" : "Margins (millimeters)";
476 private void SetPrinterDetails ()
478 if (PageSettings == null)
479 throw new ArgumentException ("PageSettings");
481 combobox_size.Items.Clear ();
482 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes)
483 combobox_size.Items.Add (paper_size.PaperName);
484 combobox_size.SelectedItem = page_settings.PaperSize.PaperName;
486 combobox_source.Items.Clear ();
487 foreach (PaperSource paper_source in InternalPrinterSettings.PaperSources)
488 combobox_source.Items.Add (paper_source.SourceName);
489 combobox_source.SelectedItem = page_settings.PaperSource.SourceName;
491 if (PageSettings.Landscape)
492 radio_landscape.Checked = true;
494 radio_portrait.Checked = true;
499 Margins page_margins = PageSettings.Margins;
500 Margins min_margins = MinMargins;
502 // Update margin data
503 textbox_top.Text = ToLocalizedLength (page_margins.Top).ToString ();
504 textbox_bottom.Text = ToLocalizedLength (page_margins.Bottom).ToString ();
505 textbox_left.Text = ToLocalizedLength (page_margins.Left).ToString ();
506 textbox_right.Text = ToLocalizedLength (page_margins.Right).ToString ();
507 textbox_top.Min = ToLocalizedLength (min_margins.Top);
508 textbox_bottom.Min = ToLocalizedLength (min_margins.Bottom);
509 textbox_left.Min = ToLocalizedLength (min_margins.Left);
510 textbox_right.Min = ToLocalizedLength (min_margins.Right);
512 button_printer.Enabled = AllowPrinter && PrinterSettings != null;
513 groupbox_orientation.Enabled = AllowOrientation;
514 groupbox_paper.Enabled = AllowPaper;
515 groupbox_margin.Enabled = AllowMargins;
517 pagePreview.Setup (PageSettings);
520 private void OnClickOkButton (object sender, EventArgs e)
522 if (combobox_size.SelectedItem != null) {
523 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes) {
524 if (paper_size.PaperName == (string) combobox_size.SelectedItem) {
525 PageSettings.PaperSize = paper_size;
531 if (combobox_source.SelectedItem != null) {
532 foreach (PaperSource paper_source in InternalPrinterSettings.PaperSources) {
533 if (paper_source.SourceName == (string) combobox_source.SelectedItem) {
534 PageSettings.PaperSource = paper_source;
540 Margins margins = new Margins ();
541 margins.Top = FromLocalizedLength (textbox_top.Value);
542 margins.Bottom = FromLocalizedLength (textbox_bottom.Value);
543 margins.Left = FromLocalizedLength (textbox_left.Value);
544 margins.Right = FromLocalizedLength (textbox_right.Value);
545 PageSettings.Margins = margins;
547 PageSettings.Landscape = radio_landscape.Checked;
548 form.DialogResult = DialogResult.OK;
551 void ShowHelpButton ()
553 if (button_help == null) {
554 button_help = new Button ();
555 button_help.Location = new System.Drawing.Point (12, 358);
556 button_help.Name = "button_help";
557 button_help.Size = new System.Drawing.Size (72, 23);
558 button_help.Text = "&Help";
559 form.Controls.Add (button_help);
562 button_help.Visible = show_help;
565 void OnClickPrinterButton (object sender, EventArgs args)
567 PrinterForm printer_helper_form = new PrinterForm (this);
569 printer_helper_form.UpdateValues ();
571 // Here update values for PrinterSettings
572 if (printer_helper_form.ShowDialog () == DialogResult.OK)
573 if (printer_helper_form.SelectedPrinter != PrinterSettings.PrinterName)
574 PrinterSettings.PrinterName = printer_helper_form.SelectedPrinter;
576 PageSettings = PrinterSettings.DefaultPageSettings;
577 SetPrinterDetails ();
579 printer_helper_form.Dispose ();
582 void OnPaperSizeChange (object sender, EventArgs e)
584 if (combobox_size.SelectedItem != null) {
585 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes) {
586 if (paper_size.PaperName == (string) combobox_size.SelectedItem) {
587 pagePreview.SetSize (paper_size.Width, paper_size.Height);
594 void OnMarginChange (object sender, EventArgs e)
596 pagePreview.SetMargins (
597 FromLocalizedLength (textbox_left.Value),
598 FromLocalizedLength (textbox_right.Value),
599 FromLocalizedLength (textbox_top.Value),
600 FromLocalizedLength (textbox_bottom.Value)
604 void OnLandscapeChange (object sender, EventArgs e)
606 pagePreview.Landscape = radio_landscape.Checked;
608 #endregion // Private Helper
610 class PrinterForm : Form
612 private System.Windows.Forms.GroupBox groupbox_printer;
613 private System.Windows.Forms.ComboBox combobox_printers;
614 private System.Windows.Forms.Label label_name;
615 private System.Windows.Forms.Label label_status;
616 private System.Windows.Forms.Button button_properties;
617 private System.Windows.Forms.Button button_network;
618 private System.Windows.Forms.Button button_cancel;
619 private System.Windows.Forms.Button button_ok;
620 private System.Windows.Forms.Label label_status_text;
621 private System.Windows.Forms.Label label_type;
622 private System.Windows.Forms.Label label_where;
623 private System.Windows.Forms.Label label_where_text;
624 private System.Windows.Forms.Label label_type_text;
625 private System.Windows.Forms.Label label_comment;
626 private System.Windows.Forms.Label label_comment_text;
627 PageSetupDialog page_setup_dialog;
629 public PrinterForm (PageSetupDialog page_setup_dialog)
631 InitializeComponent();
632 this.page_setup_dialog = page_setup_dialog;
635 public string SelectedPrinter {
637 return (string) combobox_printers.SelectedItem;
640 combobox_printers.SelectedItem = value;
641 label_type_text.Text = value;
645 public void UpdateValues ()
647 combobox_printers.Items.Clear ();
648 foreach (string printer_name in PrinterSettings.InstalledPrinters)
649 combobox_printers.Items.Add (printer_name);
651 // Select the printer indicated by PageSetupDialog.PrinterSettings
652 SelectedPrinter = page_setup_dialog.PrinterSettings.PrinterName;
654 button_network.Enabled = page_setup_dialog.ShowNetwork;
657 #region Windows Form Designer generated code
658 private void InitializeComponent()
660 this.groupbox_printer = new System.Windows.Forms.GroupBox();
661 this.combobox_printers = new System.Windows.Forms.ComboBox();
662 this.button_network = new System.Windows.Forms.Button();
663 this.button_cancel = new System.Windows.Forms.Button();
664 this.button_ok = new System.Windows.Forms.Button();
665 this.label_name = new System.Windows.Forms.Label();
666 this.label_status = new System.Windows.Forms.Label();
667 this.label_status_text = new System.Windows.Forms.Label();
668 this.label_type = new System.Windows.Forms.Label();
669 this.label_type_text = new System.Windows.Forms.Label();
670 this.label_where = new System.Windows.Forms.Label();
671 this.label_comment = new System.Windows.Forms.Label();
672 this.label_where_text = new System.Windows.Forms.Label();
673 this.label_comment_text = new System.Windows.Forms.Label();
674 this.button_properties = new System.Windows.Forms.Button();
675 this.groupbox_printer.SuspendLayout();
676 this.SuspendLayout();
680 this.groupbox_printer.Controls.AddRange(new System.Windows.Forms.Control[] {
681 this.button_properties,
682 this.label_comment_text,
683 this.label_where_text,
686 this.label_type_text,
688 this.label_status_text,
691 this.combobox_printers});
692 this.groupbox_printer.Location = new System.Drawing.Point(12, 8);
693 this.groupbox_printer.Name = "groupbox_printer";
694 this.groupbox_printer.Size = new System.Drawing.Size(438, 136);
695 this.groupbox_printer.Text = "Printer";
699 this.combobox_printers.Location = new System.Drawing.Point(64, 24);
700 this.combobox_printers.Name = "combobox_printers";
701 this.combobox_printers.SelectedValueChanged += new EventHandler (OnSelectedValueChangedPrinters);
702 this.combobox_printers.Size = new System.Drawing.Size(232, 21);
703 this.combobox_printers.TabIndex = 1;
707 this.button_network.Location = new System.Drawing.Point(16, 160);
708 this.button_network.Name = "button_network";
709 this.button_network.Size = new System.Drawing.Size(68, 22);
710 this.button_network.TabIndex = 5;
711 this.button_network.Text = "Network...";
715 this.button_cancel.DialogResult = DialogResult.Cancel;
716 this.button_cancel.Location = new System.Drawing.Point(376, 160);
717 this.button_cancel.Name = "button_cancel";
718 this.button_cancel.Size = new System.Drawing.Size(68, 22);
719 this.button_cancel.TabIndex = 4;
720 this.button_cancel.Text = "Cancel";
724 this.button_ok.DialogResult = DialogResult.OK;
725 this.button_ok.Location = new System.Drawing.Point(300, 160);
726 this.button_ok.Name = "button_ok";
727 this.button_ok.Size = new System.Drawing.Size(68, 22);
728 this.button_ok.TabIndex = 3;
729 this.button_ok.Text = "OK";
733 this.label_name.Location = new System.Drawing.Point(12, 28);
734 this.label_name.Name = "label_name";
735 this.label_name.Size = new System.Drawing.Size(48, 20);
736 this.label_name.Text = "Name:";
740 this.label_status.Location = new System.Drawing.Point(6, 52);
741 this.label_status.Name = "label_status";
742 this.label_status.Size = new System.Drawing.Size(58, 14);
743 this.label_status.Text = "Status:";
747 this.label_status_text.Location = new System.Drawing.Point(64, 52);
748 this.label_status_text.Name = "label_status_text";
749 this.label_status_text.Size = new System.Drawing.Size(64, 14);
750 this.label_status_text.Text = String.Empty;
754 this.label_type.Location = new System.Drawing.Point(6, 72);
755 this.label_type.Name = "label_type";
756 this.label_type.Size = new System.Drawing.Size(58, 14);
757 this.label_type.Text = "Type:";
761 this.label_type_text.Location = new System.Drawing.Point(64, 72);
762 this.label_type_text.Name = "label_type_text";
763 this.label_type_text.Size = new System.Drawing.Size(232, 14);
764 this.label_type_text.TabIndex = 5;
765 this.label_type_text.Text = String.Empty;
769 this.label_where.Location = new System.Drawing.Point(6, 92);
770 this.label_where.Name = "label_where";
771 this.label_where.Size = new System.Drawing.Size(58, 16);
772 this.label_where.TabIndex = 6;
773 this.label_where.Text = "Where:";
777 this.label_comment.Location = new System.Drawing.Point(6, 112);
778 this.label_comment.Name = "label_comment";
779 this.label_comment.Size = new System.Drawing.Size(56, 16);
780 this.label_comment.Text = "Comment:";
784 this.label_where_text.Location = new System.Drawing.Point(64, 92);
785 this.label_where_text.Name = "label_where_text";
786 this.label_where_text.Size = new System.Drawing.Size(232, 16);
787 this.label_where_text.Text = String.Empty;
789 // label_comment_text
791 this.label_comment_text.Location = new System.Drawing.Point(64, 112);
792 this.label_comment_text.Name = "label_comment_text";
793 this.label_comment_text.Size = new System.Drawing.Size(232, 16);
794 this.label_comment_text.Text = String.Empty;
798 this.button_properties.Location = new System.Drawing.Point(308, 22);
799 this.button_properties.Name = "button_properties";
800 this.button_properties.Size = new System.Drawing.Size(92, 22);
801 this.button_properties.TabIndex = 2;
802 this.button_properties.Text = "Properties...";
806 this.AllowDrop = true;
807 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
808 this.AcceptButton = button_ok;
809 this.CancelButton = button_cancel;
810 this.ClientSize = new System.Drawing.Size(456, 194);
811 this.Controls.AddRange(new System.Windows.Forms.Control[] {
815 this.groupbox_printer});
816 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
817 this.HelpButton = true;
818 this.MaximizeBox = false;
819 this.MinimizeBox = false;
820 this.Name = "PrinterForm";
821 this.ShowInTaskbar = false;
822 this.Text = "Configure page";
823 this.groupbox_printer.ResumeLayout(false);
824 this.ResumeLayout(false);
827 void OnSelectedValueChangedPrinters (object sender, EventArgs args)
829 SelectedPrinter = (string) combobox_printers.SelectedItem;
833 private class PagePreview : UserControl
846 System.Text.StringBuilder sb;
850 public bool Landscape
852 get { return landscape; }
855 if (landscape != value) {
862 public new float Height {
863 get { return displayHeight; }
865 if (displayHeight != value) {
866 displayHeight = value;
872 public PagePreview ()
874 sb = new System.Text.StringBuilder ();
875 for (int i = 0; i < 4; i++) {
876 sb.Append ("blabla piu piublapiu haha lai dlais dhlçai shd ");
877 sb.Append ("çoasd çlaj sdç\r\n lajsd lçaisdj lçillaisd lahs dli");
878 sb.Append ("laksjd liasjdliasdj blabla piu piublapiu haha ");
879 sb.Append ("lai dlais dhlçai shd çoasd çlaj sdç lajsd lçaisdj");
880 sb.Append (" lçillaisd lahs dli laksjd liasjdliasdj\r\n\r\n");
883 font = new Font (FontFamily.GenericSansSerif, 4);
884 this.displayHeight = 130;
887 public void SetSize (int width, int height)
890 this.height = height;
894 public void SetMargins (int left, int right, int top, int bottom)
896 this.marginBottom = bottom;
897 this.marginTop = top;
898 this.marginLeft = left;
899 this.marginRight = right;
904 public void Setup (PageSettings pageSettings)
906 this.width = pageSettings.PaperSize.Width;
907 this.height = pageSettings.PaperSize.Height;
909 Margins margins = pageSettings.Margins;
910 this.marginBottom = margins.Bottom;
911 this.marginTop = margins.Top;
912 this.marginLeft = margins.Left;
913 this.marginRight = margins.Right;
914 this.landscape = pageSettings.Landscape;
918 protected override void OnPaint (PaintEventArgs e)
925 Graphics g = e.Graphics;
927 float h = displayHeight;
928 float w = (width * displayHeight) / height;
929 float top = (marginTop * displayHeight) / height;
930 float left = (marginLeft * displayHeight) / height;
931 float bottom = (marginBottom * displayHeight) / height;
932 float right = (marginRight * displayHeight) / height;
945 g.FillRectangle (SystemBrushes.ControlDark, 4, 4, w + 4, h + 4);
946 g.FillRectangle (Brushes.White, 0, 0, w, h);
948 RectangleF outerrect = new RectangleF (0, 0, w, h);
949 RectangleF innerrect = new RectangleF (left, top,
953 ControlPaint.DrawBorder (g, outerrect, Color.Black, ButtonBorderStyle.Solid);
954 ControlPaint.DrawBorder (g, innerrect, SystemColors.ControlDark, ButtonBorderStyle.Dashed);
956 g.DrawString (sb.ToString (), font, Brushes.Black,
957 new RectangleF (innerrect.X + 2,
960 innerrect.Height - 4));