123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using System;
- using System.Windows.Forms;
- using FastReport.Utils;
- using FastReport.Export;
- namespace FastReport.Forms
- {
- /// <summary>
- /// Base form for all export options dialog forms.
- /// </summary>
- public partial class BaseExportForm : BaseDialogForm
- {
- /// <summary>
- /// Represents the "Open after export" button visibility.
- /// </summary>
- public bool OpenAfterVisible
- {
- get
- {
- return cbOpenAfter.Visible;
- }
- set
- {
- cbOpenAfter.Visible = value;
- }
- }
- private ExportBase export;
- /// <summary>
- /// Gets a reference to the currently editing export filter.
- /// </summary>
- protected ExportBase Export
- {
- get { return export; }
- }
- private void tbNumbers_KeyPress(object sender, KeyPressEventArgs e)
- {
- rbNumbers.Checked = true;
- }
- private void rbCurrent_CheckedChanged(object sender, EventArgs e)
- {
- if ((sender as RadioButton).Checked)
- tbNumbers.Text = "";
- }
- /// <inheritdoc/>
- protected override void OnFormClosing(FormClosingEventArgs e)
- {
- base.OnFormClosing(e);
- if (DialogResult == DialogResult.OK)
- {
- string s = tbNumbers.Text;
- foreach (char c in s)
- {
- if (!(c == ' ' || c == ',' || c == '-' || (c >= '0' && c <= '9')))
- {
- FRMessageBox.Error(Res.Get("Forms,PrinterSetup,Error") + "\r\n" +
- Res.Get("Forms,PrinterSetup,Hint"));
- tbNumbers.Focus();
- e.Cancel = true;
- break;
- }
- }
- }
- }
- /// <inheritdoc/>
- protected override void OnFormClosed(FormClosedEventArgs e)
- {
- base.OnFormClosed(e);
- if (DialogResult == DialogResult.OK)
- Done();
- }
- /// <summary>
- /// Called when editing is done.
- /// </summary>
- /// <remarks>
- /// Override this method to pass edited values from the dialog controls to the export filter.
- /// </remarks>
- /// <example>See the example of this method implementation that is used in the <b>ImageExport</b>.
- /// <code>
- /// protected override void Done()
- /// {
- /// base.Done();
- /// ImageExport imageExport = Export as ImageExport;
- /// imageExport.ImageFormat = (ImageExportFormat)cbxImageFormat.SelectedIndex;
- /// imageExport.Resolution = (int)udResolution.Value;
- /// imageExport.JpegQuality = (int)udQuality.Value;
- /// imageExport.SeparateFiles = cbSeparateFiles.Checked;
- /// }
- /// </code>
- /// </example>
- protected virtual void Done()
- {
- if (rbAll.Checked)
- Export.PageRange = PageRange.All;
- else if (rbCurrent.Checked)
- Export.PageRange = PageRange.Current;
- else
- Export.PageRange = PageRange.PageNumbers;
- Export.PageNumbers = tbNumbers.Text;
- Export.OpenAfterExport = cbOpenAfter.Checked;
- Export.ExportAllTabs = cbExportAllTabs.Checked;
- }
- /// <inheritdoc/>
- public override void Localize()
- {
- base.Localize();
- MyRes res = new MyRes("Forms,PrinterSetup");
- gbPageRange.Text = res.Get("PageRange");
- rbAll.Text = res.Get("All");
- rbCurrent.Text = res.Get("Current");
- rbNumbers.Text = res.Get("Numbers");
- lblHint.Text = res.Get("Hint");
- cbOpenAfter.Text = Res.Get("Export,Misc,OpenAfterExport");
- cbExportAllTabs.Text = Res.Get("Export,Misc,ExportAllTabs");
- }
- /// <summary>
- /// Initializes controls with initial values.
- /// </summary>
- /// <param name="export">The export filter to edit.</param>
- /// <remarks>
- /// Override this method to pass values from the export filter to the dialog controls.
- /// </remarks>
- /// <example>See the example of this method implementation that is used in the <b>ImageExport</b>.
- /// <code>
- /// public override void Init(ExportBase export)
- /// {
- /// base.Init(export);
- /// ImageExport imageExport = Export as ImageExport;
- /// cbxImageFormat.SelectedIndex = (int)imageExport.ImageFormat;
- /// udResolution.Value = imageExport.Resolution;
- /// udQuality.Value = imageExport.JpegQuality;
- /// cbSeparateFiles.Checked = imageExport.SeparateFiles;
- /// }
- /// </code>
- /// </example>
- public virtual void Init(ExportBase export)
- {
- this.export = export;
- Localize();
- rbAll.Checked = Export.PageRange == PageRange.All;
- rbCurrent.Checked = Export.PageRange == PageRange.Current;
- rbNumbers.Checked = Export.PageRange == PageRange.PageNumbers;
- tbNumbers.Text = Export.PageNumbers;
- cbOpenAfter.Checked = Export.OpenAfterExport;
- cbOpenAfter.Enabled = export.AllowOpenAfter;
- cbExportAllTabs.Enabled = Export.TabsIsExists;
- cbExportAllTabs.Checked = Export.ExportAllTabs;
- }
- /// <inheritdoc/>
- public bool ShowDialog(ExportBase export)
- {
- Init(export);
- UIUtils.CheckRTL(this);
- UpdateDpiDependencies();
- return ShowDialog() == DialogResult.OK;
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="BaseExportForm"/> class with default settings.
- /// </summary>
- public BaseExportForm()
- {
- InitializeComponent();
- }
- }
- }
|