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;
38 namespace System.Windows.Forms
40 [DefaultProperty("Document")]
41 public sealed class PageSetupDialog : CommonDialog
43 #region Local variables
44 private PrintDocument document;
45 private PageSettings page_settings;
46 private PrinterSettings printer_settings;
47 private Margins min_margins;
48 private bool allow_margins;
49 private bool allow_orientation;
50 private bool allow_paper;
51 private bool allow_printer;
52 private bool show_help;
53 private bool show_network;
54 private bool enable_metric;
55 private GroupBox groupbox_paper;
56 private Label label_source;
57 private Label label_size;
58 private GroupBox groupbox_orientation;
59 private RadioButton radio_landscape;
60 private RadioButton radio_portrait;
61 private GroupBox groupbox_margin;
62 private Label label_left;
63 private Button button_help;
64 private Button button_ok;
65 private Button button_cancel;
66 private Button button_printer;
67 private Label label_top;
68 private Label label_right;
69 private Label label_bottom;
70 private NumericTextBox textbox_left;
71 private NumericTextBox textbox_top;
72 private NumericTextBox textbox_right;
73 private NumericTextBox textbox_bottom;
74 private ComboBox combobox_source;
75 private ComboBox combobox_size;
76 private PagePreview pagePreview;
77 #endregion // Local variables
79 #region Public Constructors
80 public PageSetupDialog ()
82 form = new DialogForm (this);
83 InitializeComponent();
86 #endregion // Public Constructors
88 #region Public Instance Methods
89 public override void Reset ()
92 AllowOrientation = true;
97 MinMargins = new Margins (0, 0, 0, 0);
98 PrinterSettings = null;
102 #endregion // Public Instance Methods
104 #region Public Instance Properties
106 public bool AllowMargins {
107 get { return allow_margins; }
108 set { allow_margins = value; }
112 public bool AllowOrientation {
113 get { return allow_orientation; }
114 set { allow_orientation = value; }
118 public bool AllowPaper {
119 get { return allow_paper; }
120 set { allow_paper = value; }
124 public bool AllowPrinter {
125 get { return allow_printer; }
126 set { allow_printer = value; }
130 public PrintDocument Document {
131 get { return document; }
134 if (document != null) {
135 printer_settings = document.PrinterSettings;
136 page_settings = document.DefaultPageSettings;
142 [DefaultValue (false)]
143 [MonoTODO ("Stubbed, not implemented")]
144 [EditorBrowsableAttribute (EditorBrowsableState.Always)]
145 public bool EnableMetric {
146 get { return enable_metric; }
147 set { enable_metric = value; }
150 public Margins MinMargins {
151 get { return min_margins; }
152 set { min_margins = value; }
157 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
158 public PageSettings PageSettings {
159 get { return page_settings; }
161 page_settings = value;
168 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
169 public PrinterSettings PrinterSettings {
170 get { return printer_settings; }
172 printer_settings = value;
177 [DefaultValue(false)]
178 public bool ShowHelp {
179 get { return show_help; }
181 if (value != show_help) {
189 public bool ShowNetwork {
190 get { return show_network; }
191 set { show_network = value; }
194 #endregion // Public Instance Properties
196 #region Protected Instance Methods
197 protected override bool RunDialog (IntPtr hwndOwner)
200 SetPrinterDetails ();
202 } catch (Exception e) {
203 MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
207 #endregion // Protected Instance Methods
209 #region Private Helper
210 private void InitializeComponent()
212 this.groupbox_paper = new System.Windows.Forms.GroupBox();
213 this.combobox_source = new System.Windows.Forms.ComboBox();
214 this.combobox_size = new System.Windows.Forms.ComboBox();
215 this.label_source = new System.Windows.Forms.Label();
216 this.label_size = new System.Windows.Forms.Label();
217 this.groupbox_orientation = new System.Windows.Forms.GroupBox();
218 this.radio_landscape = new System.Windows.Forms.RadioButton();
219 this.radio_portrait = new System.Windows.Forms.RadioButton();
220 this.groupbox_margin = new System.Windows.Forms.GroupBox();
221 this.label_left = new System.Windows.Forms.Label();
222 this.button_ok = new System.Windows.Forms.Button();
223 this.button_cancel = new System.Windows.Forms.Button();
224 this.button_printer = new System.Windows.Forms.Button();
225 this.label_top = new System.Windows.Forms.Label();
226 this.label_right = new System.Windows.Forms.Label();
227 this.label_bottom = new System.Windows.Forms.Label();
228 this.textbox_left = new System.Windows.Forms.NumericTextBox();
229 this.textbox_top = new System.Windows.Forms.NumericTextBox();
230 this.textbox_right = new System.Windows.Forms.NumericTextBox();
231 this.textbox_bottom = new System.Windows.Forms.NumericTextBox();
232 this.pagePreview = new PagePreview ();
233 this.groupbox_paper.SuspendLayout();
234 this.groupbox_orientation.SuspendLayout();
235 this.groupbox_margin.SuspendLayout();
236 form.SuspendLayout();
240 this.groupbox_paper.Controls.Add(this.combobox_source);
241 this.groupbox_paper.Controls.Add(this.combobox_size);
242 this.groupbox_paper.Controls.Add(this.label_source);
243 this.groupbox_paper.Controls.Add(this.label_size);
244 this.groupbox_paper.Location = new System.Drawing.Point(12, 157);
245 this.groupbox_paper.Name = "groupbox_paper";
246 this.groupbox_paper.Size = new System.Drawing.Size(336, 90);
247 this.groupbox_paper.TabIndex = 0;
248 this.groupbox_paper.TabStop = false;
249 this.groupbox_paper.Text = "Paper";
253 this.combobox_source.Location = new System.Drawing.Point(84, 54);
254 this.combobox_source.Name = "combobox_source";
255 this.combobox_source.Size = new System.Drawing.Size(240, 21);
256 this.combobox_source.TabIndex = 3;
260 this.combobox_size.ItemHeight = 13;
261 this.combobox_size.Location = new System.Drawing.Point(84, 22);
262 this.combobox_size.Name = "combobox_size";
263 this.combobox_size.Size = new System.Drawing.Size(240, 21);
264 this.combobox_size.TabIndex = 2;
265 this.combobox_size.SelectedIndexChanged += new EventHandler(this.OnPaperSizeChange);
269 this.label_source.Location = new System.Drawing.Point(13, 58);
270 this.label_source.Name = "label_source";
271 this.label_source.Size = new System.Drawing.Size(48, 16);
272 this.label_source.TabIndex = 1;
273 this.label_source.Text = "&Source:";
277 this.label_size.Location = new System.Drawing.Point(13, 25);
278 this.label_size.Name = "label_size";
279 this.label_size.Size = new System.Drawing.Size(52, 16);
280 this.label_size.TabIndex = 0;
281 this.label_size.Text = "Si&ze:";
283 // groupbox_orientation
285 this.groupbox_orientation.Controls.Add(this.radio_landscape);
286 this.groupbox_orientation.Controls.Add(this.radio_portrait);
287 this.groupbox_orientation.Location = new System.Drawing.Point(12, 255);
288 this.groupbox_orientation.Name = "groupbox_orientation";
289 this.groupbox_orientation.Size = new System.Drawing.Size(96, 90);
290 this.groupbox_orientation.TabIndex = 1;
291 this.groupbox_orientation.TabStop = false;
292 this.groupbox_orientation.Text = "Orientation";
296 this.radio_landscape.Location = new System.Drawing.Point(13, 52);
297 this.radio_landscape.Name = "radio_landscape";
298 this.radio_landscape.Size = new System.Drawing.Size(80, 24);
299 this.radio_landscape.TabIndex = 7;
300 this.radio_landscape.Text = "L&andscape";
301 this.radio_landscape.CheckedChanged += new EventHandler(this.OnLandscapeChange);
305 this.radio_portrait.Location = new System.Drawing.Point(13, 19);
306 this.radio_portrait.Name = "radio_portrait";
307 this.radio_portrait.Size = new System.Drawing.Size(72, 24);
308 this.radio_portrait.TabIndex = 6;
309 this.radio_portrait.Text = "P&ortrait";
313 this.groupbox_margin.Controls.Add(this.textbox_bottom);
314 this.groupbox_margin.Controls.Add(this.textbox_right);
315 this.groupbox_margin.Controls.Add(this.textbox_top);
316 this.groupbox_margin.Controls.Add(this.textbox_left);
317 this.groupbox_margin.Controls.Add(this.label_bottom);
318 this.groupbox_margin.Controls.Add(this.label_right);
319 this.groupbox_margin.Controls.Add(this.label_top);
320 this.groupbox_margin.Controls.Add(this.label_left);
321 this.groupbox_margin.Location = new System.Drawing.Point(120, 255);
322 this.groupbox_margin.Name = "groupbox_margin";
323 this.groupbox_margin.Size = new System.Drawing.Size(228, 90);
324 this.groupbox_margin.TabIndex = 2;
325 this.groupbox_margin.TabStop = false;
326 this.groupbox_margin.Text = LocalizedLengthUnit ();
330 this.label_left.Location = new System.Drawing.Point(11, 25);
331 this.label_left.Name = "label_left";
332 this.label_left.Size = new System.Drawing.Size(40, 23);
333 this.label_left.TabIndex = 0;
334 this.label_left.Text = "&Left:";
338 this.button_ok.Location = new System.Drawing.Point(120, 358);
339 this.button_ok.Name = "button_ok";
340 this.button_ok.Size = new System.Drawing.Size(72, 23);
341 this.button_ok.TabIndex = 3;
342 this.button_ok.Text = "OK";
343 this.button_ok.Click += new EventHandler (OnClickOkButton);
347 this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
348 this.button_cancel.Location = new System.Drawing.Point(198, 358);
349 this.button_cancel.Name = "button_cancel";
350 this.button_cancel.Size = new System.Drawing.Size(72, 23);
351 this.button_cancel.TabIndex = 4;
352 this.button_cancel.Text = "Cancel";
356 this.button_printer.Location = new System.Drawing.Point(276, 358);
357 this.button_printer.Name = "button_printer";
358 this.button_printer.Size = new System.Drawing.Size(72, 23);
359 this.button_printer.TabIndex = 5;
360 this.button_printer.Text = "&Printer...";
361 this.button_printer.Click += new EventHandler (OnClickPrinterButton);
365 this.label_top.Location = new System.Drawing.Point(11, 57);
366 this.label_top.Name = "label_top";
367 this.label_top.Size = new System.Drawing.Size(40, 23);
368 this.label_top.TabIndex = 1;
369 this.label_top.Text = "&Top:";
373 this.label_right.Location = new System.Drawing.Point(124, 25);
374 this.label_right.Name = "label_right";
375 this.label_right.Size = new System.Drawing.Size(40, 23);
376 this.label_right.TabIndex = 2;
377 this.label_right.Text = "&Right:";
381 this.label_bottom.Location = new System.Drawing.Point(124, 57);
382 this.label_bottom.Name = "label_bottom";
383 this.label_bottom.Size = new System.Drawing.Size(40, 23);
384 this.label_bottom.TabIndex = 3;
385 this.label_bottom.Text = "&Bottom:";
389 this.textbox_left.Location = new System.Drawing.Point(57, 21);
390 this.textbox_left.Name = "textbox_left";
391 this.textbox_left.Size = new System.Drawing.Size(48, 20);
392 this.textbox_left.TabIndex = 4;
393 this.textbox_left.TextChanged +=new EventHandler(OnMarginChange);
397 this.textbox_top.Location = new System.Drawing.Point(57, 54);
398 this.textbox_top.Name = "textbox_top";
399 this.textbox_top.Size = new System.Drawing.Size(48, 20);
400 this.textbox_top.TabIndex = 5;
401 this.textbox_top.TextChanged +=new EventHandler(OnMarginChange);
405 this.textbox_right.Location = new System.Drawing.Point(171, 21);
406 this.textbox_right.Name = "textbox_right";
407 this.textbox_right.Size = new System.Drawing.Size(48, 20);
408 this.textbox_right.TabIndex = 6;
409 this.textbox_right.TextChanged +=new EventHandler(OnMarginChange);
413 this.textbox_bottom.Location = new System.Drawing.Point(171, 54);
414 this.textbox_bottom.Name = "textbox_bottom";
415 this.textbox_bottom.Size = new System.Drawing.Size(48, 20);
416 this.textbox_bottom.TabIndex = 7;
417 this.textbox_bottom.TextChanged +=new EventHandler(OnMarginChange);
421 this.pagePreview.Location = new System.Drawing.Point (130, 10);
422 this.pagePreview.Name = "pagePreview";
423 this.pagePreview.Size = new System.Drawing.Size (150, 150);
424 this.pagePreview.TabIndex = 6;
428 form.AcceptButton = this.button_ok;
429 form.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
430 form.CancelButton = this.button_cancel;
431 form.ClientSize = new System.Drawing.Size(360, 390);
432 form.Controls.Add (this.pagePreview);
433 form.Controls.Add (this.button_printer);
434 form.Controls.Add(this.button_cancel);
435 form.Controls.Add(this.button_ok);
436 form.Controls.Add(this.groupbox_margin);
437 form.Controls.Add(this.groupbox_orientation);
438 form.Controls.Add(this.groupbox_paper);
439 form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
440 form.HelpButton = true;
441 form.MaximizeBox = false;
442 form.MinimizeBox = false;
444 form.ShowInTaskbar = false;
445 form.Text = "Page Setup";
446 this.groupbox_paper.ResumeLayout(false);
447 this.groupbox_orientation.ResumeLayout(false);
448 this.groupbox_margin.ResumeLayout(false);
449 form.ResumeLayout(false);
453 static bool UseYardPound {
455 var current = RegionInfo.CurrentRegion;
458 return !current.IsMetric;
462 // .Net uses PrinterSettings property if it is not null.
463 // Otherwise, it uses PageSettings.PrinterSettings to set values.
464 // We use this property internally to automatically select the available one.
465 PrinterSettings InternalPrinterSettings {
467 return (printer_settings == null ? page_settings.PrinterSettings :
472 private double ToLocalizedLength (int marginsUnit)
474 return UseYardPound ?
475 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.ThousandthsOfAnInch, PrinterUnit.Display) :
476 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.ThousandthsOfAnInch, PrinterUnit.TenthsOfAMillimeter);
479 private int FromLocalizedLength (double marginsUnit)
481 return (int)(UseYardPound ?
482 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.Display, PrinterUnit.ThousandthsOfAnInch) :
483 PrinterUnitConvert.Convert (marginsUnit, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.ThousandthsOfAnInch));
486 private string LocalizedLengthUnit ()
488 return UseYardPound ? "Margins (inches)" : "Margins (millimeters)";
491 private void SetPrinterDetails ()
493 if (PageSettings == null)
494 throw new ArgumentException ("PageSettings");
496 combobox_size.Items.Clear ();
497 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes)
498 combobox_size.Items.Add (paper_size.PaperName);
499 combobox_size.SelectedItem = page_settings.PaperSize.PaperName;
501 combobox_source.Items.Clear ();
502 foreach (PaperSource paper_source in InternalPrinterSettings.PaperSources)
503 combobox_source.Items.Add (paper_source.SourceName);
504 combobox_source.SelectedItem = page_settings.PaperSource.SourceName;
506 if (PageSettings.Landscape)
507 radio_landscape.Checked = true;
509 radio_portrait.Checked = true;
514 Margins page_margins = PageSettings.Margins;
515 Margins min_margins = MinMargins;
517 // Update margin data
518 textbox_top.Text = ToLocalizedLength (page_margins.Top).ToString ();
519 textbox_bottom.Text = ToLocalizedLength (page_margins.Bottom).ToString ();
520 textbox_left.Text = ToLocalizedLength (page_margins.Left).ToString ();
521 textbox_right.Text = ToLocalizedLength (page_margins.Right).ToString ();
522 textbox_top.Min = ToLocalizedLength (min_margins.Top);
523 textbox_bottom.Min = ToLocalizedLength (min_margins.Bottom);
524 textbox_left.Min = ToLocalizedLength (min_margins.Left);
525 textbox_right.Min = ToLocalizedLength (min_margins.Right);
527 button_printer.Enabled = AllowPrinter && PrinterSettings != null;
528 groupbox_orientation.Enabled = AllowOrientation;
529 groupbox_paper.Enabled = AllowPaper;
530 groupbox_margin.Enabled = AllowMargins;
532 pagePreview.Setup (PageSettings);
535 private void OnClickOkButton (object sender, EventArgs e)
537 if (combobox_size.SelectedItem != null) {
538 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes) {
539 if (paper_size.PaperName == (string) combobox_size.SelectedItem) {
540 PageSettings.PaperSize = paper_size;
546 if (combobox_source.SelectedItem != null) {
547 foreach (PaperSource paper_source in InternalPrinterSettings.PaperSources) {
548 if (paper_source.SourceName == (string) combobox_source.SelectedItem) {
549 PageSettings.PaperSource = paper_source;
555 Margins margins = new Margins ();
556 margins.Top = FromLocalizedLength (textbox_top.Value);
557 margins.Bottom = FromLocalizedLength (textbox_bottom.Value);
558 margins.Left = FromLocalizedLength (textbox_left.Value);
559 margins.Right = FromLocalizedLength (textbox_right.Value);
560 PageSettings.Margins = margins;
562 PageSettings.Landscape = radio_landscape.Checked;
563 form.DialogResult = DialogResult.OK;
566 void ShowHelpButton ()
568 if (button_help == null) {
569 button_help = new Button ();
570 button_help.Location = new System.Drawing.Point (12, 358);
571 button_help.Name = "button_help";
572 button_help.Size = new System.Drawing.Size (72, 23);
573 button_help.Text = "&Help";
574 form.Controls.Add (button_help);
577 button_help.Visible = show_help;
580 void OnClickPrinterButton (object sender, EventArgs args)
582 PrinterForm printer_helper_form = new PrinterForm (this);
584 printer_helper_form.UpdateValues ();
586 // Here update values for PrinterSettings
587 if (printer_helper_form.ShowDialog () == DialogResult.OK)
588 if (printer_helper_form.SelectedPrinter != PrinterSettings.PrinterName)
589 PrinterSettings.PrinterName = printer_helper_form.SelectedPrinter;
591 PageSettings = PrinterSettings.DefaultPageSettings;
592 SetPrinterDetails ();
594 printer_helper_form.Dispose ();
597 void OnPaperSizeChange (object sender, EventArgs e)
599 if (combobox_size.SelectedItem != null) {
600 foreach (PaperSize paper_size in InternalPrinterSettings.PaperSizes) {
601 if (paper_size.PaperName == (string) combobox_size.SelectedItem) {
602 pagePreview.SetSize (paper_size.Width, paper_size.Height);
609 void OnMarginChange (object sender, EventArgs e)
611 pagePreview.SetMargins (
612 FromLocalizedLength (textbox_left.Value),
613 FromLocalizedLength (textbox_right.Value),
614 FromLocalizedLength (textbox_top.Value),
615 FromLocalizedLength (textbox_bottom.Value)
619 void OnLandscapeChange (object sender, EventArgs e)
621 pagePreview.Landscape = radio_landscape.Checked;
623 #endregion // Private Helper
625 class PrinterForm : Form
627 private System.Windows.Forms.GroupBox groupbox_printer;
628 private System.Windows.Forms.ComboBox combobox_printers;
629 private System.Windows.Forms.Label label_name;
630 private System.Windows.Forms.Label label_status;
631 private System.Windows.Forms.Button button_properties;
632 private System.Windows.Forms.Button button_network;
633 private System.Windows.Forms.Button button_cancel;
634 private System.Windows.Forms.Button button_ok;
635 private System.Windows.Forms.Label label_status_text;
636 private System.Windows.Forms.Label label_type;
637 private System.Windows.Forms.Label label_where;
638 private System.Windows.Forms.Label label_where_text;
639 private System.Windows.Forms.Label label_type_text;
640 private System.Windows.Forms.Label label_comment;
641 private System.Windows.Forms.Label label_comment_text;
642 PageSetupDialog page_setup_dialog;
644 public PrinterForm (PageSetupDialog page_setup_dialog)
646 InitializeComponent();
647 this.page_setup_dialog = page_setup_dialog;
650 public string SelectedPrinter {
652 return (string) combobox_printers.SelectedItem;
655 combobox_printers.SelectedItem = value;
656 label_type_text.Text = value;
660 public void UpdateValues ()
662 combobox_printers.Items.Clear ();
663 foreach (string printer_name in PrinterSettings.InstalledPrinters)
664 combobox_printers.Items.Add (printer_name);
666 // Select the printer indicated by PageSetupDialog.PrinterSettings
667 SelectedPrinter = page_setup_dialog.PrinterSettings.PrinterName;
669 button_network.Enabled = page_setup_dialog.ShowNetwork;
672 #region Windows Form Designer generated code
673 private void InitializeComponent()
675 this.groupbox_printer = new System.Windows.Forms.GroupBox();
676 this.combobox_printers = new System.Windows.Forms.ComboBox();
677 this.button_network = new System.Windows.Forms.Button();
678 this.button_cancel = new System.Windows.Forms.Button();
679 this.button_ok = new System.Windows.Forms.Button();
680 this.label_name = new System.Windows.Forms.Label();
681 this.label_status = new System.Windows.Forms.Label();
682 this.label_status_text = new System.Windows.Forms.Label();
683 this.label_type = new System.Windows.Forms.Label();
684 this.label_type_text = new System.Windows.Forms.Label();
685 this.label_where = new System.Windows.Forms.Label();
686 this.label_comment = new System.Windows.Forms.Label();
687 this.label_where_text = new System.Windows.Forms.Label();
688 this.label_comment_text = new System.Windows.Forms.Label();
689 this.button_properties = new System.Windows.Forms.Button();
690 this.groupbox_printer.SuspendLayout();
691 this.SuspendLayout();
695 this.groupbox_printer.Controls.AddRange(new System.Windows.Forms.Control[] {
696 this.button_properties,
697 this.label_comment_text,
698 this.label_where_text,
701 this.label_type_text,
703 this.label_status_text,
706 this.combobox_printers});
707 this.groupbox_printer.Location = new System.Drawing.Point(12, 8);
708 this.groupbox_printer.Name = "groupbox_printer";
709 this.groupbox_printer.Size = new System.Drawing.Size(438, 136);
710 this.groupbox_printer.Text = "Printer";
714 this.combobox_printers.Location = new System.Drawing.Point(64, 24);
715 this.combobox_printers.Name = "combobox_printers";
716 this.combobox_printers.SelectedValueChanged += new EventHandler (OnSelectedValueChangedPrinters);
717 this.combobox_printers.Size = new System.Drawing.Size(232, 21);
718 this.combobox_printers.TabIndex = 1;
722 this.button_network.Location = new System.Drawing.Point(16, 160);
723 this.button_network.Name = "button_network";
724 this.button_network.Size = new System.Drawing.Size(68, 22);
725 this.button_network.TabIndex = 5;
726 this.button_network.Text = "Network...";
730 this.button_cancel.DialogResult = DialogResult.Cancel;
731 this.button_cancel.Location = new System.Drawing.Point(376, 160);
732 this.button_cancel.Name = "button_cancel";
733 this.button_cancel.Size = new System.Drawing.Size(68, 22);
734 this.button_cancel.TabIndex = 4;
735 this.button_cancel.Text = "Cancel";
739 this.button_ok.DialogResult = DialogResult.OK;
740 this.button_ok.Location = new System.Drawing.Point(300, 160);
741 this.button_ok.Name = "button_ok";
742 this.button_ok.Size = new System.Drawing.Size(68, 22);
743 this.button_ok.TabIndex = 3;
744 this.button_ok.Text = "OK";
748 this.label_name.Location = new System.Drawing.Point(12, 28);
749 this.label_name.Name = "label_name";
750 this.label_name.Size = new System.Drawing.Size(48, 20);
751 this.label_name.Text = "Name:";
755 this.label_status.Location = new System.Drawing.Point(6, 52);
756 this.label_status.Name = "label_status";
757 this.label_status.Size = new System.Drawing.Size(58, 14);
758 this.label_status.Text = "Status:";
762 this.label_status_text.Location = new System.Drawing.Point(64, 52);
763 this.label_status_text.Name = "label_status_text";
764 this.label_status_text.Size = new System.Drawing.Size(64, 14);
765 this.label_status_text.Text = String.Empty;
769 this.label_type.Location = new System.Drawing.Point(6, 72);
770 this.label_type.Name = "label_type";
771 this.label_type.Size = new System.Drawing.Size(58, 14);
772 this.label_type.Text = "Type:";
776 this.label_type_text.Location = new System.Drawing.Point(64, 72);
777 this.label_type_text.Name = "label_type_text";
778 this.label_type_text.Size = new System.Drawing.Size(232, 14);
779 this.label_type_text.TabIndex = 5;
780 this.label_type_text.Text = String.Empty;
784 this.label_where.Location = new System.Drawing.Point(6, 92);
785 this.label_where.Name = "label_where";
786 this.label_where.Size = new System.Drawing.Size(58, 16);
787 this.label_where.TabIndex = 6;
788 this.label_where.Text = "Where:";
792 this.label_comment.Location = new System.Drawing.Point(6, 112);
793 this.label_comment.Name = "label_comment";
794 this.label_comment.Size = new System.Drawing.Size(56, 16);
795 this.label_comment.Text = "Comment:";
799 this.label_where_text.Location = new System.Drawing.Point(64, 92);
800 this.label_where_text.Name = "label_where_text";
801 this.label_where_text.Size = new System.Drawing.Size(232, 16);
802 this.label_where_text.Text = String.Empty;
804 // label_comment_text
806 this.label_comment_text.Location = new System.Drawing.Point(64, 112);
807 this.label_comment_text.Name = "label_comment_text";
808 this.label_comment_text.Size = new System.Drawing.Size(232, 16);
809 this.label_comment_text.Text = String.Empty;
813 this.button_properties.Location = new System.Drawing.Point(308, 22);
814 this.button_properties.Name = "button_properties";
815 this.button_properties.Size = new System.Drawing.Size(92, 22);
816 this.button_properties.TabIndex = 2;
817 this.button_properties.Text = "Properties...";
821 this.AllowDrop = true;
822 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
823 this.AcceptButton = button_ok;
824 this.CancelButton = button_cancel;
825 this.ClientSize = new System.Drawing.Size(456, 194);
826 this.Controls.AddRange(new System.Windows.Forms.Control[] {
830 this.groupbox_printer});
831 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
832 this.HelpButton = true;
833 this.MaximizeBox = false;
834 this.MinimizeBox = false;
835 this.Name = "PrinterForm";
836 this.ShowInTaskbar = false;
837 this.Text = "Configure page";
838 this.groupbox_printer.ResumeLayout(false);
839 this.ResumeLayout(false);
842 void OnSelectedValueChangedPrinters (object sender, EventArgs args)
844 SelectedPrinter = (string) combobox_printers.SelectedItem;
848 private class PagePreview : UserControl
865 public bool Landscape {
866 get { return landscape; }
868 if (landscape != value) {
875 public new float Height {
876 get { return displayHeight; }
878 if (displayHeight != value) {
879 displayHeight = value;
885 public PagePreview ()
887 sb = new StringBuilder ();
888 for (int i = 0; i < 4; i++) {
889 sb.Append ("blabla piu piublapiu haha lai dlais dhlçai shd ");
890 sb.Append ("çoasd çlaj sdç\r\n lajsd lçaisdj lçillaisd lahs dli");
891 sb.Append ("laksjd liasjdliasdj blabla piu piublapiu haha ");
892 sb.Append ("lai dlais dhlçai shd çoasd çlaj sdç lajsd lçaisdj");
893 sb.Append (" lçillaisd lahs dli laksjd liasjdliasdj\r\n\r\n");
896 font = new Font (FontFamily.GenericSansSerif, 4);
897 this.displayHeight = 130;
900 public void SetSize (int width, int height)
903 this.height = height;
907 public void SetMargins (int left, int right, int top, int bottom)
909 this.marginBottom = bottom;
910 this.marginTop = top;
911 this.marginLeft = left;
912 this.marginRight = right;
917 public void Setup (PageSettings pageSettings)
919 this.width = pageSettings.PaperSize.Width;
920 this.height = pageSettings.PaperSize.Height;
922 Margins margins = pageSettings.Margins;
923 this.marginBottom = margins.Bottom;
924 this.marginTop = margins.Top;
925 this.marginLeft = margins.Left;
926 this.marginRight = margins.Right;
927 this.landscape = pageSettings.Landscape;
931 protected override void OnPaint (PaintEventArgs e)
938 Graphics g = e.Graphics;
940 float h = displayHeight;
941 float w = (width * displayHeight) / height;
942 float top = (marginTop * displayHeight) / height;
943 float left = (marginLeft * displayHeight) / height;
944 float bottom = (marginBottom * displayHeight) / height;
945 float right = (marginRight * displayHeight) / height;
958 g.FillRectangle (SystemBrushes.ControlDark, 4, 4, w + 4, h + 4);
959 g.FillRectangle (Brushes.White, 0, 0, w, h);
961 RectangleF outerrect = new RectangleF (0, 0, w, h);
962 RectangleF innerrect = new RectangleF (left, top,
966 ControlPaint.DrawBorder (g, outerrect, Color.Black, ButtonBorderStyle.Solid);
967 ControlPaint.DrawBorder (g, innerrect, SystemColors.ControlDark, ButtonBorderStyle.Dashed);
969 g.DrawString (sb.ToString (), font, Brushes.Black,
970 new RectangleF (innerrect.X + 2,
973 innerrect.Height - 4));