BaseExportForm.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System;
  2. using System.Windows.Forms;
  3. using FastReport.Utils;
  4. using FastReport.Export;
  5. namespace FastReport.Forms
  6. {
  7. /// <summary>
  8. /// Base form for all export options dialog forms.
  9. /// </summary>
  10. public partial class BaseExportForm : BaseDialogForm
  11. {
  12. /// <summary>
  13. /// Represents the "Open after export" button visibility.
  14. /// </summary>
  15. public bool OpenAfterVisible
  16. {
  17. get
  18. {
  19. return cbOpenAfter.Visible;
  20. }
  21. set
  22. {
  23. cbOpenAfter.Visible = value;
  24. }
  25. }
  26. private ExportBase export;
  27. /// <summary>
  28. /// Gets a reference to the currently editing export filter.
  29. /// </summary>
  30. protected ExportBase Export
  31. {
  32. get { return export; }
  33. }
  34. private void tbNumbers_KeyPress(object sender, KeyPressEventArgs e)
  35. {
  36. rbNumbers.Checked = true;
  37. }
  38. private void rbCurrent_CheckedChanged(object sender, EventArgs e)
  39. {
  40. if ((sender as RadioButton).Checked)
  41. tbNumbers.Text = "";
  42. }
  43. /// <inheritdoc/>
  44. protected override void OnFormClosing(FormClosingEventArgs e)
  45. {
  46. base.OnFormClosing(e);
  47. if (DialogResult == DialogResult.OK)
  48. {
  49. string s = tbNumbers.Text;
  50. foreach (char c in s)
  51. {
  52. if (!(c == ' ' || c == ',' || c == '-' || (c >= '0' && c <= '9')))
  53. {
  54. FRMessageBox.Error(Res.Get("Forms,PrinterSetup,Error") + "\r\n" +
  55. Res.Get("Forms,PrinterSetup,Hint"));
  56. tbNumbers.Focus();
  57. e.Cancel = true;
  58. break;
  59. }
  60. }
  61. }
  62. }
  63. /// <inheritdoc/>
  64. protected override void OnFormClosed(FormClosedEventArgs e)
  65. {
  66. base.OnFormClosed(e);
  67. if (DialogResult == DialogResult.OK)
  68. Done();
  69. }
  70. /// <summary>
  71. /// Called when editing is done.
  72. /// </summary>
  73. /// <remarks>
  74. /// Override this method to pass edited values from the dialog controls to the export filter.
  75. /// </remarks>
  76. /// <example>See the example of this method implementation that is used in the <b>ImageExport</b>.
  77. /// <code>
  78. /// protected override void Done()
  79. /// {
  80. /// base.Done();
  81. /// ImageExport imageExport = Export as ImageExport;
  82. /// imageExport.ImageFormat = (ImageExportFormat)cbxImageFormat.SelectedIndex;
  83. /// imageExport.Resolution = (int)udResolution.Value;
  84. /// imageExport.JpegQuality = (int)udQuality.Value;
  85. /// imageExport.SeparateFiles = cbSeparateFiles.Checked;
  86. /// }
  87. /// </code>
  88. /// </example>
  89. protected virtual void Done()
  90. {
  91. if (rbAll.Checked)
  92. Export.PageRange = PageRange.All;
  93. else if (rbCurrent.Checked)
  94. Export.PageRange = PageRange.Current;
  95. else
  96. Export.PageRange = PageRange.PageNumbers;
  97. Export.PageNumbers = tbNumbers.Text;
  98. Export.OpenAfterExport = cbOpenAfter.Checked;
  99. Export.ExportAllTabs = cbExportAllTabs.Checked;
  100. }
  101. /// <inheritdoc/>
  102. public override void Localize()
  103. {
  104. base.Localize();
  105. MyRes res = new MyRes("Forms,PrinterSetup");
  106. gbPageRange.Text = res.Get("PageRange");
  107. rbAll.Text = res.Get("All");
  108. rbCurrent.Text = res.Get("Current");
  109. rbNumbers.Text = res.Get("Numbers");
  110. lblHint.Text = res.Get("Hint");
  111. cbOpenAfter.Text = Res.Get("Export,Misc,OpenAfterExport");
  112. cbExportAllTabs.Text = Res.Get("Export,Misc,ExportAllTabs");
  113. }
  114. /// <summary>
  115. /// Initializes controls with initial values.
  116. /// </summary>
  117. /// <param name="export">The export filter to edit.</param>
  118. /// <remarks>
  119. /// Override this method to pass values from the export filter to the dialog controls.
  120. /// </remarks>
  121. /// <example>See the example of this method implementation that is used in the <b>ImageExport</b>.
  122. /// <code>
  123. /// public override void Init(ExportBase export)
  124. /// {
  125. /// base.Init(export);
  126. /// ImageExport imageExport = Export as ImageExport;
  127. /// cbxImageFormat.SelectedIndex = (int)imageExport.ImageFormat;
  128. /// udResolution.Value = imageExport.Resolution;
  129. /// udQuality.Value = imageExport.JpegQuality;
  130. /// cbSeparateFiles.Checked = imageExport.SeparateFiles;
  131. /// }
  132. /// </code>
  133. /// </example>
  134. public virtual void Init(ExportBase export)
  135. {
  136. this.export = export;
  137. Localize();
  138. rbAll.Checked = Export.PageRange == PageRange.All;
  139. rbCurrent.Checked = Export.PageRange == PageRange.Current;
  140. rbNumbers.Checked = Export.PageRange == PageRange.PageNumbers;
  141. tbNumbers.Text = Export.PageNumbers;
  142. cbOpenAfter.Checked = Export.OpenAfterExport;
  143. cbOpenAfter.Enabled = export.AllowOpenAfter;
  144. cbExportAllTabs.Enabled = Export.TabsIsExists;
  145. cbExportAllTabs.Checked = Export.ExportAllTabs;
  146. }
  147. /// <inheritdoc/>
  148. public bool ShowDialog(ExportBase export)
  149. {
  150. Init(export);
  151. UIUtils.CheckRTL(this);
  152. UpdateDpiDependencies();
  153. return ShowDialog() == DialogResult.OK;
  154. }
  155. /// <summary>
  156. /// Initializes a new instance of the <see cref="BaseExportForm"/> class with default settings.
  157. /// </summary>
  158. public BaseExportForm()
  159. {
  160. InitializeComponent();
  161. }
  162. }
  163. }