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 bool enable_metric;
56 private GroupBox groupbox_paper;
57 private Label label_source;
58 private Label label_size;
59 private GroupBox groupbox_orientation;
60 private RadioButton radio_landscape;
61 private RadioButton radio_portrait;
62 private GroupBox groupbox_margin;
63 private Label label_left;
64 private Button button_help;
65 private Button button_ok;
66 private Button button_cancel;
67 private Button button_printer;
68 private Label label_top;
69 private Label label_right;
70 private Label label_bottom;
71 private NumericTextBox textbox_left;
72 private NumericTextBox textbox_top;
73 private NumericTextBox textbox_right;
74 private NumericTextBox textbox_bottom;
75 private ComboBox combobox_source;
76 private ComboBox combobox_size;
77 private PagePreview pagePreview;
78 #endregion // Local variables
80 #region Public Constructors
81 public PageSetupDialog ()
83 form = new DialogForm (this);
84 InitializeComponent();
87 #endregion // Public Constructors
89 #region Public Instance Methods
90 public override void Reset ()
93 AllowOrientation = true;
98 MinMargins = new Margins (0, 0, 0, 0);
99 PrinterSettings = null;
103 #endregion // Public Instance Methods
105 #region Public Instance Properties
107 public bool AllowMargins {
108 get { return allow_margins; }
109 set { allow_margins = value; }
113 public bool AllowOrientation {
114 get { return allow_orientation; }
115 set { allow_orientation = value; }
119 public bool AllowPaper {
120 get { return allow_paper; }
121 set { allow_paper = value; }
125 public bool AllowPrinter {
126 get { return allow_printer; }
127 set { allow_printer = value; }
131 public PrintDocument Document {
132 get { return document; }
135 if (document != null) {
136 printer_settings = document.PrinterSettings;
137 page_settings = document.DefaultPageSettings;
144 [DefaultValue (false)]
145 [MonoTODO ("Stubbed, not implemented")]
146 [EditorBrowsableAttribute (EditorBrowsableState.Always)]
147 public bool EnableMetric {
148 get { return enable_metric; }
149 set { enable_metric = value; }
153 public Margins MinMargins {
154 get { return min_margins; }
155 set { min_margins = value; }
160 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
161 public PageSettings PageSettings {
162 get { return page_settings; }
164 page_settings = value;
171 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
172 public PrinterSettings PrinterSettings {
173 get { return printer_settings; }
175 printer_settings = value;
180 [DefaultValue(false)]
181 public bool ShowHelp {
182 get { return show_help; }
184 if (value != show_help) {
192 public bool ShowNetwork {
193 get { return show_network; }
194 set { show_network = value; }
197 #endregion // Public Instance Properties
199 #region Protected Instance Methods
200 protected override bool RunDialog (IntPtr hwndOwner)
203 SetPrinterDetails ();
205 } catch (Exception e) {
206 MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
210 #endregion // Protected Instance Methods
212 #region Private Helper
213 private void InitializeComponent()
215 this.groupbox_paper = new System.Windows.Forms.GroupBox();
216 this.combobox_source = new System.Windows.Forms.ComboBox();
217 this.combobox_size = new System.Windows.Forms.ComboBox();
218 this.label_source = new System.Windows.Forms.Label();
219 this.label_size = new System.Windows.Forms.Label();
220 this.groupbox_orientation = new System.Windows.Forms.GroupBox();
221 this.radio_landscape = new System.Windows.Forms.RadioButton();
222 this.radio_portrait = new System.Windows.Forms.RadioButton();
223 this.groupbox_margin = new System.Windows.Forms.GroupBox();
224 this.label_left = new System.Windows.Forms.Label();
225 this.button_ok = new System.Windows.Forms.Button();
226 this.button_cancel = new System.Windows.Forms.Button();
227 this.button_printer = new System.Windows.Forms.Button();
228 this.label_top = new System.Windows.Forms.Label();
229 this.label_right = new System.Windows.Forms.Label();
230 this.label_bottom = new System.Windows.Forms.Label();
231 this.textbox_left = new System.Windows.Forms.NumericTextBox();
232 this.textbox_top = new System.Windows.Forms.NumericTextBox();
233 this.textbox_right = new System.Windows.Forms.NumericTextBox();
234 this.textbox_bottom = new System.Windows.Forms.NumericTextBox();
235 this.pagePreview = new PagePreview ();
236 this.groupbox_paper.SuspendLayout();
237 this.groupbox_orientation.SuspendLayout();
238 this.groupbox_margin.SuspendLayout();
239 form.SuspendLayout();
243 this.groupbox_paper.Controls.Add(this.combobox_source);
244 this.groupbox_paper.Controls.Add(this.combobox_size);
245 this.groupbox_paper.Controls.Add(this.label_source);
246 this.groupbox_paper.Controls.Add(this.label_size);
247 this.groupbox_paper.Location = new System.Drawing.Point(12, 157);
248 this.groupbox_paper.Name = "groupbox_paper";
249 this.groupbox_paper.Size = new System.Drawing.Size(336, 90);
250 this.groupbox_paper.TabIndex = 0;
251 this.groupbox_paper.TabStop = false;
252 this.groupbox_paper.Text = "Paper";
256 this.combobox_source.Location = new System.Drawing.Point(84, 54);
257 this.combobox_source.Name = "combobox_source";
258 this.combobox_source.Size = new System.Drawing.Size(240, 21);
259 this.combobox_source.TabIndex = 3;
263 this.combobox_size.ItemHeight = 13;
264 this.combobox_size.Location = new System.Drawing.Point(84, 22);
265 this.combobox_size.Name = "combobox_size";
266 this.combobox_size.Size = new System.Drawing.Size(240, 21);
267 this.combobox_size.TabIndex = 2;
268 this.combobox_size.SelectedIndexChanged += new EventHandler(this.OnPaperSizeChange);
272 this.label_source.Location = new System.Drawing.Point(13, 58);
273 this.label_source.Name = "label_source";
274 this.label_source.Size = new System.Drawing.Size(48, 16);
275 this.label_source.TabIndex = 1;
276 this.label_source.Text = "&Source:";
280 this.label_size.Location = new System.Drawing.Point(13, 25);
281 this.label_size.Name = "label_size";
282 this.label_size.Size = new System.Drawing.Size(52, 16);
283 this.label_size.TabIndex = 0;
284 this.label_size.Text = "Si&ze:";
286 // groupbox_orientation
288 this.groupbox_orientation.Controls.Add(this.radio_landscape);
289 this.groupbox_orientation.Controls.Add(this.radio_portrait);
290 this.groupbox_orientation.Location = new System.Drawing.Point(12, 255);
291 this.groupbox_orientation.Name = "groupbox_orientation";
292 this.groupbox_orientation.Size = new System.Drawing.Size(96, 90);
293 this.groupbox_orientation.TabIndex = 1;
294 this.groupbox_orientation.TabStop = false;
295 this.groupbox_orientation.Text = "Orientation";
299 this.radio_landscape.Location = new System.Drawing.Point(13, 52);
300 this.radio_landscape.Name = "radio_landscape";
301 this.radio_landscape.Size = new System.Drawing.Size(80, 24);
302 this.radio_landscape.TabIndex = 7;
303 this.radio_landscape.Text = "L&andscape";
304 this.radio_landscape.CheckedChanged += new EventHandler(this.OnLandscapeChange);
308 this.radio_portrait.Location = new System.Drawing.Point(13, 19);
309 this.radio_portrait.Name = "radio_portrait";
310 this.radio_portrait.Size = new System.Drawing.Size(72, 24);
311 this.radio_portrait.TabIndex = 6;
312 this.radio_portrait.Text = "P&ortrait";
316 this.groupbox_margin.Controls.Add(this.textbox_bottom);
317 this.groupbox_margin.Controls.Add(this.textbox_right);
318 this.groupbox_margin.Controls.Add(this.textbox_top);
319 this.groupbox_margin.Controls.Add(this.textbox_left);
320 this.groupbox_margin.Controls.Add(this.label_bottom);
321 this.groupbox_margin.Controls.Add(this.label_right);
322 this.groupbox_margin.Controls.Add(this.label_top);
323 this.groupbox_margin.Controls.Add(this.label_left);
324 this.groupbox_margin.Location = new System.Drawing.Point(120, 255);
325 this.groupbox_margin.Name = "groupbox_margin";
326 this.groupbox_margin.Size = new System.Drawing.Size(228, 90);
327 this.groupbox_margin.TabIndex = 2;
328 this.groupbox_margin.TabStop = false;
329 this.groupbox_margin.Text = LocalizedLengthUnit ();
333 this.label_left.Location = new System.Drawing.Point(11, 25);
334 this.label_left.Name = "label_left";
335 this.label_left.Size = new System.Drawing.Size(40, 23);
336 this.label_left.TabIndex = 0;
337 this.label_left.Text = "&Left:";
341 this.button_ok.Location = new System.Drawing.Point(120, 358);
342 this.button_ok.Name = "button_ok";
343 this.button_ok.Size = new System.Drawing.Size(72, 23);
344 this.button_ok.TabIndex = 3;
345 this.button_ok.Text = "OK";
346 this.button_ok.Click += new EventHandler (OnClickOkButton);
350 this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
351 this.button_cancel.Location = new System.Drawing.Point(198, 358);
352 this.button_cancel.Name = "button_cancel";
353 this.button_cancel.Size = new System.Drawing.Size(72, 23);
354 this.button_cancel.TabIndex = 4;
355 this.button_cancel.Text = "Cancel";
359 this.button_printer.Location = new System.Drawing.Point(276, 358);
360 this.button_printer.Name = "button_printer";
361 this.button_printer.Size = new System.Drawing.Size(72, 23);
362 this.button_printer.TabIndex = 5;
363 this.button_printer.Text = "&Printer...";
364 this.button_printer.Click += new EventHandler (OnClickPrinterButton);
368 this.label_top.Location = new System.Drawing.Point(11, 57);
369 this.label_top.Name = "label_top";
370 this.label_top.Size = new System.Drawing.Size(40, 23);
371 this.label_top.TabIndex = 1;
372 this.label_top.Text = "&Top:";
376 this.label_right.Location = new System.Drawing.Point(124, 25);
377 this.label_right.Name = "label_right";
378 this.label_right.Size = new System.Drawing.Size(40, 23);
379 this.label_right.TabIndex = 2;
380 this.label_right.Text = "&Right:";
384 this.label_bottom.Location = new System.Drawing.Point(124, 57);
385 this.label_bottom.Name = "label_bottom";
386 this.label_bottom.Size = new System.Drawing.Size(40, 23);
387 this.label_bottom.TabIndex = 3;
388 this.label_bottom.Text = "&Bottom:";
392 this.textbox_left.Location = new System.Drawing.Point(57, 21);
393 this.textbox_left.Name = "textbox_left";
394 this.textbox_left.Size = new System.Drawing.Size(48, 20);
395 this.textbox_left.TabIndex = 4;
396 this.textbox_left.TextChanged +=new EventHandler(OnMarginChange);
400 this.textbox_top.Location = new System.Drawing.Point(57, 54);
401 this.textbox_top.Name = "textbox_top";
402 this.textbox_top.Size = new System.Drawing.Size(48, 20);
403 this.textbox_top.TabIndex = 5;
404 this.textbox_top.TextChanged +=new EventHandler(OnMarginChange);
408 this.textbox_right.Location = new System.Drawing.Point(171, 21);
409 this.textbox_right.Name = "textbox_right";
410 this.textbox_right.Size = new System.Drawing.Size(48, 20);
411 this.textbox_right.TabIndex = 6;
412 this.textbox_right.TextChanged +=new EventHandler(OnMarginChange);
416 this.textbox_bottom.Location = new System.Drawing.Point(171, 54);
417 this.textbox_bottom.Name = "textbox_bottom";
418 this.textbox_bottom.Size = new System.Drawing.Size(48, 20);
419 this.textbox_bottom.TabIndex = 7;
420 this.textbox_bottom.TextChanged +=new EventHandler(OnMarginChange);
424 this.pagePreview.Location = new System.Drawing.Point (130, 10);
425 this.pagePreview.Name = "pagePreview";
426 this.pagePreview.Size = new System.Drawing.Size (150, 150);
427 this.pagePreview.TabIndex = 6;
431 form.AcceptButton = this.button_ok;
432 form.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
433 form.CancelButton = this.button_cancel;
434 form.ClientSize = new System.Drawing.Size(360, 390);
435 form.Controls.Add (this.pagePreview);
436 form.Controls.Add (this.button_printer);
437 form.Controls.Add(this.button_cancel);
438 form.Controls.Add(this.button_ok);
439 form.Controls.Add(this.groupbox_margin);
440 form.Controls.Add(this.groupbox_orientation);
441 form.Controls.Add(this.groupbox_paper);
442 form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
443 form.HelpButton = true;
444 form.MaximizeBox = false;
445 form.MinimizeBox = false;
447 form.ShowInTaskbar = false;
448 form.Text = "Page Setup";
449 this.groupbox_paper.ResumeLayout(false);
450 this.groupbox_orientation.ResumeLayout(false);
451 this.groupbox_margin.ResumeLayout(false);
452 form.ResumeLayout(false);
456 static bool UseYardPound {
457 get { return !RegionInfo.CurrentRegion.IsMetric; }
460 // .Net uses PrinterSettings property if it is not null.
461 // Otherwise, it uses PageSettings.PrinterSettings to set values.
462 // We use this property internally to automatically select the available one.
463 PrinterSettings InternalPrinterSettings {
465 return (printer_settings == null ? page_settings.PrinterSettings :
470 private double ToLocalizedLength (int marginsUnit)
472 return UseYardPound ?
473 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.ThousandthsOfAnInch, PrinterUnit.Display) :
474 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.ThousandthsOfAnInch, PrinterUnit.TenthsOfAMillimeter);
477 private int FromLocalizedLength (double marginsUnit)
479 return (int)(UseYardPound ?
480 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.Display, PrinterUnit.ThousandthsOfAnInch) :
481 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.ThousandthsOfAnInch));
484 private string LocalizedLengthUnit ()
486 return UseYardPound ? "Margins (inches)" : "Margins (millimeters)";
489 private void SetPrinterDetails ()
491 if (PageSettings == null)
492 throw new ArgumentException ("PageSettings");
494 combobox_size.Items.Clear ();
495 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes)
496 combobox_size.Items.Add (paper_size.PaperName);
497 combobox_size.SelectedItem = page_settings.PaperSize.PaperName;
499 combobox_source.Items.Clear ();
500 foreach (PaperSource paper_source in InternalPrinterSettings.PaperSources)
501 combobox_source.Items.Add (paper_source.SourceName);
502 combobox_source.SelectedItem = page_settings.PaperSource.SourceName;
504 if (PageSettings.Landscape)
505 radio_landscape.Checked = true;
507 radio_portrait.Checked = true;
512 Margins page_margins = PageSettings.Margins;
513 Margins min_margins = MinMargins;
515 // Update margin data
516 textbox_top.Text = ToLocalizedLength (page_margins.Top).ToString ();
517 textbox_bottom.Text = ToLocalizedLength (page_margins.Bottom).ToString ();
518 textbox_left.Text = ToLocalizedLength (page_margins.Left).ToString ();
519 textbox_right.Text = ToLocalizedLength (page_margins.Right).ToString ();
520 textbox_top.Min = ToLocalizedLength (min_margins.Top);
521 textbox_bottom.Min = ToLocalizedLength (min_margins.Bottom);
522 textbox_left.Min = ToLocalizedLength (min_margins.Left);
523 textbox_right.Min = ToLocalizedLength (min_margins.Right);
525 button_printer.Enabled = AllowPrinter && PrinterSettings != null;
526 groupbox_orientation.Enabled = AllowOrientation;
527 groupbox_paper.Enabled = AllowPaper;
528 groupbox_margin.Enabled = AllowMargins;
530 pagePreview.Setup (PageSettings);
533 private void OnClickOkButton (object sender, EventArgs e)
535 if (combobox_size.SelectedItem != null) {
536 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes) {
537 if (paper_size.PaperName == (string) combobox_size.SelectedItem) {
538 PageSettings.PaperSize = paper_size;
544 if (combobox_source.SelectedItem != null) {
545 foreach (PaperSource paper_source in InternalPrinterSettings.PaperSources) {
546 if (paper_source.SourceName == (string) combobox_source.SelectedItem) {
547 PageSettings.PaperSource = paper_source;
553 Margins margins = new Margins ();
554 margins.Top = FromLocalizedLength (textbox_top.Value);
555 margins.Bottom = FromLocalizedLength (textbox_bottom.Value);
556 margins.Left = FromLocalizedLength (textbox_left.Value);
557 margins.Right = FromLocalizedLength (textbox_right.Value);
558 PageSettings.Margins = margins;
560 PageSettings.Landscape = radio_landscape.Checked;
561 form.DialogResult = DialogResult.OK;
564 void ShowHelpButton ()
566 if (button_help == null) {
567 button_help = new Button ();
568 button_help.Location = new System.Drawing.Point (12, 358);
569 button_help.Name = "button_help";
570 button_help.Size = new System.Drawing.Size (72, 23);
571 button_help.Text = "&Help";
572 form.Controls.Add (button_help);
575 button_help.Visible = show_help;
578 void OnClickPrinterButton (object sender, EventArgs args)
580 PrinterForm printer_helper_form = new PrinterForm (this);
582 printer_helper_form.UpdateValues ();
584 // Here update values for PrinterSettings
585 if (printer_helper_form.ShowDialog () == DialogResult.OK)
586 if (printer_helper_form.SelectedPrinter != PrinterSettings.PrinterName)
587 PrinterSettings.PrinterName = printer_helper_form.SelectedPrinter;
589 PageSettings = PrinterSettings.DefaultPageSettings;
590 SetPrinterDetails ();
592 printer_helper_form.Dispose ();
595 void OnPaperSizeChange (object sender, EventArgs e)
597 if (combobox_size.SelectedItem != null) {
598 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes) {
599 if (paper_size.PaperName == (string) combobox_size.SelectedItem) {
600 pagePreview.SetSize (paper_size.Width, paper_size.Height);
607 void OnMarginChange (object sender, EventArgs e)
609 pagePreview.SetMargins (
610 FromLocalizedLength (textbox_left.Value),
611 FromLocalizedLength (textbox_right.Value),
612 FromLocalizedLength (textbox_top.Value),
613 FromLocalizedLength (textbox_bottom.Value)
617 void OnLandscapeChange (object sender, EventArgs e)
619 pagePreview.Landscape = radio_landscape.Checked;
621 #endregion // Private Helper
623 class PrinterForm : Form
625 private System.Windows.Forms.GroupBox groupbox_printer;
626 private System.Windows.Forms.ComboBox combobox_printers;
627 private System.Windows.Forms.Label label_name;
628 private System.Windows.Forms.Label label_status;
629 private System.Windows.Forms.Button button_properties;
630 private System.Windows.Forms.Button button_network;
631 private System.Windows.Forms.Button button_cancel;
632 private System.Windows.Forms.Button button_ok;
633 private System.Windows.Forms.Label label_status_text;
634 private System.Windows.Forms.Label label_type;
635 private System.Windows.Forms.Label label_where;
636 private System.Windows.Forms.Label label_where_text;
637 private System.Windows.Forms.Label label_type_text;
638 private System.Windows.Forms.Label label_comment;
639 private System.Windows.Forms.Label label_comment_text;
640 PageSetupDialog page_setup_dialog;
642 public PrinterForm (PageSetupDialog page_setup_dialog)
644 InitializeComponent();
645 this.page_setup_dialog = page_setup_dialog;
648 public string SelectedPrinter {
650 return (string) combobox_printers.SelectedItem;
653 combobox_printers.SelectedItem = value;
654 label_type_text.Text = value;
658 public void UpdateValues ()
660 combobox_printers.Items.Clear ();
661 foreach (string printer_name in PrinterSettings.InstalledPrinters)
662 combobox_printers.Items.Add (printer_name);
664 // Select the printer indicated by PageSetupDialog.PrinterSettings
665 SelectedPrinter = page_setup_dialog.PrinterSettings.PrinterName;
667 button_network.Enabled = page_setup_dialog.ShowNetwork;
670 #region Windows Form Designer generated code
671 private void InitializeComponent()
673 this.groupbox_printer = new System.Windows.Forms.GroupBox();
674 this.combobox_printers = new System.Windows.Forms.ComboBox();
675 this.button_network = new System.Windows.Forms.Button();
676 this.button_cancel = new System.Windows.Forms.Button();
677 this.button_ok = new System.Windows.Forms.Button();
678 this.label_name = new System.Windows.Forms.Label();
679 this.label_status = new System.Windows.Forms.Label();
680 this.label_status_text = new System.Windows.Forms.Label();
681 this.label_type = new System.Windows.Forms.Label();
682 this.label_type_text = new System.Windows.Forms.Label();
683 this.label_where = new System.Windows.Forms.Label();
684 this.label_comment = new System.Windows.Forms.Label();
685 this.label_where_text = new System.Windows.Forms.Label();
686 this.label_comment_text = new System.Windows.Forms.Label();
687 this.button_properties = new System.Windows.Forms.Button();
688 this.groupbox_printer.SuspendLayout();
689 this.SuspendLayout();
693 this.groupbox_printer.Controls.AddRange(new System.Windows.Forms.Control[] {
694 this.button_properties,
695 this.label_comment_text,
696 this.label_where_text,
699 this.label_type_text,
701 this.label_status_text,
704 this.combobox_printers});
705 this.groupbox_printer.Location = new System.Drawing.Point(12, 8);
706 this.groupbox_printer.Name = "groupbox_printer";
707 this.groupbox_printer.Size = new System.Drawing.Size(438, 136);
708 this.groupbox_printer.Text = "Printer";
712 this.combobox_printers.Location = new System.Drawing.Point(64, 24);
713 this.combobox_printers.Name = "combobox_printers";
714 this.combobox_printers.SelectedValueChanged += new EventHandler (OnSelectedValueChangedPrinters);
715 this.combobox_printers.Size = new System.Drawing.Size(232, 21);
716 this.combobox_printers.TabIndex = 1;
720 this.button_network.Location = new System.Drawing.Point(16, 160);
721 this.button_network.Name = "button_network";
722 this.button_network.Size = new System.Drawing.Size(68, 22);
723 this.button_network.TabIndex = 5;
724 this.button_network.Text = "Network...";
728 this.button_cancel.DialogResult = DialogResult.Cancel;
729 this.button_cancel.Location = new System.Drawing.Point(376, 160);
730 this.button_cancel.Name = "button_cancel";
731 this.button_cancel.Size = new System.Drawing.Size(68, 22);
732 this.button_cancel.TabIndex = 4;
733 this.button_cancel.Text = "Cancel";
737 this.button_ok.DialogResult = DialogResult.OK;
738 this.button_ok.Location = new System.Drawing.Point(300, 160);
739 this.button_ok.Name = "button_ok";
740 this.button_ok.Size = new System.Drawing.Size(68, 22);
741 this.button_ok.TabIndex = 3;
742 this.button_ok.Text = "OK";
746 this.label_name.Location = new System.Drawing.Point(12, 28);
747 this.label_name.Name = "label_name";
748 this.label_name.Size = new System.Drawing.Size(48, 20);
749 this.label_name.Text = "Name:";
753 this.label_status.Location = new System.Drawing.Point(6, 52);
754 this.label_status.Name = "label_status";
755 this.label_status.Size = new System.Drawing.Size(58, 14);
756 this.label_status.Text = "Status:";
760 this.label_status_text.Location = new System.Drawing.Point(64, 52);
761 this.label_status_text.Name = "label_status_text";
762 this.label_status_text.Size = new System.Drawing.Size(64, 14);
763 this.label_status_text.Text = String.Empty;
767 this.label_type.Location = new System.Drawing.Point(6, 72);
768 this.label_type.Name = "label_type";
769 this.label_type.Size = new System.Drawing.Size(58, 14);
770 this.label_type.Text = "Type:";
774 this.label_type_text.Location = new System.Drawing.Point(64, 72);
775 this.label_type_text.Name = "label_type_text";
776 this.label_type_text.Size = new System.Drawing.Size(232, 14);
777 this.label_type_text.TabIndex = 5;
778 this.label_type_text.Text = String.Empty;
782 this.label_where.Location = new System.Drawing.Point(6, 92);
783 this.label_where.Name = "label_where";
784 this.label_where.Size = new System.Drawing.Size(58, 16);
785 this.label_where.TabIndex = 6;
786 this.label_where.Text = "Where:";
790 this.label_comment.Location = new System.Drawing.Point(6, 112);
791 this.label_comment.Name = "label_comment";
792 this.label_comment.Size = new System.Drawing.Size(56, 16);
793 this.label_comment.Text = "Comment:";
797 this.label_where_text.Location = new System.Drawing.Point(64, 92);
798 this.label_where_text.Name = "label_where_text";
799 this.label_where_text.Size = new System.Drawing.Size(232, 16);
800 this.label_where_text.Text = String.Empty;
802 // label_comment_text
804 this.label_comment_text.Location = new System.Drawing.Point(64, 112);
805 this.label_comment_text.Name = "label_comment_text";
806 this.label_comment_text.Size = new System.Drawing.Size(232, 16);
807 this.label_comment_text.Text = String.Empty;
811 this.button_properties.Location = new System.Drawing.Point(308, 22);
812 this.button_properties.Name = "button_properties";
813 this.button_properties.Size = new System.Drawing.Size(92, 22);
814 this.button_properties.TabIndex = 2;
815 this.button_properties.Text = "Properties...";
819 this.AllowDrop = true;
820 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
821 this.AcceptButton = button_ok;
822 this.CancelButton = button_cancel;
823 this.ClientSize = new System.Drawing.Size(456, 194);
824 this.Controls.AddRange(new System.Windows.Forms.Control[] {
828 this.groupbox_printer});
829 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
830 this.HelpButton = true;
831 this.MaximizeBox = false;
832 this.MinimizeBox = false;
833 this.Name = "PrinterForm";
834 this.ShowInTaskbar = false;
835 this.Text = "Configure page";
836 this.groupbox_printer.ResumeLayout(false);
837 this.ResumeLayout(false);
840 void OnSelectedValueChangedPrinters (object sender, EventArgs args)
842 SelectedPrinter = (string) combobox_printers.SelectedItem;
846 private class PagePreview : UserControl
859 System.Text.StringBuilder sb;
863 public bool Landscape {
864 get { return landscape; }
866 if (landscape != value) {
873 public new float Height {
874 get { return displayHeight; }
876 if (displayHeight != value) {
877 displayHeight = value;
883 public PagePreview ()
885 sb = new System.Text.StringBuilder ();
886 for (int i = 0; i < 4; i++) {
887 sb.Append ("blabla piu piublapiu haha lai dlais dhlçai shd ");
888 sb.Append ("çoasd çlaj sdç\r\n lajsd lçaisdj lçillaisd lahs dli");
889 sb.Append ("laksjd liasjdliasdj blabla piu piublapiu haha ");
890 sb.Append ("lai dlais dhlçai shd çoasd çlaj sdç lajsd lçaisdj");
891 sb.Append (" lçillaisd lahs dli laksjd liasjdliasdj\r\n\r\n");
894 font = new Font (FontFamily.GenericSansSerif, 4);
895 this.displayHeight = 130;
898 public void SetSize (int width, int height)
901 this.height = height;
905 public void SetMargins (int left, int right, int top, int bottom)
907 this.marginBottom = bottom;
908 this.marginTop = top;
909 this.marginLeft = left;
910 this.marginRight = right;
915 public void Setup (PageSettings pageSettings)
917 this.width = pageSettings.PaperSize.Width;
918 this.height = pageSettings.PaperSize.Height;
920 Margins margins = pageSettings.Margins;
921 this.marginBottom = margins.Bottom;
922 this.marginTop = margins.Top;
923 this.marginLeft = margins.Left;
924 this.marginRight = margins.Right;
925 this.landscape = pageSettings.Landscape;
929 protected override void OnPaint (PaintEventArgs e)
936 Graphics g = e.Graphics;
938 float h = displayHeight;
939 float w = (width * displayHeight) / height;
940 float top = (marginTop * displayHeight) / height;
941 float left = (marginLeft * displayHeight) / height;
942 float bottom = (marginBottom * displayHeight) / height;
943 float right = (marginRight * displayHeight) / height;
956 g.FillRectangle (SystemBrushes.ControlDark, 4, 4, w + 4, h + 4);
957 g.FillRectangle (Brushes.White, 0, 0, w, h);
959 RectangleF outerrect = new RectangleF (0, 0, w, h);
960 RectangleF innerrect = new RectangleF (left, top,
964 ControlPaint.DrawBorder (g, outerrect, Color.Black, ButtonBorderStyle.Solid);
965 ControlPaint.DrawBorder (g, innerrect, SystemColors.ControlDark, ButtonBorderStyle.Dashed);
967 g.DrawString (sb.ToString (), font, Brushes.Black,
968 new RectangleF (innerrect.X + 2,
971 innerrect.Height - 4));