Fix bug #395
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / PrintDialog.cs
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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.
19 //
20 // Copyright (c) 2005-2006 Novell, Inc.
21 //
22 // Authors:
23 //      Someone
24 //      Jonathan Chambers (jonathan.chambers@ansys.com)
25 //      Jordi Mas i Hernandez (jordimash@gmail.com)
26 //
27
28 using System;
29 using System.ComponentModel;
30 using System.ComponentModel.Design;
31 using System.ComponentModel.Design.Serialization;
32 using System.Collections;
33 using System.Diagnostics;
34 using System.Drawing;
35 using System.Drawing.Printing;
36 using System.Reflection;
37
38 namespace System.Windows.Forms
39 {
40         [Designer ("System.Windows.Forms.Design.PrintDialogDesigner, " + Consts.AssemblySystem_Design,
41                    "System.ComponentModel.Design.IDesigner")]
42         [DefaultProperty("Document")]
43         public sealed class PrintDialog : CommonDialog {
44                 PrintDocument document;
45                 bool allow_current_page;
46                 bool allow_print_to_file;
47                 bool allow_selection;
48                 bool allow_some_pages;
49                 bool show_help;
50                 bool show_network;
51                 bool print_to_file;
52                 PrinterSettings current_settings;
53
54                 private Button cancel_button;
55                 private Button accept_button;
56                 private Button help_button;
57                 private ComboBox printer_combo;
58                 private RadioButton radio_all;
59                 private RadioButton radio_pages;
60                 private RadioButton radio_sel;
61                 private PrinterSettings.StringCollection installed_printers;
62                 private PrinterSettings default_printer_settings;
63                 private TextBox txtFrom;
64                 private TextBox txtTo;
65                 private Label labelTo;
66                 private Label labelFrom;
67                 private CheckBox chkbox_print;
68                 private NumericUpDown updown_copies;
69                 private CheckBox chkbox_collate;
70                 private Label label_status;
71                 private Label label_type;
72                 private Label label_where;
73                 private Label label_comment;
74                 private CollatePreview collate;
75                 private bool use_ex_dialog;
76
77                 public PrintDialog ()
78                 {
79                         form = new DialogForm (this);
80                         help_button = null;
81                         installed_printers = System.Drawing.Printing.PrinterSettings.InstalledPrinters;
82
83                         form.Text = "Print";
84                         CreateFormControls ();
85                         Reset ();
86                 }
87
88                 public override void Reset ()
89                 {
90                         current_settings = null;
91                         AllowPrintToFile = true;
92                         AllowSelection = false;
93                         AllowSomePages = false;
94                         PrintToFile = false;
95                         ShowHelp = false;
96                         ShowNetwork = true;
97                 }
98
99                 [DefaultValue (false)]
100                 public bool AllowCurrentPage {
101                         get {
102                                 return allow_current_page;
103                         }
104
105                         set {
106                                 allow_current_page = value;
107                                 radio_pages.Enabled = value;
108                         }
109                 }
110
111                 [DefaultValue(true)]
112                 public bool AllowPrintToFile {
113                         get {
114                                 return allow_print_to_file;
115                         }
116
117                         set {
118                                 allow_print_to_file = value;
119                                 chkbox_print.Enabled = value;
120                         }
121                 }
122
123                 [DefaultValue(false)]
124                 public bool AllowSelection {
125                         get {
126                                 return allow_selection;
127                         }
128
129                         set {
130                                 allow_selection = value;
131                                 radio_sel.Enabled = value;
132                         }
133                 }
134
135                 [DefaultValue(false)]
136                 public bool AllowSomePages {
137                         get {
138                                 return allow_some_pages;
139                         }
140
141                         set {
142                                 allow_some_pages = value;
143                                 radio_pages.Enabled = value;
144                                 txtFrom.Enabled = value;
145                                 txtTo.Enabled = value;
146                                 labelTo.Enabled = value;
147                                 labelFrom.Enabled = value;
148
149                                 if (PrinterSettings != null) {
150                                         txtFrom.Text = PrinterSettings.FromPage.ToString ();
151                                         txtTo.Text = PrinterSettings.ToPage.ToString ();
152                                 }
153                         }
154                 }
155
156                 [DefaultValue(null)]
157                 public PrintDocument Document {
158                         get {
159                                 return document;
160                         }
161
162                         set {
163                                 document = value;
164                                 current_settings = (value == null) ? new PrinterSettings () : value.PrinterSettings;
165                         }
166                 }
167
168                 [Browsable(false)]
169                 [DefaultValue(null)]
170                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
171                 public PrinterSettings PrinterSettings {
172                         get {
173                                 if (current_settings == null)
174                                         current_settings = new PrinterSettings ();
175                                 return current_settings;
176                         }
177
178                         set {
179                                 if (value != null && value == current_settings)
180                                         return;
181
182                                 current_settings = (value == null) ? new PrinterSettings () : value;
183                                 document = null;
184                         }
185                 }
186
187                 [DefaultValue(false)]
188                 public bool PrintToFile {
189                         get {
190                                 return print_to_file;
191                         }
192
193                         set {
194                                 print_to_file = value;
195                         }
196                 }
197
198                 [DefaultValue(true)]
199                 public bool ShowNetwork {
200                         get {
201                                 return show_network;
202                         }
203
204                         set {
205                                 show_network = value;
206                         }
207                 }
208
209                 [DefaultValue(false)]
210                 public bool ShowHelp {
211                         get {
212                                 return show_help;
213                         }
214
215                         set {
216                                 show_help = value;
217                                 ShowHelpButton ();
218                         }
219                 }
220
221                 [MonoTODO ("Stub, not implemented, will always use default dialog")]
222                 [DefaultValue (false)]
223                 public bool UseEXDialog {
224                         get { return use_ex_dialog; }
225                         set { use_ex_dialog = value; }
226                 }
227
228                 protected override bool RunDialog (IntPtr hwndOwner)
229                 {
230                         if (allow_some_pages && PrinterSettings.FromPage > PrinterSettings.ToPage)
231                                 throw new ArgumentException ("FromPage out of range");
232
233                         if (allow_some_pages) {
234                                 txtFrom.Text = PrinterSettings.FromPage.ToString ();
235                                 txtTo.Text = PrinterSettings.ToPage.ToString ();
236                         }
237
238                         if (PrinterSettings.PrintRange == PrintRange.SomePages && allow_some_pages)
239                                 radio_pages.Checked = true;
240                         else if (PrinterSettings.PrintRange == PrintRange.Selection && allow_selection)
241                                 radio_sel.Checked = true;
242                         else
243                                 radio_all.Checked = true;
244
245                         updown_copies.Value = PrinterSettings.Copies == 0 ? 1 : (int) PrinterSettings.Copies;
246                         chkbox_collate.Checked = PrinterSettings.Collate;
247                         chkbox_collate.Enabled = (updown_copies.Value > 1) ? true : false;
248
249                         if (show_help) {
250                                 ShowHelpButton ();
251                         }
252
253                         SetPrinterDetails ();
254
255                         return true;
256                 }
257
258                 private void OnClickCancelButton (object sender, EventArgs e)
259                 {
260                         form.DialogResult = DialogResult.Cancel;
261                 }
262
263                 void ShowErrorMessage (string message, Control control_to_focus)
264                 {
265                         MessageBox.Show (message, "Print", MessageBoxButtons.OK, MessageBoxIcon.Warning);
266                         if (control_to_focus != null)
267                                 control_to_focus.Focus ();
268                 }
269
270                 private void OnClickOkButton (object sender, EventArgs e)
271                 {
272                         if (updown_copies.Text.Length < 1) {
273                                 ShowErrorMessage ("The 'Copies' value cannot be empty and must be a positive value.", 
274                                                 updown_copies);
275                                 return;
276                         }
277
278                         int from = -1, to = -1;
279
280                         if (allow_some_pages && radio_pages.Checked) {
281                                 if (txtFrom.Text.Length < 1) {
282                                         ShowErrorMessage ("The 'From' value cannot be empty and must be a positive value.",
283                                                         txtFrom);
284                                         return;
285                                 }
286
287                                 try {
288                                         from = Int32.Parse (txtFrom.Text);
289                                         to = Int32.Parse (txtTo.Text);
290                                 }
291                                 catch {
292                                         ShowErrorMessage ("From/To values should be numeric", txtFrom);
293                                         return;
294                                 }
295                                         
296                                 if (from > to) {
297                                         ShowErrorMessage ("'From' value cannot be greater than 'To' value.", txtFrom);
298                                         return;
299                                 }
300
301                                 if (to < PrinterSettings.MinimumPage || to > PrinterSettings.MaximumPage) {
302                                         ShowErrorMessage ("'To' value is not within the page range\n" +
303                                                         "Enter a number between " + PrinterSettings.MinimumPage +
304                                                         " and " + PrinterSettings.MaximumPage + ".", txtTo);
305                                         return;
306                                 }
307
308                                 if (from < PrinterSettings.MinimumPage || from > PrinterSettings.MaximumPage) {
309                                         ShowErrorMessage ("'From' value is not within the page range\n" +
310                                                         "Enter a number between " + PrinterSettings.MinimumPage +
311                                                         " and " + PrinterSettings.MaximumPage + ".", txtFrom);
312                                         return;
313                                 }
314                         }
315                         
316                         if (radio_all.Checked == true)
317                                 PrinterSettings.PrintRange = PrintRange.AllPages;
318                         else if (radio_pages.Checked == true)
319                                 PrinterSettings.PrintRange = PrintRange.SomePages;
320                         else
321                                 PrinterSettings.PrintRange = PrintRange.Selection;
322
323                         PrinterSettings.Copies = (short) updown_copies.Value;
324                         if (PrinterSettings.PrintRange == PrintRange.SomePages) {
325                                 PrinterSettings.FromPage = from;
326                                 PrinterSettings.ToPage = to;
327                         }
328                         PrinterSettings.Collate = chkbox_collate.Checked;
329
330                         if (allow_print_to_file) {
331                                 PrinterSettings.PrintToFile = chkbox_print.Checked;
332                         }
333
334                         form.DialogResult = DialogResult.OK;
335
336                         if (printer_combo.SelectedItem != null)
337                                 PrinterSettings.PrinterName = (string) printer_combo.SelectedItem;
338
339                         if (document != null) {
340                                 document.PrintController = new PrintControllerWithStatusDialog (document.PrintController);
341                                 document.PrinterSettings = PrinterSettings;
342                         }
343                 }
344
345                 private void ShowHelpButton ()
346                 {
347                         if (help_button == null) {
348                                 help_button = new Button ();
349                                 help_button.TabIndex = 60;
350
351                                 help_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
352                                 help_button.FlatStyle = FlatStyle.System;
353                                 help_button.Location = new Point (20, 270);
354                                 help_button.Text = "&Help";
355                                 help_button.FlatStyle = FlatStyle.System;
356                                 form.Controls.Add (help_button);
357                         }
358
359                         help_button.Visible = show_help;
360                 }
361
362                 private void OnUpDownValueChanged (object sender, System.EventArgs e)
363                 {
364                         chkbox_collate.Enabled = (updown_copies.Value > 1) ? true : false;
365                 }
366
367                 void OnPagesCheckedChanged (object obj, EventArgs args)
368                 {
369                         if (radio_pages.Checked && !txtTo.Focused)
370                                 txtFrom.Focus ();
371                 }
372
373                 private void CreateFormControls ()
374                 {
375                         form.SuspendLayout ();
376
377                         GroupBox group_box_prn = new GroupBox ();
378                         group_box_prn.Location = new Point (10, 8);
379                         group_box_prn.Text = "Printer";
380                         group_box_prn.Size = new Size (420, 145);
381
382                         GroupBox group_box_range = new GroupBox ();
383                         group_box_range.Location = new Point (10, 155);
384                         group_box_range.Text = "Print range";
385                         group_box_range.Size = new Size (240, 100);
386
387                         GroupBox group_box_copies = new GroupBox ();
388                         group_box_copies.Location = new Point (265, 155);
389                         group_box_copies.Text = "Copies";
390                         group_box_copies.Size = new Size (165, 100);
391
392                         // Accept button
393                         accept_button = new Button ();
394                         form.AcceptButton = accept_button;
395                         accept_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
396                         accept_button.FlatStyle = FlatStyle.System;
397                         accept_button.Location = new Point (265, 270);
398                         accept_button.Text = "OK";
399                         accept_button.FlatStyle = FlatStyle.System;
400                         accept_button.Click += new EventHandler (OnClickOkButton);
401
402                         // Cancel button
403                         cancel_button = new Button ();
404                         form.CancelButton = cancel_button;
405                         cancel_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
406                         cancel_button.FlatStyle = FlatStyle.System;
407                         cancel_button.Location = new Point (350, 270);
408                         cancel_button.Text = "Cancel";
409                         cancel_button.FlatStyle = FlatStyle.System;
410                         cancel_button.Click += new EventHandler (OnClickCancelButton);
411
412                         // Static controls
413                         Label label = new Label ();
414                         label.AutoSize = true;
415                         label.Text = "&Name:";
416                         label.Location = new Point (20, 33);
417                         group_box_prn.Controls.Add (label);
418
419                         label = new Label ();
420                         label.Text = "Status:";
421                         label.AutoSize = true;
422                         label.Location = new Point (20, 60);
423                         group_box_prn.Controls.Add (label);
424
425                         label_status = new Label ();
426                         label_status.AutoSize = true;
427                         label_status.Location = new Point (80, 60);
428                         group_box_prn.Controls.Add (label_status);
429
430                         label = new Label ();
431                         label.Text = "Type:";
432                         label.AutoSize = true;
433                         label.Location = new Point (20, 80);
434                         group_box_prn.Controls.Add (label);
435
436                         label_type = new Label ();
437                         label_type.AutoSize = true;
438                         label_type.Location = new Point (80, 80);
439                         group_box_prn.Controls.Add (label_type);
440
441                         label = new Label ();
442                         label.Text = "Where:";
443                         label.AutoSize = true;
444                         label.Location = new Point (20, 100);
445                         group_box_prn.Controls.Add (label);
446                         
447                         label_where = new Label ();
448                         label_where.AutoSize = true;
449                         label_where.Location = new Point (80, 100);
450                         group_box_prn.Controls.Add (label_where);
451
452                         label = new Label ();
453                         label.Text = "Comment:";
454                         label.AutoSize = true;
455                         label.Location = new Point (20, 120);
456                         group_box_prn.Controls.Add (label);
457
458                         label_comment = new Label ();
459                         label_comment.AutoSize = true;
460                         label_comment.Location = new Point (80, 120);
461                         group_box_prn.Controls.Add (label_comment);
462
463                         radio_all = new RadioButton ();
464                         radio_all.TabIndex = 21;
465                         radio_all.Location = new Point (20, 20);
466                         radio_all.Text = "&All";
467                         radio_all.Checked = true;
468                         group_box_range.Controls.Add (radio_all);
469
470                         radio_pages = new RadioButton ();
471                         radio_pages.TabIndex = 22;
472                         radio_pages.Location = new Point (20, 46);
473                         radio_pages.Text = "Pa&ges";
474                         radio_pages.Width = 60;
475                         radio_pages.CheckedChanged += new EventHandler (OnPagesCheckedChanged);
476                         group_box_range.Controls.Add (radio_pages);
477
478                         radio_sel = new RadioButton ();
479                         radio_sel.TabIndex = 23;
480                         radio_sel.Location = new Point (20, 72);
481                         radio_sel.Text = "&Selection";
482                         group_box_range.Controls.Add (radio_sel);
483
484                         labelFrom = new Label ();
485                         labelFrom.Text = "&from:";
486                         labelFrom.TabIndex = 24;
487                         labelFrom.AutoSize = true;
488                         labelFrom.Location = new Point (80, 50);
489                         group_box_range.Controls.Add (labelFrom);
490
491                         txtFrom = new TextBox ();
492                         txtFrom.TabIndex = 25;
493                         txtFrom.Location = new Point (120, 50);
494                         txtFrom.Width = 40;
495                         txtFrom.TextChanged += new EventHandler (OnPagesTextChanged);
496                         group_box_range.Controls.Add (txtFrom);
497
498                         labelTo = new Label ();
499                         labelTo.Text = "&to:";
500                         labelTo.TabIndex = 26;
501                         labelTo.AutoSize = true;
502                         labelTo.Location = new Point (170, 50);
503                         group_box_range.Controls.Add (labelTo);
504
505                         txtTo = new TextBox ();
506                         txtTo.TabIndex = 27;
507                         txtTo.Location = new Point (190, 50);
508                         txtTo.Width = 40;
509                         txtTo.TextChanged += new EventHandler (OnPagesTextChanged);
510                         group_box_range.Controls.Add (txtTo);
511
512                         chkbox_print = new CheckBox ();
513                         chkbox_print.Location = new Point (305, 115);
514                         chkbox_print.Text = "Print to fil&e";
515
516
517                         updown_copies = new NumericUpDown ();
518                         updown_copies.TabIndex = 31;
519                         updown_copies.Location = new Point (105, 18);
520                         updown_copies.Minimum = 1;
521                         group_box_copies.Controls.Add (updown_copies);
522                         updown_copies.ValueChanged += new System.EventHandler (OnUpDownValueChanged);
523                         updown_copies.Size = new System.Drawing.Size (40, 20);
524
525                         label = new Label ();
526                         label.Text = "Number of &copies:";
527                         label.AutoSize = true;
528                         label.Location = new Point (10, 20);
529                         group_box_copies.Controls.Add (label);
530
531                         chkbox_collate = new CheckBox ();
532                         chkbox_collate.TabIndex = 32;
533                         chkbox_collate.Location = new Point (105, 55);
534                         chkbox_collate.Text = "C&ollate";
535                         chkbox_collate.Width = 58;
536                         chkbox_collate.CheckedChanged += new EventHandler(chkbox_collate_CheckedChanged);
537                 
538                         group_box_copies.Controls.Add (chkbox_collate);
539
540                         collate = new CollatePreview ();
541                         collate.Location = new Point (6, 50);
542                         collate.Size = new Size (100, 45);
543                         group_box_copies.Controls.Add (collate);
544                         
545
546
547                         // Printer combo
548                         printer_combo = new ComboBox ();
549                         printer_combo.DropDownStyle = ComboBoxStyle.DropDownList;
550                         printer_combo.Location = new Point (80, 32);
551                         printer_combo.Width = 220;
552                         printer_combo.SelectedIndexChanged += new EventHandler (OnPrinterSelectedIndexChanged);
553
554                         default_printer_settings = new PrinterSettings ();
555                         for (int i = 0; i < installed_printers.Count; i++) {
556                                 printer_combo.Items.Add (installed_printers[i]);
557                                 if (installed_printers[i] == default_printer_settings.PrinterName)
558                                         printer_combo.SelectedItem = installed_printers[i];
559                         }
560                         printer_combo.TabIndex = 11;
561                         chkbox_print.TabIndex = 12;
562                         group_box_prn.Controls.Add (printer_combo);
563                         group_box_prn.Controls.Add (chkbox_print);
564
565                         form.Size =  new Size (450, 327); // 384
566                         form.FormBorderStyle = FormBorderStyle.FixedDialog;
567                         form.MaximizeBox = false;
568                         group_box_prn.TabIndex = 10;
569                         group_box_range.TabIndex = 20;
570                         group_box_copies.TabIndex = 30;
571                         accept_button.TabIndex = 40;
572                         cancel_button.TabIndex = 50;
573                         form.Controls.Add (group_box_prn);
574                         form.Controls.Add (group_box_range);
575                         form.Controls.Add (group_box_copies);
576                         form.Controls.Add (accept_button);
577                         form.Controls.Add (cancel_button);
578                         form.ResumeLayout (false);
579                 }
580
581                 void OnPagesTextChanged (object sender, EventArgs args)
582                 {
583                         radio_pages.Checked = true;
584                 }
585
586                 private void OnPrinterSelectedIndexChanged (object sender,  System.EventArgs e) 
587                 {
588                         SetPrinterDetails ();
589                 }
590
591                 private void SetPrinterDetails ()
592                 {
593                         try
594                         {
595                                 string printer, port = string.Empty, type = string.Empty;
596                                 string status = string.Empty, comment = string.Empty;
597                                 Type sysprn = Type.GetType ("System.Drawing.Printing.SysPrn, System.Drawing");
598                                 MethodInfo dlg_info = sysprn.GetMethod ("GetPrintDialogInfo", BindingFlags.Static | BindingFlags.NonPublic);
599
600                                 printer = (string) printer_combo.SelectedItem;
601
602                                 if (printer != null) {
603                                         object[] args  = new object [5];
604                                         args[0] = printer;
605                                         args[1] = port;
606                                         args[2] = type;
607                                         args[3] = status;
608                                         args[4] = comment;
609                                         dlg_info.Invoke (null, args);
610                                         port = (string) args[1];
611                                         type = (string) args[2];
612                                         status = (string) args[3];
613                                         comment = (string) args[4];
614                                 }
615
616                                 label_status.Text = status;
617                                 label_type.Text = type;
618                                 label_where.Text = port;
619                                 label_comment.Text = comment;
620
621                                 accept_button.Enabled = true;
622                         }
623                         catch  {
624                                 accept_button.Enabled = false;
625                         }
626                 }
627
628                 private void chkbox_collate_CheckedChanged(object sender, EventArgs e) {
629                         collate.Collate = chkbox_collate.Checked;
630                 }
631
632                 class CollatePreview : UserControl 
633                 {       
634                         private bool collate;
635                         public bool Collate {
636                                 get { return collate;}
637                                 set { if (collate != value) {
638                                                   collate = value;
639                                                   Invalidate();
640                                           }
641                                 }
642                         }
643
644                         new Font font;
645
646                         public CollatePreview () 
647                         {
648                                 font = new Font(FontFamily.GenericSansSerif, 10);
649                         }
650                         
651                         protected override void OnPaint(PaintEventArgs e) 
652                         {
653                                 if (collate)
654                                         DrawCollate (e.Graphics);
655                                 else
656                                         DrawNoCollate (e.Graphics);
657
658                                 base.OnPaint (e);
659                         }
660
661                         void DrawCollate (Graphics g)
662                         {
663                                 int x1 = 0;
664                                 int y1 = 12;
665
666                                 int x2 = 14;
667                                 int y2 = 6;
668
669                                 int x3 = 26;
670                                 int y3 = 0;
671
672                                 for (int i = 0; i < 2; i++) {
673                                         
674                                         g.FillRectangle (Brushes.White, x3 + (i*18), y3, 18, 24);
675                                         ControlPaint.DrawBorder (g, new Rectangle (x3 + (i*18), y3, 18, 24), SystemColors.ControlDark, ButtonBorderStyle.Solid);
676                                         g.DrawString ((i+1).ToString(), font, SystemBrushes.ControlDarkDark, x3 + (i*18) + 5, y3 + 5, StringFormat.GenericTypographic);
677
678                                         g.FillRectangle (Brushes.White, x2 + (i*18), y2, 18, 24);
679                                         ControlPaint.DrawBorder (g, new Rectangle (x2 + (i*18), y2, 18, 24), SystemColors.ControlDark, ButtonBorderStyle.Solid);
680                                         g.DrawString ((i+1).ToString(), font, SystemBrushes.ControlDarkDark, x2 + (i*18) + 5, y2 + 5, StringFormat.GenericTypographic);
681                                 
682                                         g.FillRectangle (Brushes.White, x1 + (i*18), y1, 18, 24);
683                                         ControlPaint.DrawBorder (g, new Rectangle (x1 + (i*18), y1, 18, 24), SystemColors.ControlDark, ButtonBorderStyle.Solid);
684                                         g.DrawString ((i+1).ToString(), font, SystemBrushes.ControlDarkDark, x1 + (i*18) + 5, y1 + 5, StringFormat.GenericTypographic);
685
686
687                                         x1 += 28;
688                                         x2 += 28;
689                                         x3 += 28;
690                                 }
691                         }
692
693                         void DrawNoCollate (Graphics g) 
694                         {
695                                 int x1 = 0;
696                                 int y1 = 12;
697
698                                 int x2 = 13;
699                                 int y2 = 4;
700
701                                 for (int i = 0; i < 3; i++) {
702                                         
703                                         g.FillRectangle (Brushes.White, x2 + (i*18), y2, 18, 24);
704                                         ControlPaint.DrawBorder (g, new Rectangle (x2 + (i*18), y2, 18, 24), SystemColors.ControlDark, ButtonBorderStyle.Solid);
705                                         g.DrawString ((i+1).ToString(), font, SystemBrushes.ControlDarkDark, x2 + (i*18) + 5, y2 + 5, StringFormat.GenericTypographic);
706                                 
707                                         g.FillRectangle (Brushes.White, x1 + (i*18), y1, 18, 24);
708                                         ControlPaint.DrawBorder (g, new Rectangle (x1 + (i*18), y1, 18, 24), SystemColors.ControlDark, ButtonBorderStyle.Solid);
709                                         g.DrawString ((i+1).ToString(), font, SystemBrushes.ControlDarkDark, x1 + (i*18) + 5, y1 + 5, StringFormat.GenericTypographic);
710
711                                         x1 += 15;
712                                         x2 += 15;
713                                 }
714                         }
715                 }
716         }
717 }