TextBoxControl.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using System;
  2. using System.ComponentModel;
  3. using FastReport.Utils;
  4. using System.Windows.Forms;
  5. namespace FastReport.Dialog
  6. {
  7. /// <summary>
  8. /// Represents a Windows text box control.
  9. /// Wraps the <see cref="System.Windows.Forms.TextBox"/> control.
  10. /// </summary>
  11. public partial class TextBoxControl : DataFilterBaseControl
  12. {
  13. private TextBox textBox;
  14. #region Properties
  15. /// <summary>
  16. /// Gets an internal <b>TextBox</b>.
  17. /// </summary>
  18. [Browsable(false)]
  19. public TextBox TextBox
  20. {
  21. get { return textBox; }
  22. }
  23. /// <summary>
  24. /// Gets or sets a value indicating whether pressing ENTER in a multiline TextBox control creates a new line of text in the control or activates the default button for the form.
  25. /// Wraps the <see cref="System.Windows.Forms.TextBox.AcceptsReturn"/> property.
  26. /// </summary>
  27. [DefaultValue(false)]
  28. [Category("Behavior")]
  29. public bool AcceptsReturn
  30. {
  31. get { return TextBox.AcceptsReturn; }
  32. set { TextBox.AcceptsReturn = value; }
  33. }
  34. /// <summary>
  35. /// Gets or sets a value indicating whether pressing the TAB key in a multiline text box control types a TAB character in the control instead of moving the focus to the next control in the tab order.
  36. /// Wraps the <see cref="System.Windows.Forms.TextBoxBase.AcceptsTab"/> property.
  37. /// </summary>
  38. [DefaultValue(false)]
  39. [Category("Behavior")]
  40. public bool AcceptsTab
  41. {
  42. get { return TextBox.AcceptsTab; }
  43. set { TextBox.AcceptsTab = value; }
  44. }
  45. /// <summary>
  46. /// Gets or sets whether the TextBox control modifies the case of characters as they are typed.
  47. /// Wraps the <see cref="System.Windows.Forms.TextBox.CharacterCasing"/> property.
  48. /// </summary>
  49. [DefaultValue(CharacterCasing.Normal)]
  50. [Category("Behavior")]
  51. public CharacterCasing CharacterCasing
  52. {
  53. get { return TextBox.CharacterCasing; }
  54. set { TextBox.CharacterCasing = value; }
  55. }
  56. /// <summary>
  57. /// Gets or sets the maximum number of characters the user can type or paste into the text box control.
  58. /// Wraps the <see cref="System.Windows.Forms.TextBoxBase.MaxLength"/> property.
  59. /// </summary>
  60. [DefaultValue(32767)]
  61. [Category("Behavior")]
  62. public int MaxLength
  63. {
  64. get { return TextBox.MaxLength; }
  65. set { TextBox.MaxLength = value; }
  66. }
  67. /// <summary>
  68. /// Gets or sets a value indicating whether this is a multiline TextBox control.
  69. /// Wraps the <see cref="System.Windows.Forms.TextBox.Multiline"/> property.
  70. /// </summary>
  71. [DefaultValue(false)]
  72. [Category("Behavior")]
  73. public bool Multiline
  74. {
  75. get { return TextBox.Multiline; }
  76. set { TextBox.Multiline = value; }
  77. }
  78. /// <summary>
  79. /// Gets or sets a value indicating whether text in the text box is read-only.
  80. /// Wraps the <see cref="System.Windows.Forms.TextBoxBase.ReadOnly"/> property.
  81. /// </summary>
  82. [DefaultValue(false)]
  83. [Category("Behavior")]
  84. public bool ReadOnly
  85. {
  86. get { return TextBox.ReadOnly; }
  87. set { TextBox.ReadOnly = value; }
  88. }
  89. /// <summary>
  90. /// Gets or sets which scroll bars should appear in a multiline TextBox control.
  91. /// Wraps the <see cref="System.Windows.Forms.TextBox.ScrollBars"/> property.
  92. /// </summary>
  93. [DefaultValue(ScrollBars.None)]
  94. [Category("Appearance")]
  95. public ScrollBars ScrollBars
  96. {
  97. get { return TextBox.ScrollBars; }
  98. set { TextBox.ScrollBars = value; }
  99. }
  100. /// <summary>
  101. /// Gets or sets how text is aligned in a TextBox control.
  102. /// Wraps the <see cref="System.Windows.Forms.TextBox.TextAlign"/> property.
  103. /// </summary>
  104. [DefaultValue(HorizontalAlignment.Left)]
  105. [Category("Appearance")]
  106. public HorizontalAlignment TextAlign
  107. {
  108. get { return TextBox.TextAlign; }
  109. set { TextBox.TextAlign = value; }
  110. }
  111. /// <summary>
  112. /// Gets or sets a value indicating whether the text in the TextBox control should appear as the default password character.
  113. /// Wraps the <see cref="System.Windows.Forms.TextBox.UseSystemPasswordChar"/> property.
  114. /// </summary>
  115. [DefaultValue(false)]
  116. [Category("Behavior")]
  117. public bool UseSystemPasswordChar
  118. {
  119. get { return TextBox.UseSystemPasswordChar; }
  120. set { TextBox.UseSystemPasswordChar = value; }
  121. }
  122. /// <summary>
  123. /// Indicates whether a multiline text box control automatically wraps words to the beginning of the next line when necessary.
  124. /// Wraps the <see cref="System.Windows.Forms.TextBoxBase.WordWrap"/> property.
  125. /// </summary>
  126. [DefaultValue(true)]
  127. [Category("Behavior")]
  128. public bool WordWrap
  129. {
  130. get { return TextBox.WordWrap; }
  131. set { TextBox.WordWrap = value; }
  132. }
  133. #endregion
  134. #region Protected Methods
  135. /// <inheritdoc/>
  136. protected override object GetValue()
  137. {
  138. return Text;
  139. }
  140. #endregion
  141. #region Public Methods
  142. /// <inheritdoc/>
  143. public override void Serialize(FRWriter writer)
  144. {
  145. TextBoxControl c = writer.DiffObject as TextBoxControl;
  146. base.Serialize(writer);
  147. if (AcceptsReturn != c.AcceptsReturn)
  148. writer.WriteBool("AcceptsReturn", AcceptsReturn);
  149. if (AcceptsTab != c.AcceptsTab)
  150. writer.WriteBool("AcceptsTab", AcceptsTab);
  151. if (CharacterCasing != c.CharacterCasing)
  152. writer.WriteValue("CharacterCasing", CharacterCasing);
  153. if (MaxLength != c.MaxLength)
  154. writer.WriteInt("MaxLength", MaxLength);
  155. if (Multiline != c.Multiline)
  156. writer.WriteBool("Multiline", Multiline);
  157. if (ReadOnly != c.ReadOnly)
  158. writer.WriteBool("ReadOnly", ReadOnly);
  159. if (ScrollBars != c.ScrollBars)
  160. writer.WriteValue("ScrollBars", ScrollBars);
  161. if (TextAlign != c.TextAlign)
  162. writer.WriteValue("TextAlign", TextAlign);
  163. if (UseSystemPasswordChar != c.UseSystemPasswordChar)
  164. writer.WriteBool("UseSystemPasswordChar", UseSystemPasswordChar);
  165. if (WordWrap != c.WordWrap)
  166. writer.WriteBool("WordWrap", WordWrap);
  167. }
  168. /// <inheritdoc/>
  169. public override void OnLeave(EventArgs e)
  170. {
  171. base.OnLeave(e);
  172. OnFilterChanged();
  173. }
  174. #endregion
  175. /// <summary>
  176. /// Initializes a new instance of the <b>TextBoxControl</b> class with default settings.
  177. /// </summary>
  178. public TextBoxControl()
  179. {
  180. textBox = new TextBox();
  181. Control = textBox;
  182. BindableProperty = this.GetType().GetProperty("Text");
  183. }
  184. }
  185. }