DialogControl.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. using System;
  2. using System.Drawing;
  3. using System.ComponentModel;
  4. using System.Reflection;
  5. using FastReport.Utils;
  6. using System.Windows.Forms;
  7. using System.Drawing.Design;
  8. namespace FastReport.Dialog
  9. {
  10. /// <summary>
  11. /// Base class for all dialog controls such as <b>ButtonControl</b>, <b>TextBoxControl</b>.
  12. /// </summary>
  13. public abstract partial class DialogControl : DialogComponentBase
  14. {
  15. #region Fields
  16. private Control control;
  17. private string clickEvent;
  18. private string doubleClickEvent;
  19. private string enterEvent;
  20. private string leaveEvent;
  21. private string keyDownEvent;
  22. private string keyPressEvent;
  23. private string keyUpEvent;
  24. private string mouseDownEvent;
  25. private string mouseMoveEvent;
  26. private string mouseUpEvent;
  27. private string mouseEnterEvent;
  28. private string mouseLeaveEvent;
  29. private string resizeEvent;
  30. private string textChangedEvent;
  31. private string paintEvent;
  32. private PropertyInfo bindableProperty;
  33. #endregion
  34. #region Properties
  35. /// <summary>
  36. /// Occurs when the control is clicked.
  37. /// Wraps the <see cref="System.Windows.Forms.Control.Click"/> event.
  38. /// </summary>
  39. public event EventHandler Click;
  40. /// <summary>
  41. /// Occurs when the control is double-clicked.
  42. /// Wraps the <see cref="System.Windows.Forms.Control.DoubleClick"/> event.
  43. /// </summary>
  44. public event EventHandler DoubleClick;
  45. /// <summary>
  46. /// Occurs when the control is entered.
  47. /// Wraps the <see cref="System.Windows.Forms.Control.Enter"/> event.
  48. /// </summary>
  49. public event EventHandler Enter;
  50. /// <summary>
  51. /// Occurs when the input focus leaves the control.
  52. /// Wraps the <see cref="System.Windows.Forms.Control.Leave"/> event.
  53. /// </summary>
  54. public event EventHandler Leave;
  55. /// <summary>
  56. /// Occurs when a key is pressed while the control has focus.
  57. /// Wraps the <see cref="System.Windows.Forms.Control.KeyDown"/> event.
  58. /// </summary>
  59. public event KeyEventHandler KeyDown;
  60. /// <summary>
  61. /// Occurs when a key is pressed while the control has focus.
  62. /// Wraps the <see cref="System.Windows.Forms.Control.KeyPress"/> event.
  63. /// </summary>
  64. public event KeyPressEventHandler KeyPress;
  65. /// <summary>
  66. /// Occurs when a key is released while the control has focus.
  67. /// Wraps the <see cref="System.Windows.Forms.Control.KeyUp"/> event.
  68. /// </summary>
  69. public event KeyEventHandler KeyUp;
  70. /// <summary>
  71. /// Occurs when the mouse pointer is over the control and a mouse button is pressed.
  72. /// Wraps the <see cref="System.Windows.Forms.Control.MouseDown"/> event.
  73. /// </summary>
  74. public event MouseEventHandler MouseDown;
  75. /// <summary>
  76. /// Occurs when the mouse pointer is moved over the control.
  77. /// Wraps the <see cref="System.Windows.Forms.Control.MouseMove"/> event.
  78. /// </summary>
  79. public event MouseEventHandler MouseMove;
  80. /// <summary>
  81. /// Occurs when the mouse pointer is over the control and a mouse button is released.
  82. /// Wraps the <see cref="System.Windows.Forms.Control.MouseUp"/> event.
  83. /// </summary>
  84. public event MouseEventHandler MouseUp;
  85. /// <summary>
  86. /// Occurs when the mouse pointer enters the control.
  87. /// Wraps the <see cref="System.Windows.Forms.Control.MouseEnter"/> event.
  88. /// </summary>
  89. public event EventHandler MouseEnter;
  90. /// <summary>
  91. /// Occurs when the mouse pointer leaves the control.
  92. /// Wraps the <see cref="System.Windows.Forms.Control.MouseLeave"/> event.
  93. /// </summary>
  94. public event EventHandler MouseLeave;
  95. /// <summary>
  96. /// Occurs when the control is resized.
  97. /// Wraps the <see cref="System.Windows.Forms.Control.Resize"/> event.
  98. /// </summary>
  99. public event EventHandler Resize;
  100. /// <summary>
  101. /// Occurs when the Text property value changes.
  102. /// Wraps the <see cref="System.Windows.Forms.Control.TextChanged"/> event.
  103. /// </summary>
  104. public event EventHandler TextChanged;
  105. /// <summary>
  106. /// Occurs when the control is redrawn.
  107. /// Wraps the <see cref="System.Windows.Forms.Control.Paint"/> event.
  108. /// </summary>
  109. public event PaintEventHandler Paint;
  110. /// <summary>
  111. /// Gets an internal <b>Control</b>.
  112. /// </summary>
  113. [Browsable(false)]
  114. public Control Control
  115. {
  116. get { return control; }
  117. set { control = value; }
  118. }
  119. /// <summary>
  120. /// Gets or sets the background color for the control.
  121. /// Wraps the <see cref="System.Windows.Forms.Control.BackColor"/> property.
  122. /// </summary>
  123. [Category("Appearance")]
  124. [Editor("FastReport.TypeEditors.ColorEditor, FastReport", typeof(UITypeEditor))]
  125. public virtual Color BackColor
  126. {
  127. get { return Control.BackColor; }
  128. set { Control.BackColor = value; }
  129. }
  130. /// <summary>
  131. /// Gets or sets the cursor that is displayed when the mouse pointer is over the control.
  132. /// Wraps the <see cref="System.Windows.Forms.Control.Cursor"/> property.
  133. /// </summary>
  134. [Category("Appearance")]
  135. public Cursor Cursor
  136. {
  137. get { return Control.Cursor; }
  138. set { Control.Cursor = value; }
  139. }
  140. /// <summary>
  141. /// Gets or sets a value indicating whether the control can respond to user interaction.
  142. /// Wraps the <see cref="System.Windows.Forms.Control.Enabled"/> property.
  143. /// </summary>
  144. [DefaultValue(true)]
  145. [Category("Behavior")]
  146. public bool Enabled
  147. {
  148. get { return Control.Enabled; }
  149. set
  150. {
  151. Control.Enabled = value;
  152. OnEnabledChanged();
  153. }
  154. }
  155. /// <summary>
  156. /// Gets or sets the font of the text displayed by the control.
  157. /// Wraps the <see cref="System.Windows.Forms.Control.Font"/> property.
  158. /// </summary>
  159. [Category("Appearance")]
  160. public Font Font
  161. {
  162. get { return Control.Font; }
  163. set { Control.Font = value; }
  164. }
  165. /// <summary>
  166. /// Gets or sets the foreground color of the control.
  167. /// Wraps the <see cref="System.Windows.Forms.Control.ForeColor"/> property.
  168. /// </summary>
  169. [Category("Appearance")]
  170. [Editor("FastReport.TypeEditors.ColorEditor, FastReport", typeof(UITypeEditor))]
  171. public virtual Color ForeColor
  172. {
  173. get { return Control.ForeColor; }
  174. set { Control.ForeColor = value; }
  175. }
  176. /// <summary>
  177. /// Gets or sets a value indicating whether control's elements are aligned to support locales using right-to-left fonts.
  178. /// Wraps the <see cref="System.Windows.Forms.Control.RightToLeft"/> property.
  179. /// </summary>
  180. [DefaultValue(RightToLeft.No)]
  181. [Category("Appearance")]
  182. public RightToLeft RightToLeft
  183. {
  184. get { return Control.RightToLeft; }
  185. set { Control.RightToLeft = value; }
  186. }
  187. /// <summary>
  188. /// Gets or sets the tab order of the control within its container.
  189. /// Wraps the <see cref="System.Windows.Forms.Control.TabIndex"/> property.
  190. /// </summary>
  191. [DefaultValue(0)]
  192. [Category("Behavior")]
  193. public int TabIndex
  194. {
  195. get { return Control.TabIndex; }
  196. set { Control.TabIndex = value; }
  197. }
  198. /// <summary>
  199. /// Gets or sets a value indicating whether the user can give the focus to this control using the TAB key.
  200. /// Wraps the <see cref="System.Windows.Forms.Control.TabStop"/> property.
  201. /// </summary>
  202. [DefaultValue(true)]
  203. [Category("Behavior")]
  204. public bool TabStop
  205. {
  206. get { return Control.TabStop; }
  207. set { Control.TabStop = value; }
  208. }
  209. /// <summary>
  210. /// Gets or sets the text associated with this control.
  211. /// Wraps the <see cref="System.Windows.Forms.Control.Text"/> property.
  212. /// </summary>
  213. [Category("Data")]
  214. [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
  215. public virtual string Text
  216. {
  217. get { return Control.Text; }
  218. set { Control.Text = value; }
  219. }
  220. /// <summary>
  221. /// Gets or sets which control borders are docked to its parent control and determines how a control is resized with its parent.
  222. /// Wraps the <see cref="System.Windows.Forms.Control.Dock"/> property.
  223. /// </summary>
  224. [Category("Layout")]
  225. public override DockStyle Dock
  226. {
  227. get { return Control.Dock; }
  228. set { Control.Dock = value; }
  229. }
  230. /// <summary>
  231. /// Gets or sets the edges of the container to which a control is bound and determines how a control is resized with its parent.
  232. /// Wraps the <see cref="System.Windows.Forms.Control.Anchor"/> property.
  233. /// </summary>
  234. [Category("Layout")]
  235. public override AnchorStyles Anchor
  236. {
  237. get { return Control.Anchor; }
  238. set { Control.Anchor = value; }
  239. }
  240. /// <summary>
  241. /// Gets or sets a value indicating whether the control is displayed.
  242. /// Wraps the <see cref="System.Windows.Forms.Control.Visible"/> property.
  243. /// </summary>
  244. [Category("Behavior")]
  245. public override bool Visible
  246. {
  247. get { return base.Visible; }
  248. set
  249. {
  250. base.Visible = value;
  251. Control.Visible = value;
  252. }
  253. }
  254. /// <summary>
  255. /// Gets or sets a property that returns actual data contained in a control. This value is used
  256. /// in the "Data" window.
  257. /// </summary>
  258. [Browsable(false)]
  259. public PropertyInfo BindableProperty
  260. {
  261. get { return bindableProperty; }
  262. set { bindableProperty = value; }
  263. }
  264. /// <summary>
  265. /// Gets or sets a script method name that will be used to handle the
  266. /// <see cref="Click"/> event.
  267. /// </summary>
  268. [Category("Events")]
  269. public string ClickEvent
  270. {
  271. get { return clickEvent; }
  272. set { clickEvent = value; }
  273. }
  274. /// <summary>
  275. /// Gets or sets a script method name that will be used to handle the
  276. /// <see cref="DoubleClick"/> event.
  277. /// </summary>
  278. [Category("Events")]
  279. public string DoubleClickEvent
  280. {
  281. get { return doubleClickEvent; }
  282. set { doubleClickEvent = value; }
  283. }
  284. /// <summary>
  285. /// Gets or sets a script method name that will be used to handle the
  286. /// <see cref="Enter"/> event.
  287. /// </summary>
  288. [Category("Events")]
  289. public string EnterEvent
  290. {
  291. get { return enterEvent; }
  292. set { enterEvent = value; }
  293. }
  294. /// <summary>
  295. /// Gets or sets a script method name that will be used to handle the
  296. /// <see cref="Leave"/> event.
  297. /// </summary>
  298. [Category("Events")]
  299. public string LeaveEvent
  300. {
  301. get { return leaveEvent; }
  302. set { leaveEvent = value; }
  303. }
  304. /// <summary>
  305. /// Gets or sets a script method name that will be used to handle the
  306. /// <see cref="KeyDown"/> event.
  307. /// </summary>
  308. [Category("Events")]
  309. public string KeyDownEvent
  310. {
  311. get { return keyDownEvent; }
  312. set { keyDownEvent = value; }
  313. }
  314. /// <summary>
  315. /// Gets or sets a script method name that will be used to handle the
  316. /// <see cref="KeyPress"/> event.
  317. /// </summary>
  318. [Category("Events")]
  319. public string KeyPressEvent
  320. {
  321. get { return keyPressEvent; }
  322. set { keyPressEvent = value; }
  323. }
  324. /// <summary>
  325. /// Gets or sets a script method name that will be used to handle the
  326. /// <see cref="KeyUp"/> event.
  327. /// </summary>
  328. [Category("Events")]
  329. public string KeyUpEvent
  330. {
  331. get { return keyUpEvent; }
  332. set { keyUpEvent = value; }
  333. }
  334. /// <summary>
  335. /// Gets or sets a script method name that will be used to handle the
  336. /// <see cref="MouseDown"/> event.
  337. /// </summary>
  338. [Category("Events")]
  339. public string MouseDownEvent
  340. {
  341. get { return mouseDownEvent; }
  342. set { mouseDownEvent = value; }
  343. }
  344. /// <summary>
  345. /// Gets or sets a script method name that will be used to handle the
  346. /// <see cref="MouseMove"/> event.
  347. /// </summary>
  348. [Category("Events")]
  349. public string MouseMoveEvent
  350. {
  351. get { return mouseMoveEvent; }
  352. set { mouseMoveEvent = value; }
  353. }
  354. /// <summary>
  355. /// Gets or sets a script method name that will be used to handle the
  356. /// <see cref="MouseUp"/> event.
  357. /// </summary>
  358. [Category("Events")]
  359. public string MouseUpEvent
  360. {
  361. get { return mouseUpEvent; }
  362. set { mouseUpEvent = value; }
  363. }
  364. /// <summary>
  365. /// Gets or sets a script method name that will be used to handle the
  366. /// <see cref="MouseEnter"/> event.
  367. /// </summary>
  368. [Category("Events")]
  369. public string MouseEnterEvent
  370. {
  371. get { return mouseEnterEvent; }
  372. set { mouseEnterEvent = value; }
  373. }
  374. /// <summary>
  375. /// Gets or sets a script method name that will be used to handle the
  376. /// <see cref="MouseLeave"/> event.
  377. /// </summary>
  378. [Category("Events")]
  379. public string MouseLeaveEvent
  380. {
  381. get { return mouseLeaveEvent; }
  382. set { mouseLeaveEvent = value; }
  383. }
  384. /// <summary>
  385. /// Gets or sets a script method name that will be used to handle the
  386. /// <see cref="Resize"/> event.
  387. /// </summary>
  388. [Category("Events")]
  389. public string ResizeEvent
  390. {
  391. get { return resizeEvent; }
  392. set { resizeEvent = value; }
  393. }
  394. /// <summary>
  395. /// Gets or sets a script method name that will be used to handle the
  396. /// <see cref="TextChanged"/> event.
  397. /// </summary>
  398. [Category("Events")]
  399. public string TextChangedEvent
  400. {
  401. get { return textChangedEvent; }
  402. set { textChangedEvent = value; }
  403. }
  404. /// <summary>
  405. /// Gets or sets a script method name that will be used to handle the
  406. /// <see cref="Paint"/> event.
  407. /// </summary>
  408. [Category("Events")]
  409. public string PaintEvent
  410. {
  411. get { return paintEvent; }
  412. set { paintEvent = value; }
  413. }
  414. /// <inheritdoc/>
  415. public override float Left
  416. {
  417. get { return Control.Left; }
  418. set
  419. {
  420. if (!IsDesigning || !HasRestriction(Restrictions.DontMove))
  421. Control.Left = (int)value;
  422. }
  423. }
  424. /// <inheritdoc/>
  425. public override float Top
  426. {
  427. get { return Control.Top; }
  428. set
  429. {
  430. if (!IsDesigning || !HasRestriction(Restrictions.DontMove))
  431. Control.Top = (int)value;
  432. }
  433. }
  434. /// <inheritdoc/>
  435. public override float Width
  436. {
  437. get { return Control.Width; }
  438. set
  439. {
  440. if (!IsDesigning || !HasRestriction(Restrictions.DontResize))
  441. Control.Width = (int)value;
  442. }
  443. }
  444. /// <inheritdoc/>
  445. public override float Height
  446. {
  447. get { return Control.Height; }
  448. set
  449. {
  450. if (!IsDesigning || !HasRestriction(Restrictions.DontResize))
  451. Control.Height = (int)value;
  452. }
  453. }
  454. #endregion
  455. #region Private Methods
  456. private void Control_Click(object sender, EventArgs e)
  457. {
  458. OnClick(e);
  459. }
  460. private void Control_DoubleClick(object sender, EventArgs e)
  461. {
  462. OnDoubleClick(e);
  463. }
  464. private void Control_Enter(object sender, EventArgs e)
  465. {
  466. OnEnter(e);
  467. }
  468. private void Control_Leave(object sender, EventArgs e)
  469. {
  470. OnLeave(e);
  471. }
  472. private void Control_KeyDown(object sender, KeyEventArgs e)
  473. {
  474. OnKeyDown(e);
  475. }
  476. private void Control_KeyPress(object sender, KeyPressEventArgs e)
  477. {
  478. OnKeyPress(e);
  479. }
  480. private void Control_KeyUp(object sender, KeyEventArgs e)
  481. {
  482. OnKeyUp(e);
  483. }
  484. private void Control_MouseDown(object sender, MouseEventArgs e)
  485. {
  486. OnMouseDown(e);
  487. }
  488. private void Control_MouseMove(object sender, MouseEventArgs e)
  489. {
  490. OnMouseMove(e);
  491. }
  492. private void Control_MouseUp(object sender, MouseEventArgs e)
  493. {
  494. OnMouseUp(e);
  495. }
  496. private void Control_MouseEnter(object sender, EventArgs e)
  497. {
  498. OnMouseEnter(e);
  499. }
  500. private void Control_MouseLeave(object sender, EventArgs e)
  501. {
  502. OnMouseLeave(e);
  503. }
  504. private void Control_Resize(object sender, EventArgs e)
  505. {
  506. OnResize(e);
  507. }
  508. private void Control_TextChanged(object sender, EventArgs e)
  509. {
  510. OnTextChanged(e);
  511. }
  512. private void Control_Paint(object sender, PaintEventArgs e)
  513. {
  514. OnPaint(e);
  515. }
  516. #endregion
  517. #region Protected Methods
  518. /// <inheritdoc/>
  519. protected override void Dispose(bool disposing)
  520. {
  521. base.Dispose(disposing);
  522. if (disposing)
  523. Control.Dispose();
  524. }
  525. /// <summary>
  526. /// Called when the control's Enabled state changed.
  527. /// </summary>
  528. protected virtual void OnEnabledChanged()
  529. {
  530. }
  531. /// <summary>
  532. /// Attaches <b>Control</b> events to its event handlers.
  533. /// </summary>
  534. /// <remarks>
  535. /// Override this method if your custom control has own events.
  536. /// </remarks>
  537. /// <example>See the example of <b>AttachEvents</b> implementation used in the <b>CheckBoxControl</b>:
  538. /// <code>
  539. /// protected override void AttachEvents()
  540. /// {
  541. /// base.AttachEvents();
  542. /// CheckBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
  543. /// }
  544. ///
  545. /// private void CheckBox_CheckedChanged(object sender, EventArgs e)
  546. /// {
  547. /// if (CheckedChanged != null)
  548. /// CheckedChanged(this, e);
  549. /// InvokeEvent(CheckedChangedEvent, e);
  550. /// }
  551. /// </code>
  552. /// </example>
  553. protected virtual void AttachEvents()
  554. {
  555. Control.Click += new EventHandler(Control_Click);
  556. Control.DoubleClick += new EventHandler(Control_DoubleClick);
  557. Control.Enter += new EventHandler(Control_Enter);
  558. Control.Leave += new EventHandler(Control_Leave);
  559. Control.KeyDown += new KeyEventHandler(Control_KeyDown);
  560. Control.KeyPress += new KeyPressEventHandler(Control_KeyPress);
  561. Control.KeyUp += new KeyEventHandler(Control_KeyUp);
  562. Control.MouseDown += new MouseEventHandler(Control_MouseDown);
  563. Control.MouseMove += new MouseEventHandler(Control_MouseMove);
  564. Control.MouseUp += new MouseEventHandler(Control_MouseUp);
  565. Control.MouseEnter += new EventHandler(Control_MouseEnter);
  566. Control.MouseLeave += new EventHandler(Control_MouseLeave);
  567. Control.Resize += new EventHandler(Control_Resize);
  568. Control.TextChanged += new EventHandler(Control_TextChanged);
  569. Control.Paint += new PaintEventHandler(Control_Paint);
  570. }
  571. /// <summary>
  572. /// Detaches <b>Control</b> events from its event handlers.
  573. /// </summary>
  574. /// <remarks>
  575. /// Override this method if your custom control has own events. In this method, you should
  576. /// detach control's events that were attached in the <see cref="AttachEvents"/> method.
  577. /// </remarks>
  578. /// <example>See the example of <b>DetachEvents</b> implementation used in the <b>CheckBoxControl</b>:
  579. /// <code>
  580. /// protected override void DetachEvents()
  581. /// {
  582. /// base.DetachEvents();
  583. /// CheckBox.CheckedChanged -= new EventHandler(CheckBox_CheckedChanged);
  584. /// }
  585. /// </code>
  586. /// </example>
  587. protected virtual void DetachEvents()
  588. {
  589. Control.Click -= new EventHandler(Control_Click);
  590. Control.DoubleClick -= new EventHandler(Control_DoubleClick);
  591. Control.Enter -= new EventHandler(Control_Enter);
  592. Control.Leave -= new EventHandler(Control_Leave);
  593. Control.KeyDown -= new KeyEventHandler(Control_KeyDown);
  594. Control.KeyPress -= new KeyPressEventHandler(Control_KeyPress);
  595. Control.KeyUp -= new KeyEventHandler(Control_KeyUp);
  596. Control.MouseDown -= new MouseEventHandler(Control_MouseDown);
  597. Control.MouseMove -= new MouseEventHandler(Control_MouseMove);
  598. Control.MouseUp -= new MouseEventHandler(Control_MouseUp);
  599. Control.MouseEnter -= new EventHandler(Control_MouseEnter);
  600. Control.MouseLeave -= new EventHandler(Control_MouseLeave);
  601. Control.Resize -= new EventHandler(Control_Resize);
  602. Control.TextChanged -= new EventHandler(Control_TextChanged);
  603. Control.Paint -= new PaintEventHandler(Control_Paint);
  604. }
  605. #endregion
  606. #region Public Methods
  607. /// <inheritdoc/>
  608. public override void SetParent(Base value)
  609. {
  610. base.SetParent(value);
  611. if (Parent is DialogPage)
  612. Control.Parent = (Parent as DialogPage).Form;
  613. else if (Parent is ParentControl)
  614. Control.Parent = (Parent as ParentControl).Control;
  615. else if (Parent == null)
  616. Control.Parent = null;
  617. #if !FRCORE
  618. if (Control.Parent != null)
  619. {
  620. // in winforms, the controls are added in opposite order
  621. Control.BringToFront();
  622. // this will reset the font to form's font. We need this to ensure the automatic form scaling will do the work
  623. if (Control.Font.Equals(Control.Parent.Font))
  624. Control.Font = null;
  625. }
  626. #endif
  627. }
  628. /// <inheritdoc/>
  629. public override void Serialize(FRWriter writer)
  630. {
  631. if (Page == null)
  632. return;
  633. DialogControl c = writer.DiffObject as DialogControl;
  634. base.Serialize(writer);
  635. if (BackColor != c.BackColor)
  636. writer.WriteValue("BackColor", BackColor);
  637. if (Cursor != c.Cursor)
  638. writer.WriteValue("Cursor", Cursor);
  639. if (Enabled != c.Enabled)
  640. writer.WriteBool("Enabled", Enabled);
  641. Form form = (Page as DialogPage).Form;
  642. // fixed 27.08.2021 for FR.Core, if uncomment this condition - font doesn't serialise => next open report with font = null
  643. if (form != null /*&& !Font.Equals(Control.Parent.Font)*/ && writer.ItemName != "inherited")
  644. {
  645. #if !FRCORE
  646. float fontDpiMultiplier = form.FontDpiMultiplier();
  647. #else
  648. float fontDpiMultiplier = 1;
  649. #endif
  650. using (Font f = new Font(Font.FontFamily, Font.Size / fontDpiMultiplier, Font.Style))
  651. writer.WriteValue("Font", f);
  652. }
  653. if (ForeColor != c.ForeColor)
  654. writer.WriteValue("ForeColor", ForeColor);
  655. if (RightToLeft != c.RightToLeft)
  656. writer.WriteValue("RightToLeft", RightToLeft);
  657. writer.WriteInt("TabIndex", TabIndex);
  658. if (TabStop != c.TabStop)
  659. writer.WriteBool("TabStop", TabStop);
  660. if (Text != c.Text)
  661. writer.WriteStr("Text", Text);
  662. if (ClickEvent != c.ClickEvent)
  663. writer.WriteStr("ClickEvent", ClickEvent);
  664. if (DoubleClickEvent != c.DoubleClickEvent)
  665. writer.WriteStr("DoubleClickEvent", DoubleClickEvent);
  666. if (EnterEvent != c.EnterEvent)
  667. writer.WriteStr("EnterEvent", EnterEvent);
  668. if (LeaveEvent != c.LeaveEvent)
  669. writer.WriteStr("LeaveEvent", LeaveEvent);
  670. if (KeyDownEvent != c.KeyDownEvent)
  671. writer.WriteStr("KeyDownEvent", KeyDownEvent);
  672. if (KeyPressEvent != c.KeyPressEvent)
  673. writer.WriteStr("KeyPressEvent", KeyPressEvent);
  674. if (KeyUpEvent != c.KeyUpEvent)
  675. writer.WriteStr("KeyUpEvent", KeyUpEvent);
  676. if (MouseDownEvent != c.MouseDownEvent)
  677. writer.WriteStr("MouseDownEvent", MouseDownEvent);
  678. if (MouseMoveEvent != c.MouseMoveEvent)
  679. writer.WriteStr("MouseMoveEvent", MouseMoveEvent);
  680. if (MouseUpEvent != c.MouseUpEvent)
  681. writer.WriteStr("MouseUpEvent", MouseUpEvent);
  682. if (MouseEnterEvent != c.MouseEnterEvent)
  683. writer.WriteStr("MouseEnterEvent", MouseEnterEvent);
  684. if (MouseLeaveEvent != c.MouseLeaveEvent)
  685. writer.WriteStr("MouseLeaveEvent", MouseLeaveEvent);
  686. if (ResizeEvent != c.ResizeEvent)
  687. writer.WriteStr("ResizeEvent", ResizeEvent);
  688. if (TextChangedEvent != c.TextChangedEvent)
  689. writer.WriteStr("TextChangedEvent", TextChangedEvent);
  690. if (PaintEvent != c.PaintEvent)
  691. writer.WriteStr("PaintEvent", PaintEvent);
  692. }
  693. /// <summary>
  694. /// Initializes the control before display it in the dialog form.
  695. /// </summary>
  696. /// <remarks>
  697. /// This method is called when report is run.
  698. /// </remarks>
  699. public virtual void InitializeControl()
  700. {
  701. AttachEvents();
  702. }
  703. /// <summary>
  704. /// Finalizes the control after its parent form is closed.
  705. /// </summary>
  706. /// <remarks>
  707. /// This method is called when report is run.
  708. /// </remarks>
  709. public virtual void FinalizeControl()
  710. {
  711. DetachEvents();
  712. }
  713. /// <summary>
  714. /// Sets input focus to the control.
  715. /// </summary>
  716. public void Focus()
  717. {
  718. Control.Focus();
  719. }
  720. /// <summary>
  721. /// Conceals the control from the user.
  722. /// </summary>
  723. public void Hide()
  724. {
  725. Control.Hide();
  726. }
  727. /// <summary>
  728. /// Displays the control to the user.
  729. /// </summary>
  730. public void Show()
  731. {
  732. Control.Show();
  733. }
  734. #endregion
  735. #region Invoke Events
  736. /// <summary>
  737. /// This method fires the <b>Click</b> event and the script code connected to the <b>ClickEvent</b>.
  738. /// </summary>
  739. /// <param name="e">Event data.</param>
  740. public virtual void OnClick(EventArgs e)
  741. {
  742. if (Click != null)
  743. Click(this, e);
  744. InvokeEvent(ClickEvent, e);
  745. }
  746. /// <summary>
  747. /// This method fires the <b>DoubleClick</b> event and the script code connected to the <b>DoubleClickEvent</b>.
  748. /// </summary>
  749. /// <param name="e">Event data.</param>
  750. public virtual void OnDoubleClick(EventArgs e)
  751. {
  752. if (DoubleClick != null)
  753. DoubleClick(this, e);
  754. InvokeEvent(DoubleClickEvent, e);
  755. }
  756. /// <summary>
  757. /// This method fires the <b>Enter</b> event and the script code connected to the <b>EnterEvent</b>.
  758. /// </summary>
  759. /// <param name="e">Event data.</param>
  760. public virtual void OnEnter(EventArgs e)
  761. {
  762. if (Enter != null)
  763. Enter(this, e);
  764. InvokeEvent(EnterEvent, e);
  765. }
  766. /// <summary>
  767. /// This method fires the <b>Leave</b> event and the script code connected to the <b>LeaveEvent</b>.
  768. /// </summary>
  769. /// <param name="e">Event data.</param>
  770. public virtual void OnLeave(EventArgs e)
  771. {
  772. if (Leave != null)
  773. Leave(this, e);
  774. InvokeEvent(LeaveEvent, e);
  775. }
  776. /// <summary>
  777. /// This method fires the <b>KeyDown</b> event and the script code connected to the <b>KeyDownEvent</b>.
  778. /// </summary>
  779. /// <param name="e">Event data.</param>
  780. public virtual void OnKeyDown(KeyEventArgs e)
  781. {
  782. if (KeyDown != null)
  783. KeyDown(this, e);
  784. InvokeEvent(KeyDownEvent, e);
  785. }
  786. /// <summary>
  787. /// This method fires the <b>KeyPress</b> event and the script code connected to the <b>KeyPressEvent</b>.
  788. /// </summary>
  789. /// <param name="e">Event data.</param>
  790. public virtual void OnKeyPress(KeyPressEventArgs e)
  791. {
  792. if (KeyPress != null)
  793. KeyPress(this, e);
  794. InvokeEvent(KeyPressEvent, e);
  795. }
  796. /// <summary>
  797. /// This method fires the <b>KeyUp</b> event and the script code connected to the <b>KeyUpEvent</b>.
  798. /// </summary>
  799. /// <param name="e">Event data.</param>
  800. public virtual void OnKeyUp(KeyEventArgs e)
  801. {
  802. if (KeyUp != null)
  803. KeyUp(this, e);
  804. InvokeEvent(KeyUpEvent, e);
  805. }
  806. /// <summary>
  807. /// This method fires the <b>MouseDown</b> event and the script code connected to the <b>MouseDownEvent</b>.
  808. /// </summary>
  809. /// <param name="e">Event data.</param>
  810. public virtual void OnMouseDown(MouseEventArgs e)
  811. {
  812. if (MouseDown != null)
  813. MouseDown(this, e);
  814. InvokeEvent(MouseDownEvent, e);
  815. }
  816. /// <summary>
  817. /// This method fires the <b>MouseMove</b> event and the script code connected to the <b>MouseMoveEvent</b>.
  818. /// </summary>
  819. /// <param name="e">Event data.</param>
  820. public virtual void OnMouseMove(MouseEventArgs e)
  821. {
  822. if (MouseMove != null)
  823. MouseMove(this, e);
  824. InvokeEvent(MouseMoveEvent, e);
  825. }
  826. /// <summary>
  827. /// This method fires the <b>MouseUp</b> event and the script code connected to the <b>MouseUpEvent</b>.
  828. /// </summary>
  829. /// <param name="e">Event data.</param>
  830. public virtual void OnMouseUp(MouseEventArgs e)
  831. {
  832. if (MouseUp != null)
  833. MouseUp(this, e);
  834. InvokeEvent(MouseUpEvent, e);
  835. }
  836. /// <summary>
  837. /// This method fires the <b>MouseEnter</b> event and the script code connected to the <b>MouseEnterEvent</b>.
  838. /// </summary>
  839. /// <param name="e">Event data.</param>
  840. public virtual void OnMouseEnter(EventArgs e)
  841. {
  842. if (MouseEnter != null)
  843. MouseEnter(this, e);
  844. InvokeEvent(MouseEnterEvent, e);
  845. }
  846. /// <summary>
  847. /// This method fires the <b>MouseLeave</b> event and the script code connected to the <b>MouseLeaveEvent</b>.
  848. /// </summary>
  849. /// <param name="e">Event data.</param>
  850. public virtual void OnMouseLeave(EventArgs e)
  851. {
  852. if (MouseLeave != null)
  853. MouseLeave(this, e);
  854. InvokeEvent(MouseLeaveEvent, e);
  855. }
  856. /// <summary>
  857. /// This method fires the <b>Resize</b> event and the script code connected to the <b>ResizeEvent</b>.
  858. /// </summary>
  859. /// <param name="e">Event data.</param>
  860. public virtual void OnResize(EventArgs e)
  861. {
  862. if (Resize != null)
  863. Resize(this, e);
  864. InvokeEvent(ResizeEvent, e);
  865. }
  866. /// <summary>
  867. /// This method fires the <b>TextChanged</b> event and the script code connected to the <b>TextChangedEvent</b>.
  868. /// </summary>
  869. /// <param name="e">Event data.</param>
  870. public virtual void OnTextChanged(EventArgs e)
  871. {
  872. if (TextChanged != null)
  873. TextChanged(this, e);
  874. InvokeEvent(TextChangedEvent, e);
  875. }
  876. /// <summary>
  877. /// This method fires the <b>Paint</b> event and the script code connected to the <b>PaintEvent</b>.
  878. /// </summary>
  879. /// <param name="e">Event data.</param>
  880. public virtual void OnPaint(PaintEventArgs e)
  881. {
  882. if (Paint != null)
  883. Paint(this, e);
  884. InvokeEvent(PaintEvent, e);
  885. }
  886. #endregion
  887. }
  888. }