DialogPage.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. using System;
  2. using System.Drawing;
  3. using System.ComponentModel;
  4. using System.Windows.Forms;
  5. using System.Drawing.Design;
  6. using FastReport.Utils;
  7. using System.Threading.Tasks;
  8. #if !FRCORE
  9. using FastReport.Forms;
  10. #endif
  11. namespace FastReport.Dialog
  12. {
  13. /// <summary>
  14. /// Represents the special kind of report page that wraps the <see cref="System.Windows.Forms.Form"/>
  15. /// and used to display dialog forms.
  16. /// </summary>
  17. /// <remarks>
  18. /// Use the <see cref="Controls"/> property to add/remove controls to/from a dialog form.
  19. /// <para/>If you set the <b>Visible</b> property to <b>false</b>, this dialog form will be
  20. /// skippen when you run a report.
  21. /// </remarks>
  22. /// <example>This example shows how to create a dialog form with one button in code.
  23. /// <code>
  24. /// DialogPage form = new DialogPage();
  25. /// // set the width and height in pixels
  26. /// form.Width = 200;
  27. /// form.Height = 200;
  28. /// form.Name = "Form1";
  29. /// // create a button
  30. /// ButtonControl button = new ButtonControl();
  31. /// button.Location = new Point(20, 20);
  32. /// button.Size = new Size(75, 25);
  33. /// button.Text = "The button";
  34. /// // add the button to the form
  35. /// form.Controls.Add(button);
  36. /// </code>
  37. /// </example>
  38. public partial class DialogPage : PageBase, IParent
  39. {
  40. #region Fields
  41. private ButtonControl acceptButton;
  42. private ButtonControl cancelButton;
  43. #if !FRCORE
  44. private BaseForm form;
  45. #else
  46. private Form form;
  47. #endif
  48. private DialogComponentCollection controls;
  49. private string loadEvent;
  50. private string formClosedEvent;
  51. private string formClosingEvent;
  52. private string shownEvent;
  53. private string resizeEvent;
  54. private string paintEvent;
  55. private DialogControl errorControl;
  56. private Color errorControlBackColor;
  57. private Timer errorControlTimer;
  58. private int errorControlTimerTickCount;
  59. private bool activeInWeb;
  60. private int oldDpi;
  61. #endregion
  62. #region Properties
  63. /// <summary>
  64. /// Occurs before a form is displayed for the first time.
  65. /// Wraps the <see cref="System.Windows.Forms.Form.Load"/> event.
  66. /// </summary>
  67. public event EventHandler Load;
  68. /// <summary>
  69. /// Occurs after the form is closed.
  70. /// Wraps the <see cref="System.Windows.Forms.Form.FormClosed"/> event.
  71. /// </summary>
  72. public event FormClosedEventHandler FormClosed;
  73. /// <summary>
  74. /// Occurs before the form is closed.
  75. /// Wraps the <see cref="System.Windows.Forms.Form.FormClosing"/> event.
  76. /// </summary>
  77. public event FormClosingEventHandler FormClosing;
  78. /// <summary>
  79. /// Occurs whenever the form is first displayed.
  80. /// Wraps the <see cref="System.Windows.Forms.Form.Shown"/> event.
  81. /// </summary>
  82. public event EventHandler Shown;
  83. /// <summary>
  84. /// Occurs when the form is resized.
  85. /// Wraps the <see cref="System.Windows.Forms.Control.Resize"/> event.
  86. /// </summary>
  87. public event EventHandler Resize;
  88. /// <summary>
  89. /// Occurs when the form is redrawn.
  90. /// Wraps the <see cref="System.Windows.Forms.Control.Paint"/> event.
  91. /// </summary>
  92. public event PaintEventHandler Paint;
  93. /// <summary>
  94. /// Gets an internal <b>Form</b>.
  95. /// </summary>
  96. [Browsable(false)]
  97. #if !FRCORE
  98. public BaseForm Form
  99. #else
  100. public Form Form
  101. #endif
  102. {
  103. get { return form; }
  104. }
  105. /// <summary>
  106. /// Gets or sets an active state in Web application.
  107. /// </summary>
  108. [Browsable(false)]
  109. public bool ActiveInWeb
  110. {
  111. get { return activeInWeb; }
  112. set { activeInWeb = value; }
  113. }
  114. /// <summary>
  115. /// Gets or sets the button on the form that is clicked when the user presses the ENTER key.
  116. /// Wraps the <see cref="System.Windows.Forms.Form.AcceptButton"/> property.
  117. /// </summary>
  118. [Category("Misc")]
  119. [Editor("FastReport.TypeEditors.PageComponentRefEditor, FastReport", typeof(UITypeEditor))]
  120. [TypeConverter(typeof(FastReport.TypeConverters.ComponentRefConverter))]
  121. public ButtonControl AcceptButton
  122. {
  123. get { return acceptButton; }
  124. set
  125. {
  126. if (acceptButton != value)
  127. {
  128. if (acceptButton != null)
  129. acceptButton.Disposed -= new EventHandler(AcceptButton_Disposed);
  130. if (value != null)
  131. value.Disposed += new EventHandler(AcceptButton_Disposed);
  132. }
  133. acceptButton = value;
  134. Form.AcceptButton = value == null ? null : value.Button;
  135. }
  136. }
  137. /// <summary>
  138. /// Gets or sets the button control that is clicked when the user presses the ESC key.
  139. /// Wraps the <see cref="System.Windows.Forms.Form.CancelButton"/> property.
  140. /// </summary>
  141. [Category("Misc")]
  142. [Editor("FastReport.TypeEditors.PageComponentRefEditor, FastReport", typeof(UITypeEditor))]
  143. [TypeConverter(typeof(FastReport.TypeConverters.ComponentRefConverter))]
  144. public ButtonControl CancelButton
  145. {
  146. get { return cancelButton; }
  147. set
  148. {
  149. if (cancelButton != value)
  150. {
  151. if (cancelButton != null)
  152. cancelButton.Disposed -= new EventHandler(CancelButton_Disposed);
  153. if (value != null)
  154. value.Disposed += new EventHandler(CancelButton_Disposed);
  155. }
  156. cancelButton = value;
  157. Form.CancelButton = value == null ? null : value.Button;
  158. }
  159. }
  160. /// <summary>
  161. /// Gets the auto scale dimensions for this form.
  162. /// </summary>
  163. public SizeF AutoScaleDimensions
  164. {
  165. get { return Form.AutoScaleDimensions; }
  166. set { Form.AutoScaleDimensions = value; }
  167. }
  168. /// <summary>
  169. /// Gets or sets the background color for the form.
  170. /// Wraps the <see cref="System.Windows.Forms.Form.BackColor"/> property.
  171. /// </summary>
  172. [Category("Appearance")]
  173. [Editor("FastReport.TypeEditors.ColorEditor, FastReport", typeof(UITypeEditor))]
  174. public Color BackColor
  175. {
  176. get { return Form.BackColor; }
  177. set
  178. {
  179. Form.BackColor = value;
  180. ResetFormBitmap();
  181. }
  182. }
  183. /// <summary>
  184. /// Gets or sets the font of the text displayed by the control.
  185. /// Wraps the <see cref="System.Windows.Forms.Control.Font"/> property.
  186. /// </summary>
  187. [Category("Appearance")]
  188. public Font Font
  189. {
  190. get { return Form.Font; }
  191. set { Form.Font = value; }
  192. }
  193. /// <summary>
  194. /// Gets or sets the border style of the form.
  195. /// Wraps the <see cref="System.Windows.Forms.Form.FormBorderStyle"/> property.
  196. /// </summary>
  197. [DefaultValue(FormBorderStyle.FixedDialog)]
  198. [Category("Appearance")]
  199. public FormBorderStyle FormBorderStyle
  200. {
  201. get { return Form.FormBorderStyle; }
  202. set
  203. {
  204. Form.FormBorderStyle = value;
  205. ResetFormBitmap();
  206. }
  207. }
  208. /// <summary>
  209. /// Gets or sets a value indicating whether control's elements are aligned to support locales using right-to-left fonts.
  210. /// Wraps the <see cref="System.Windows.Forms.Control.RightToLeft"/> property.
  211. /// </summary>
  212. [DefaultValue(RightToLeft.No)]
  213. [Category("Appearance")]
  214. public RightToLeft RightToLeft
  215. {
  216. get { return Form.RightToLeft; }
  217. set
  218. {
  219. Form.RightToLeft = value;
  220. ResetFormBitmap();
  221. }
  222. }
  223. /// <summary>
  224. /// Gets or sets the text associated with this form.
  225. /// Wraps the <see cref="System.Windows.Forms.Form.Text"/> property.
  226. /// </summary>
  227. [Category("Appearance")]
  228. public string Text
  229. {
  230. get { return Form.Text; }
  231. set
  232. {
  233. Form.Text = value;
  234. ResetFormBitmap();
  235. }
  236. }
  237. /// <summary>
  238. /// Gets or sets a script method name that will be used to handle the
  239. /// <see cref="Load"/> event.
  240. /// </summary>
  241. [Category("Events")]
  242. public string LoadEvent
  243. {
  244. get { return loadEvent; }
  245. set { loadEvent = value; }
  246. }
  247. /// <summary>
  248. /// Gets or sets a script method name that will be used to handle the
  249. /// <see cref="FormClosed"/> event.
  250. /// </summary>
  251. [Category("Events")]
  252. public string FormClosedEvent
  253. {
  254. get { return formClosedEvent; }
  255. set { formClosedEvent = value; }
  256. }
  257. /// <summary>
  258. /// Gets or sets a script method name that will be used to handle the
  259. /// <see cref="FormClosing"/> event.
  260. /// </summary>
  261. [Category("Events")]
  262. public string FormClosingEvent
  263. {
  264. get { return formClosingEvent; }
  265. set { formClosingEvent = value; }
  266. }
  267. /// <summary>
  268. /// Gets or sets a script method name that will be used to handle the
  269. /// <see cref="Shown"/> event.
  270. /// </summary>
  271. [Category("Events")]
  272. public string ShownEvent
  273. {
  274. get { return shownEvent; }
  275. set { shownEvent = value; }
  276. }
  277. /// <summary>
  278. /// Gets or sets a script method name that will be used to handle the
  279. /// <see cref="Resize"/> event.
  280. /// </summary>
  281. [Category("Events")]
  282. public string ResizeEvent
  283. {
  284. get { return resizeEvent; }
  285. set { resizeEvent = value; }
  286. }
  287. /// <summary>
  288. /// Gets or sets a script method name that will be used to handle the
  289. /// <see cref="Paint"/> event.
  290. /// </summary>
  291. [Category("Events")]
  292. public string PaintEvent
  293. {
  294. get { return paintEvent; }
  295. set { paintEvent = value; }
  296. }
  297. /// <summary>
  298. /// Gets the collection of controls contained within the form.
  299. /// </summary>
  300. [Browsable(false)]
  301. public DialogComponentCollection Controls
  302. {
  303. get { return controls; }
  304. }
  305. /// <inheritdoc/>
  306. public override float Width
  307. {
  308. get { return Form.Width; }
  309. set
  310. {
  311. if (!IsDesigning || !HasRestriction(Restrictions.DontResize))
  312. Form.Width = Math.Max(10, (int)value);
  313. ResetFormBitmap();
  314. }
  315. }
  316. /// <inheritdoc/>
  317. public override float Height
  318. {
  319. get { return Form.Height; }
  320. set
  321. {
  322. if (!IsDesigning || !HasRestriction(Restrictions.DontResize))
  323. Form.Height = Math.Max(10, (int)value);
  324. ResetFormBitmap();
  325. }
  326. }
  327. /// <inheritdoc/>
  328. public override SizeF ClientSize
  329. {
  330. get { return new SizeF(Form.ClientSize.Width, Form.ClientSize.Height); }
  331. set { Form.ClientSize = new Size((int)value.Width, (int)value.Height); }
  332. }
  333. #endregion
  334. #region Private Methods
  335. private string CreateButtonName(string baseName)
  336. {
  337. if (Report.FindObject(baseName) == null)
  338. return baseName;
  339. int i = 1;
  340. while (Report.FindObject(baseName + i.ToString()) != null)
  341. {
  342. i++;
  343. }
  344. return baseName + i.ToString();
  345. }
  346. private void AcceptButton_Disposed(object sender, EventArgs e)
  347. {
  348. AcceptButton = null;
  349. }
  350. private void CancelButton_Disposed(object sender, EventArgs e)
  351. {
  352. CancelButton = null;
  353. }
  354. private void Form_Load(object sender, EventArgs e)
  355. {
  356. OnLoad(e);
  357. }
  358. private void Form_FormClosed(object sender, FormClosedEventArgs e)
  359. {
  360. OnFormClosed(e);
  361. }
  362. private void Form_FormClosing(object sender, FormClosingEventArgs e)
  363. {
  364. OnFormClosing(e);
  365. }
  366. private void Form_Shown(object sender, EventArgs e)
  367. {
  368. OnShown(e);
  369. }
  370. private void Form_Resize(object sender, EventArgs e)
  371. {
  372. OnResize(e);
  373. }
  374. private void Form_Paint(object sender, PaintEventArgs e)
  375. {
  376. OnPaint(e);
  377. }
  378. #if !FRCORE
  379. private void FixControlFonts(Control parent)
  380. {
  381. #if !AVALONIA
  382. float m = Form.Dpi() / (float)oldDpi;
  383. foreach (Control c in parent.Controls)
  384. {
  385. if (!c.Font.Equals(c.Parent.Font))
  386. {
  387. c.Font = new Font(c.Font.FontFamily, c.Font.Size * m, c.Font.Style);
  388. }
  389. FixControlFonts(c);
  390. }
  391. #endif
  392. }
  393. private void Form_DpiChanged(object sender, EventArgs e)
  394. {
  395. // take care of controls with non-standard fonts. Such fonts are not scaled automatically.
  396. FixControlFonts(Form);
  397. oldDpi = Form.Dpi();
  398. }
  399. #endif
  400. private void SetErrorControl(DialogControl control)
  401. {
  402. errorControl = control;
  403. if (control != null)
  404. {
  405. control.Focus();
  406. if (errorControlTimer == null)
  407. {
  408. errorControlTimerTickCount = 0;
  409. errorControlBackColor = errorControl.BackColor;
  410. errorControlTimer = new Timer();
  411. errorControlTimer.Interval = 300;
  412. errorControlTimer.Tick += new EventHandler(FErrorControlTimer_Tick);
  413. errorControlTimer.Start();
  414. }
  415. }
  416. }
  417. private void FErrorControlTimer_Tick(object sender, EventArgs e)
  418. {
  419. errorControl.BackColor = errorControlTimerTickCount % 2 == 0 ? Color.Red : errorControlBackColor;
  420. errorControlTimerTickCount++;
  421. if (errorControlTimerTickCount > 5)
  422. {
  423. errorControlTimer.Stop();
  424. errorControlTimer.Dispose();
  425. errorControlTimer = null;
  426. }
  427. }
  428. #endregion
  429. #region Protected Methods
  430. /// <inheritdoc/>
  431. protected override void Dispose(bool disposing)
  432. {
  433. base.Dispose(disposing);
  434. if (disposing)
  435. Form.Dispose();
  436. }
  437. #endregion
  438. #region IParent
  439. /// <inheritdoc/>
  440. public virtual void GetChildObjects(ObjectCollection list)
  441. {
  442. foreach (DialogComponentBase c in controls)
  443. {
  444. list.Add(c);
  445. }
  446. }
  447. /// <inheritdoc/>
  448. public virtual bool CanContain(Base child)
  449. {
  450. return (child is DialogComponentBase);
  451. }
  452. /// <inheritdoc/>
  453. public virtual void AddChild(Base child)
  454. {
  455. if (child is DialogComponentBase)
  456. controls.Add(child as DialogComponentBase);
  457. }
  458. /// <inheritdoc/>
  459. public virtual void RemoveChild(Base child)
  460. {
  461. if (child is DialogComponentBase)
  462. controls.Remove(child as DialogComponentBase);
  463. }
  464. /// <inheritdoc/>
  465. public virtual int GetChildOrder(Base child)
  466. {
  467. return controls.IndexOf(child as DialogComponentBase);
  468. }
  469. /// <inheritdoc/>
  470. public virtual void SetChildOrder(Base child, int order)
  471. {
  472. int oldOrder = child.ZOrder;
  473. if (oldOrder != -1 && order != -1 && oldOrder != order)
  474. {
  475. if (order > controls.Count)
  476. order = controls.Count;
  477. if (oldOrder <= order)
  478. order--;
  479. controls.Remove(child as DialogComponentBase);
  480. controls.Insert(order, child as DialogComponentBase);
  481. }
  482. }
  483. /// <inheritdoc/>
  484. public virtual void UpdateLayout(float dx, float dy)
  485. {
  486. // do nothing
  487. }
  488. #endregion
  489. #region Public Methods
  490. /// <inheritdoc/>
  491. public override void Assign(Base source)
  492. {
  493. BaseAssign(source);
  494. DialogPage src = source as DialogPage;
  495. AcceptButton = src.AcceptButton;
  496. CancelButton = src.CancelButton;
  497. #if !FRCORE
  498. int dpi = src.Form.Dpi();
  499. float fontDpiMultiplier = src.Form.FontDpiMultiplier();
  500. #else
  501. int dpi = 96;
  502. float fontDpiMultiplier = 1;
  503. #endif
  504. AutoScaleDimensions = new SizeF(dpi, dpi);
  505. BackColor = src.BackColor;
  506. Font = new Font(Font.FontFamily, Font.Size / fontDpiMultiplier, Font.Style);
  507. FormBorderStyle = src.FormBorderStyle;
  508. RightToLeft = src.RightToLeft;
  509. Text = src.Text;
  510. ClientSize = src.ClientSize;
  511. }
  512. /// <inheritdoc/>
  513. public override void Serialize(FRWriter writer)
  514. {
  515. DialogPage c = writer.DiffObject as DialogPage;
  516. base.Serialize(writer);
  517. if (AcceptButton != c.AcceptButton)
  518. writer.WriteRef("AcceptButton", AcceptButton);
  519. if (CancelButton != c.CancelButton)
  520. writer.WriteRef("CancelButton", CancelButton);
  521. #if !FRCORE
  522. int dpi = Form.Dpi();
  523. #else
  524. int dpi = 96;
  525. #endif
  526. writer.WriteValue("AutoScaleDimensions", new SizeF(dpi, dpi));
  527. if (BackColor != c.BackColor)
  528. writer.WriteValue("BackColor", BackColor);
  529. if (!Font.Equals(c.Font) && writer.ItemName != "inherited")
  530. {
  531. #if !FRCORE
  532. float fontDpiMultiplier = Form.FontDpiMultiplier();
  533. #else
  534. float fontDpiMultiplier = 1;
  535. #endif
  536. using (Font f = new Font(Font.FontFamily, Font.Size / fontDpiMultiplier, Font.Style))
  537. writer.WriteValue("Font", f);
  538. }
  539. if (FormBorderStyle != c.FormBorderStyle)
  540. writer.WriteValue("FormBorderStyle", FormBorderStyle);
  541. if (RightToLeft != c.RightToLeft)
  542. writer.WriteValue("RightToLeft", RightToLeft);
  543. if (Text != c.Text)
  544. writer.WriteStr("Text", Text);
  545. if (LoadEvent != c.LoadEvent)
  546. writer.WriteStr("LoadEvent", LoadEvent);
  547. if (FormClosedEvent != c.FormClosedEvent)
  548. writer.WriteStr("FormClosedEvent", FormClosedEvent);
  549. if (FormClosingEvent != c.FormClosingEvent)
  550. writer.WriteStr("FormClosingEvent", FormClosingEvent);
  551. if (ShownEvent != c.ShownEvent)
  552. writer.WriteStr("ShownEvent", ShownEvent);
  553. if (ResizeEvent != c.ResizeEvent)
  554. writer.WriteStr("ResizeEvent", ResizeEvent);
  555. if (PaintEvent != c.PaintEvent)
  556. writer.WriteStr("PaintEvent", PaintEvent);
  557. writer.WriteValue("ClientSize", ClientSize);
  558. }
  559. /// <inheritdoc/>
  560. public override void Deserialize(FRReader reader)
  561. {
  562. Form.SuspendLayout();
  563. // in case the dimensions are not stored in the report file (old file format), use 96dpi by default
  564. if (!reader.HasProperty("AutoScaleDimensions"))
  565. Form.AutoScaleDimensions = new SizeF(96f, 96f);
  566. Form.AutoScaleMode = AutoScaleMode.Dpi;
  567. base.Deserialize(reader);
  568. // old file format - width and height were stored instead of ClientSize
  569. if (reader.HasProperty("Width"))
  570. {
  571. // old-style FixedDialog form size was a bit smaller
  572. if (FormBorderStyle == FormBorderStyle.FixedDialog)
  573. {
  574. Form.Width += 10;
  575. Form.Height += 10;
  576. }
  577. #if FRCORE
  578. // TODO: remove after fix in FR.Compat
  579. if (Form.Size.IsEmpty) // fix for Core
  580. {
  581. Form.Size = new Size(Form.Width, Form.Height);
  582. }
  583. #endif
  584. // compensate difference in caption/border size. Don't ask how but it's working
  585. Form.ClientSize = Form.Size;
  586. Form.Width -= (int)((Form.Width - Form.ClientSize.Width) * DrawUtils.ScreenDpiFX);
  587. Form.Height -= (int)((Form.Height - Form.ClientSize.Height) * DrawUtils.ScreenDpiFX);
  588. }
  589. #if !FRCORE
  590. FixControlFonts(Form);
  591. Form.ResumeLayout(false);
  592. #else
  593. Form.ResumeLayout();
  594. #endif
  595. }
  596. internal void InitializeControls()
  597. {
  598. Form.Hide();
  599. Form.StartPosition = FormStartPosition.CenterScreen;
  600. Form.Load += Form_Load;
  601. Form.FormClosed += Form_FormClosed;
  602. Form.FormClosing += Form_FormClosing;
  603. Form.Shown += Form_Shown;
  604. Form.Resize += Form_Resize;
  605. Form.Paint += Form_Paint;
  606. ObjectCollection allObjects = AllObjects;
  607. foreach (Base c in allObjects)
  608. {
  609. if (c is DialogControl)
  610. {
  611. (c as DialogControl).InitializeControl();
  612. }
  613. }
  614. }
  615. internal void FinalizeControls()
  616. {
  617. Form.Load -= Form_Load;
  618. Form.FormClosed -= Form_FormClosed;
  619. Form.FormClosing -= Form_FormClosing;
  620. Form.Shown -= Form_Shown;
  621. Form.Resize -= Form_Resize;
  622. Form.Paint -= Form_Paint;
  623. ObjectCollection allObjects = AllObjects;
  624. foreach (Base c in allObjects)
  625. {
  626. if (c is DialogControl)
  627. (c as DialogControl).FinalizeControl();
  628. }
  629. }
  630. /// <summary>
  631. /// Shows the form as a modal dialog box with the currently active window set as its owner.
  632. /// Wraps the <see cref="System.Windows.Forms.Form.ShowDialog()"/> method.
  633. /// </summary>
  634. /// <returns>One of the <b>DialogResult</b> values.</returns>
  635. public DialogResult ShowDialog()
  636. {
  637. try
  638. {
  639. InitializeControls();
  640. return Form.ShowDialog();
  641. }
  642. finally
  643. {
  644. FinalizeControls();
  645. }
  646. }
  647. /// <summary>
  648. /// Shows the form as a modal dialog box with the currently active window set as its owner.
  649. /// Wraps the <see cref="System.Windows.Forms.Form.ShowDialog()"/> method. Uses async call to ShowDialog if possible.
  650. /// </summary>
  651. /// <returns>One of the <b>DialogResult</b> values.</returns>
  652. public async Task<DialogResult> ShowDialogAsync()
  653. {
  654. try
  655. {
  656. InitializeControls();
  657. #if AVALONIA
  658. return await Form.ShowDialogAsync();
  659. #else
  660. return Form.ShowDialog();
  661. #endif
  662. }
  663. finally
  664. {
  665. FinalizeControls();
  666. }
  667. }
  668. /// <summary>
  669. /// This method fires the <b>Load</b> event and the script code connected to the <b>LoadEvent</b>.
  670. /// </summary>
  671. /// <param name="e">Event data.</param>
  672. public void OnLoad(EventArgs e)
  673. {
  674. if (Load != null)
  675. Load(this, e);
  676. InvokeEvent(LoadEvent, e);
  677. }
  678. /// <summary>
  679. /// This method fires the <b>FormClosed</b> event and the script code connected to the <b>FormClosedEvent</b>.
  680. /// </summary>
  681. /// <param name="e">Event data.</param>
  682. public void OnFormClosed(FormClosedEventArgs e)
  683. {
  684. if (FormClosed != null)
  685. FormClosed(this, e);
  686. InvokeEvent(FormClosedEvent, e);
  687. }
  688. /// <summary>
  689. /// This method fires the <b>FormClosing</b> event and the script code connected to the <b>FormClosingEvent</b>.
  690. /// </summary>
  691. /// <param name="e">Event data.</param>
  692. public void OnFormClosing(FormClosingEventArgs e)
  693. {
  694. if (form.DialogResult == DialogResult.OK)
  695. {
  696. // filter data
  697. SetErrorControl(null);
  698. foreach (Base c in AllObjects)
  699. {
  700. DataFilterBaseControl c1 = c as DataFilterBaseControl;
  701. if (c1 != null && c1.Enabled)
  702. {
  703. try
  704. {
  705. if (c1.AutoFilter)
  706. c1.FilterData();
  707. c1.SetReportParameter();
  708. }
  709. catch
  710. {
  711. SetErrorControl(c1);
  712. }
  713. }
  714. if (errorControl != null)
  715. {
  716. e.Cancel = true;
  717. break;
  718. }
  719. }
  720. }
  721. if (FormClosing != null)
  722. FormClosing(this, e);
  723. InvokeEvent(FormClosingEvent, e);
  724. }
  725. /// <summary>
  726. /// This method fires the <b>Shown</b> event and the script code connected to the <b>ShownEvent</b>.
  727. /// </summary>
  728. /// <param name="e">Event data.</param>
  729. public void OnShown(EventArgs e)
  730. {
  731. if (Shown != null)
  732. Shown(this, e);
  733. InvokeEvent(ShownEvent, e);
  734. }
  735. /// <summary>
  736. /// This method fires the <b>Resize</b> event and the script code connected to the <b>ResizeEvent</b>.
  737. /// </summary>
  738. /// <param name="e">Event data.</param>
  739. public void OnResize(EventArgs e)
  740. {
  741. if (Resize != null)
  742. Resize(this, e);
  743. InvokeEvent(ResizeEvent, e);
  744. }
  745. /// <summary>
  746. /// This method fires the <b>Paint</b> event and the script code connected to the <b>PaintEvent</b>.
  747. /// </summary>
  748. /// <param name="e">Event data.</param>
  749. public void OnPaint(PaintEventArgs e)
  750. {
  751. if (Paint != null)
  752. Paint(this, e);
  753. InvokeEvent(PaintEvent, e);
  754. }
  755. #endregion
  756. /// <summary>
  757. /// Initializes a new instance of the <b>DialogPage</b> class.
  758. /// </summary>
  759. public DialogPage()
  760. {
  761. controls = new DialogComponentCollection(this);
  762. #if !FRCORE
  763. form = new BaseForm();
  764. #else
  765. form = new Form();
  766. #endif
  767. form.ShowIcon = false;
  768. form.ShowInTaskbar = false;
  769. form.FormBorderStyle = FormBorderStyle.FixedDialog;
  770. form.MinimizeBox = false;
  771. form.MaximizeBox = false;
  772. form.Font = DrawUtils.DefaultFont;
  773. #if !FRCORE
  774. form.DpiChanged += Form_DpiChanged;
  775. #endif
  776. oldDpi = DrawUtils.ScreenDpi;
  777. activeInWeb = false;
  778. BaseName = "Form";
  779. SetFlags(Flags.CanWriteBounds, false);
  780. }
  781. }
  782. }