DialogPage.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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. #if !FRCORE
  8. using FastReport.Forms;
  9. #endif
  10. namespace FastReport.Dialog
  11. {
  12. /// <summary>
  13. /// Represents the special kind of report page that wraps the <see cref="System.Windows.Forms.Form"/>
  14. /// and used to display dialog forms.
  15. /// </summary>
  16. /// <remarks>
  17. /// Use the <see cref="Controls"/> property to add/remove controls to/from a dialog form.
  18. /// <para/>If you set the <b>Visible</b> property to <b>false</b>, this dialog form will be
  19. /// skippen when you run a report.
  20. /// </remarks>
  21. /// <example>This example shows how to create a dialog form with one button in code.
  22. /// <code>
  23. /// DialogPage form = new DialogPage();
  24. /// // set the width and height in pixels
  25. /// form.Width = 200;
  26. /// form.Height = 200;
  27. /// form.Name = "Form1";
  28. /// // create a button
  29. /// ButtonControl button = new ButtonControl();
  30. /// button.Location = new Point(20, 20);
  31. /// button.Size = new Size(75, 25);
  32. /// button.Text = "The button";
  33. /// // add the button to the form
  34. /// form.Controls.Add(button);
  35. /// </code>
  36. /// </example>
  37. public partial class DialogPage : PageBase, IParent
  38. {
  39. #region Fields
  40. private ButtonControl acceptButton;
  41. private ButtonControl cancelButton;
  42. #if !FRCORE
  43. private BaseForm form;
  44. #else
  45. private Form form;
  46. #endif
  47. private DialogComponentCollection controls;
  48. private string loadEvent;
  49. private string formClosedEvent;
  50. private string formClosingEvent;
  51. private string shownEvent;
  52. private string resizeEvent;
  53. private string paintEvent;
  54. private DialogControl errorControl;
  55. private Color errorControlBackColor;
  56. private Timer errorControlTimer;
  57. private int errorControlTimerTickCount;
  58. private bool activeInWeb;
  59. private SizeF autoScaleDimensions;
  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 { 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 = (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 = (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. float m = Form.Dpi() / (float)oldDpi;
  382. foreach (Control c in parent.Controls)
  383. {
  384. if (!c.Font.Equals(c.Parent.Font))
  385. {
  386. c.Font = new Font(c.Font.FontFamily, c.Font.Size * m, c.Font.Style);
  387. }
  388. FixControlFonts(c);
  389. }
  390. }
  391. private void Form_DpiChanged(object sender, EventArgs e)
  392. {
  393. // take care of controls with non-standard fonts. Such fonts are not scaled automatically.
  394. FixControlFonts(Form);
  395. oldDpi = Form.Dpi();
  396. }
  397. #endif
  398. private void SetErrorControl(DialogControl control)
  399. {
  400. errorControl = control;
  401. if (control != null)
  402. {
  403. control.Focus();
  404. if (errorControlTimer == null)
  405. {
  406. errorControlTimerTickCount = 0;
  407. errorControlBackColor = errorControl.BackColor;
  408. errorControlTimer = new Timer();
  409. errorControlTimer.Interval = 300;
  410. errorControlTimer.Tick += new EventHandler(FErrorControlTimer_Tick);
  411. errorControlTimer.Start();
  412. }
  413. }
  414. }
  415. private void FErrorControlTimer_Tick(object sender, EventArgs e)
  416. {
  417. errorControl.BackColor = errorControlTimerTickCount % 2 == 0 ? Color.Red : errorControlBackColor;
  418. errorControlTimerTickCount++;
  419. if (errorControlTimerTickCount > 5)
  420. {
  421. errorControlTimer.Stop();
  422. errorControlTimer.Dispose();
  423. errorControlTimer = null;
  424. }
  425. }
  426. #endregion
  427. #region Protected Methods
  428. /// <inheritdoc/>
  429. protected override void Dispose(bool disposing)
  430. {
  431. base.Dispose(disposing);
  432. if (disposing)
  433. Form.Dispose();
  434. }
  435. #endregion
  436. #region IParent
  437. /// <inheritdoc/>
  438. public virtual void GetChildObjects(ObjectCollection list)
  439. {
  440. foreach (DialogComponentBase c in controls)
  441. {
  442. list.Add(c);
  443. }
  444. }
  445. /// <inheritdoc/>
  446. public virtual bool CanContain(Base child)
  447. {
  448. return (child is DialogComponentBase);
  449. }
  450. /// <inheritdoc/>
  451. public virtual void AddChild(Base child)
  452. {
  453. if (child is DialogComponentBase)
  454. controls.Add(child as DialogComponentBase);
  455. }
  456. /// <inheritdoc/>
  457. public virtual void RemoveChild(Base child)
  458. {
  459. if (child is DialogComponentBase)
  460. controls.Remove(child as DialogComponentBase);
  461. }
  462. /// <inheritdoc/>
  463. public virtual int GetChildOrder(Base child)
  464. {
  465. return controls.IndexOf(child as DialogComponentBase);
  466. }
  467. /// <inheritdoc/>
  468. public virtual void SetChildOrder(Base child, int order)
  469. {
  470. int oldOrder = child.ZOrder;
  471. if (oldOrder != -1 && order != -1 && oldOrder != order)
  472. {
  473. if (order > controls.Count)
  474. order = controls.Count;
  475. if (oldOrder <= order)
  476. order--;
  477. controls.Remove(child as DialogComponentBase);
  478. controls.Insert(order, child as DialogComponentBase);
  479. }
  480. }
  481. /// <inheritdoc/>
  482. public virtual void UpdateLayout(float dx, float dy)
  483. {
  484. // do nothing
  485. }
  486. #endregion
  487. #region Public Methods
  488. /// <inheritdoc/>
  489. public override void Assign(Base source)
  490. {
  491. BaseAssign(source);
  492. DialogPage src = source as DialogPage;
  493. AcceptButton = src.AcceptButton;
  494. CancelButton = src.CancelButton;
  495. #if !FRCORE
  496. int dpi = src.Form.Dpi();
  497. float fontDpiMultiplier = src.Form.FontDpiMultiplier();
  498. #else
  499. int dpi = 96;
  500. float fontDpiMultiplier = 1;
  501. #endif
  502. AutoScaleDimensions = new SizeF(dpi, dpi);
  503. BackColor = src.BackColor;
  504. Font = new Font(Font.FontFamily, Font.Size / fontDpiMultiplier, Font.Style);
  505. FormBorderStyle = src.FormBorderStyle;
  506. RightToLeft = src.RightToLeft;
  507. Text = src.Text;
  508. ClientSize = src.ClientSize;
  509. }
  510. /// <inheritdoc/>
  511. public override void Serialize(FRWriter writer)
  512. {
  513. DialogPage c = writer.DiffObject as DialogPage;
  514. base.Serialize(writer);
  515. if (AcceptButton != c.AcceptButton)
  516. writer.WriteRef("AcceptButton", AcceptButton);
  517. if (CancelButton != c.CancelButton)
  518. writer.WriteRef("CancelButton", CancelButton);
  519. #if !FRCORE
  520. int dpi = Form.Dpi();
  521. #else
  522. int dpi = 96;
  523. #endif
  524. writer.WriteValue("AutoScaleDimensions", new SizeF(dpi, dpi));
  525. if (BackColor != c.BackColor)
  526. writer.WriteValue("BackColor", BackColor);
  527. if (!Font.Equals(c.Font) && writer.ItemName != "inherited")
  528. {
  529. #if !FRCORE
  530. float fontDpiMultiplier = Form.FontDpiMultiplier();
  531. #else
  532. float fontDpiMultiplier = 1;
  533. #endif
  534. using (Font f = new Font(Font.FontFamily, Font.Size / fontDpiMultiplier, Font.Style))
  535. writer.WriteValue("Font", f);
  536. }
  537. if (FormBorderStyle != c.FormBorderStyle)
  538. writer.WriteValue("FormBorderStyle", FormBorderStyle);
  539. if (RightToLeft != c.RightToLeft)
  540. writer.WriteValue("RightToLeft", RightToLeft);
  541. if (Text != c.Text)
  542. writer.WriteStr("Text", Text);
  543. if (LoadEvent != c.LoadEvent)
  544. writer.WriteStr("LoadEvent", LoadEvent);
  545. if (FormClosedEvent != c.FormClosedEvent)
  546. writer.WriteStr("FormClosedEvent", FormClosedEvent);
  547. if (FormClosingEvent != c.FormClosingEvent)
  548. writer.WriteStr("FormClosingEvent", FormClosingEvent);
  549. if (ShownEvent != c.ShownEvent)
  550. writer.WriteStr("ShownEvent", ShownEvent);
  551. if (ResizeEvent != c.ResizeEvent)
  552. writer.WriteStr("ResizeEvent", ResizeEvent);
  553. if (PaintEvent != c.PaintEvent)
  554. writer.WriteStr("PaintEvent", PaintEvent);
  555. writer.WriteValue("ClientSize", ClientSize);
  556. }
  557. /// <inheritdoc/>
  558. public override void Deserialize(FRReader reader)
  559. {
  560. // in case the dimensions are not stored in the report file (old file format), use 96dpi by default
  561. autoScaleDimensions = new SizeF(96f, 96f);
  562. Form.SuspendLayout();
  563. base.Deserialize(reader);
  564. // old file format - width and height were stored instead of ClientSize
  565. if (reader.HasProperty("Width") && DrawUtils.ScreenDpi > 96)
  566. {
  567. // this will fix the form size on high dpi display
  568. Form.Size = new Size(Form.Width + (int)((Form.Width - Form.ClientSize.Width) * DrawUtils.ScreenDpiFX),
  569. Form.Height + (int)((Form.Height - Form.ClientSize.Height) * DrawUtils.ScreenDpiFX));
  570. }
  571. Form.AutoScaleDimensions = autoScaleDimensions;
  572. Form.AutoScaleMode = AutoScaleMode.Dpi;
  573. #if !FRCORE
  574. FixControlFonts(Form);
  575. #endif
  576. Form.ResumeLayout();
  577. }
  578. internal void InitializeControls()
  579. {
  580. Form.Hide();
  581. Form.StartPosition = FormStartPosition.CenterScreen;
  582. Form.Load += Form_Load;
  583. Form.FormClosed += Form_FormClosed;
  584. Form.FormClosing += Form_FormClosing;
  585. Form.Shown += Form_Shown;
  586. Form.Resize += Form_Resize;
  587. Form.Paint += Form_Paint;
  588. ObjectCollection allObjects = AllObjects;
  589. foreach (Base c in allObjects)
  590. {
  591. if (c is DialogControl)
  592. {
  593. (c as DialogControl).InitializeControl();
  594. }
  595. }
  596. }
  597. internal void FinalizeControls()
  598. {
  599. Form.Load -= Form_Load;
  600. Form.FormClosed -= Form_FormClosed;
  601. Form.FormClosing -= Form_FormClosing;
  602. Form.Shown -= Form_Shown;
  603. Form.Resize -= Form_Resize;
  604. Form.Paint -= Form_Paint;
  605. ObjectCollection allObjects = AllObjects;
  606. foreach (Base c in allObjects)
  607. {
  608. if (c is DialogControl)
  609. (c as DialogControl).FinalizeControl();
  610. }
  611. }
  612. /// <summary>
  613. /// Shows the form as a modal dialog box with the currently active window set as its owner.
  614. /// Wraps the <see cref="System.Windows.Forms.Form.ShowDialog()"/> method.
  615. /// </summary>
  616. /// <returns>One of the <b>DialogResult</b> values.</returns>
  617. public DialogResult ShowDialog()
  618. {
  619. try
  620. {
  621. InitializeControls();
  622. return Form.ShowDialog();
  623. }
  624. finally
  625. {
  626. FinalizeControls();
  627. }
  628. }
  629. /// <summary>
  630. /// This method fires the <b>Load</b> event and the script code connected to the <b>LoadEvent</b>.
  631. /// </summary>
  632. /// <param name="e">Event data.</param>
  633. public void OnLoad(EventArgs e)
  634. {
  635. if (Load != null)
  636. Load(this, e);
  637. InvokeEvent(LoadEvent, e);
  638. }
  639. /// <summary>
  640. /// This method fires the <b>FormClosed</b> event and the script code connected to the <b>FormClosedEvent</b>.
  641. /// </summary>
  642. /// <param name="e">Event data.</param>
  643. public void OnFormClosed(FormClosedEventArgs e)
  644. {
  645. if (FormClosed != null)
  646. FormClosed(this, e);
  647. InvokeEvent(FormClosedEvent, e);
  648. }
  649. /// <summary>
  650. /// This method fires the <b>FormClosing</b> event and the script code connected to the <b>FormClosingEvent</b>.
  651. /// </summary>
  652. /// <param name="e">Event data.</param>
  653. public void OnFormClosing(FormClosingEventArgs e)
  654. {
  655. if (form.DialogResult == DialogResult.OK)
  656. {
  657. // filter data
  658. SetErrorControl(null);
  659. foreach (Base c in AllObjects)
  660. {
  661. DataFilterBaseControl c1 = c as DataFilterBaseControl;
  662. if (c1 != null && c1.Enabled)
  663. {
  664. try
  665. {
  666. if (c1.AutoFilter)
  667. c1.FilterData();
  668. c1.SetReportParameter();
  669. }
  670. catch
  671. {
  672. SetErrorControl(c1);
  673. }
  674. }
  675. if (errorControl != null)
  676. {
  677. e.Cancel = true;
  678. break;
  679. }
  680. }
  681. }
  682. if (FormClosing != null)
  683. FormClosing(this, e);
  684. InvokeEvent(FormClosingEvent, e);
  685. }
  686. /// <summary>
  687. /// This method fires the <b>Shown</b> event and the script code connected to the <b>ShownEvent</b>.
  688. /// </summary>
  689. /// <param name="e">Event data.</param>
  690. public void OnShown(EventArgs e)
  691. {
  692. if (Shown != null)
  693. Shown(this, e);
  694. InvokeEvent(ShownEvent, e);
  695. }
  696. /// <summary>
  697. /// This method fires the <b>Resize</b> event and the script code connected to the <b>ResizeEvent</b>.
  698. /// </summary>
  699. /// <param name="e">Event data.</param>
  700. public void OnResize(EventArgs e)
  701. {
  702. if (Resize != null)
  703. Resize(this, e);
  704. InvokeEvent(ResizeEvent, e);
  705. }
  706. /// <summary>
  707. /// This method fires the <b>Paint</b> event and the script code connected to the <b>PaintEvent</b>.
  708. /// </summary>
  709. /// <param name="e">Event data.</param>
  710. public void OnPaint(PaintEventArgs e)
  711. {
  712. if (Paint != null)
  713. Paint(this, e);
  714. InvokeEvent(PaintEvent, e);
  715. }
  716. #endregion
  717. /// <summary>
  718. /// Initializes a new instance of the <b>DialogPage</b> class.
  719. /// </summary>
  720. public DialogPage()
  721. {
  722. controls = new DialogComponentCollection(this);
  723. #if !FRCORE
  724. form = new BaseForm();
  725. #else
  726. form = new Form();
  727. #endif
  728. form.ShowIcon = false;
  729. form.ShowInTaskbar = false;
  730. form.FormBorderStyle = FormBorderStyle.FixedDialog;
  731. form.MinimizeBox = false;
  732. form.MaximizeBox = false;
  733. form.Font = DrawUtils.DefaultFont;
  734. #if !FRCORE
  735. form.DpiChanged += Form_DpiChanged;
  736. #endif
  737. oldDpi = DrawUtils.ScreenDpi;
  738. activeInWeb = false;
  739. BaseName = "Form";
  740. SetFlags(Flags.CanWriteBounds, false);
  741. }
  742. }
  743. }