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