DKCheckBoxComboBox.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:ObjectSelectionWrapper.cs
  5. * 2.功能描述:下拉用户控件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2014/09/29 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Drawing;
  14. using System.Reflection;
  15. using System.Windows.Forms;
  16. namespace Dongke.IBOSS.PRD.Basics.BaseControls
  17. {
  18. /// <summary>
  19. /// Martin Lottering : 2007-10-27
  20. /// --------------------------------
  21. /// This is a usefull control in Filters. Allows you to save space and can replace a Grouped Box of CheckBoxes.
  22. /// Currently used on the TasksFilter for TaskStatusses, which means the user can select which Statusses to include
  23. /// in the "Search".
  24. /// This control does not implement a CheckBoxListBox, instead it adds a wrapper for the normal ComboBox and Items.
  25. /// See the CheckBoxItems property.
  26. /// ----------------
  27. /// ALSO IMPORTANT: In Data Binding when setting the DataSource. The ValueMember must be a bool type property, because it will
  28. /// be binded to the Checked property of the displayed CheckBox. Also see the DisplayMemberSingleItem for more information.
  29. /// ----------------
  30. /// Extends the CodeProject PopupComboBox "Simple pop-up control" "http://www.codeproject.com/cs/miscctrl/simplepopup.asp"
  31. /// by Lukasz Swiatkowski.
  32. /// </summary>
  33. public partial class DKCheckBoxComboBox : PopupComboBox
  34. {
  35. #region CONSTRUCTOR
  36. public DKCheckBoxComboBox()
  37. : base()
  38. {
  39. InitializeComponent();
  40. _CheckBoxProperties = new CheckBoxProperties();
  41. _CheckBoxProperties.PropertyChanged += new EventHandler(_CheckBoxProperties_PropertyChanged);
  42. // Dumps the ListControl in a(nother) Container to ensure the ScrollBar on the ListControl does not
  43. // Paint over the Size grip. Setting the Padding or Margin on the Popup or host control does
  44. // not work as I expected. I don't think it can work that way.
  45. CheckBoxComboBoxListControlContainer ContainerControl = new CheckBoxComboBoxListControlContainer();
  46. _CheckBoxComboBoxListControl = new CheckBoxComboBoxListControl(this);
  47. _CheckBoxComboBoxListControl.Items.CheckBoxCheckedChanged += new EventHandler(Items_CheckBoxCheckedChanged);
  48. ContainerControl.Controls.Add(_CheckBoxComboBoxListControl);
  49. // This padding spaces neatly on the left-hand side and allows space for the size grip at the bottom.
  50. ContainerControl.Padding = new Padding(4, 0, 0, 14);
  51. // The ListControl FILLS the ListContainer.
  52. _CheckBoxComboBoxListControl.Dock = DockStyle.Fill;
  53. // The DropDownControl used by the base class. Will be wrapped in a popup by the base class.
  54. DropDownControl = ContainerControl;
  55. // Must be set after the DropDownControl is set, since the popup is recreated.
  56. // NOTE: I made the dropDown protected so that it can be accessible here. It was private.
  57. dropDown.Resizable = true;
  58. //DropDownStyle = ComboBoxStyle.DropDownList;
  59. //ReadOnly = true;
  60. DisplayMemberSingleItem = "Name";
  61. DisplayMember = "NameConcatenated";
  62. ValueMember = "Selected";
  63. }
  64. #endregion
  65. #region PRIVATE PROPERTIES
  66. /// <summary>
  67. /// The checkbox list control. The public CheckBoxItems property provides a direct reference to its Items.
  68. /// </summary>
  69. private CheckBoxComboBoxListControl _CheckBoxComboBoxListControl;
  70. /// <summary>
  71. /// In DataBinding operations, this property will be used as the DisplayMember in the CheckBoxComboBoxListBox.
  72. /// The normal/existing "DisplayMember" property is used by the TextBox of the ComboBox to display
  73. /// a concatenated Text of the items selected. This concatenation and its formatting however is controlled
  74. /// by the Binded object, since it owns that property.
  75. /// </summary>
  76. private string _DisplayMemberSingleItem = null;
  77. #endregion
  78. #region PUBLIC PROPERTIES
  79. /// <summary>
  80. /// A direct reference to the Items of CheckBoxComboBoxListControl.
  81. /// You can use it to Get or Set the Checked status of items manually if you want.
  82. /// But do not manipulate the List itself directly, e.g. Adding and Removing,
  83. /// since the list is synchronised when shown with the ComboBox.Items. So for changing
  84. /// the list contents, use Items instead.
  85. /// </summary>
  86. [Browsable(false)]
  87. public CheckBoxComboBoxItemList CheckBoxItems
  88. {
  89. get { return _CheckBoxComboBoxListControl.Items; }
  90. }
  91. /// <summary>
  92. /// The DataSource of the combobox. Refreshes the CheckBox wrappers when this is set.
  93. /// </summary>
  94. public new object DataSource
  95. {
  96. get { return base.DataSource; }
  97. set
  98. {
  99. base.DataSource = value;
  100. if (!string.IsNullOrEmpty(ValueMember))
  101. // This ensures that at least the checkboxitems are available to be initialised.
  102. _CheckBoxComboBoxListControl.SynchroniseControlsWithComboBoxItems();
  103. }
  104. }
  105. /// <summary>
  106. /// The ValueMember of the combobox. Refreshes the CheckBox wrappers when this is set.
  107. /// </summary>
  108. public new string ValueMember
  109. {
  110. get { return base.ValueMember; }
  111. set
  112. {
  113. base.ValueMember = value;
  114. if (!string.IsNullOrEmpty(ValueMember))
  115. // This ensures that at least the checkboxitems are available to be initialised.
  116. _CheckBoxComboBoxListControl.SynchroniseControlsWithComboBoxItems();
  117. }
  118. }
  119. /// <summary>
  120. /// In DataBinding operations, this property will be used as the DisplayMember in the CheckBoxComboBoxListBox.
  121. /// The normal/existing "DisplayMember" property is used by the TextBox of the ComboBox to display
  122. /// a concatenated Text of the items selected. This concatenation however is controlled by the Binded
  123. /// object, since it owns that property.
  124. /// </summary>
  125. public string DisplayMemberSingleItem
  126. {
  127. get { if (string.IsNullOrEmpty(_DisplayMemberSingleItem)) return DisplayMember; else return _DisplayMemberSingleItem; }
  128. set { _DisplayMemberSingleItem = value; }
  129. }
  130. /// <summary>
  131. /// Made this property Browsable again, since the Base Popup hides it. This class uses it again.
  132. /// Gets an object representing the collection of the items contained in this
  133. /// System.Windows.Forms.ComboBox.
  134. /// </summary>
  135. /// <returns>A System.Windows.Forms.ComboBox.ObjectCollection representing the items in
  136. /// the System.Windows.Forms.ComboBox.
  137. /// </returns>
  138. [Browsable(true)]
  139. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  140. public new ObjectCollection Items
  141. {
  142. get { return base.Items; }
  143. }
  144. #endregion
  145. #region EVENTS & EVENT HANDLERS
  146. public event EventHandler CheckBoxCheckedChanged;
  147. private void Items_CheckBoxCheckedChanged(object sender, EventArgs e)
  148. {
  149. OnCheckBoxCheckedChanged(sender, e);
  150. }
  151. #endregion
  152. #region EVENT CALLERS and OVERRIDES e.g. OnResize()
  153. protected void OnCheckBoxCheckedChanged(object sender, EventArgs e)
  154. {
  155. if (DropDownStyle != ComboBoxStyle.DropDownList)
  156. {
  157. string ListText = "";
  158. foreach (DKCheckBoxComboBoxItem Item in _CheckBoxComboBoxListControl.Items)
  159. if (Item.Checked)
  160. ListText += string.IsNullOrEmpty(ListText) ? Item.Text : String.Format(", {0}", Item.Text);
  161. Text = ListText;
  162. }
  163. EventHandler handler = CheckBoxCheckedChanged;
  164. if (handler != null)
  165. handler(sender, e);
  166. }
  167. protected override void OnResize(EventArgs e)
  168. {
  169. // When the ComboBox is resized, the width of the dropdown
  170. // is also resized to match the width of the ComboBox. I think it looks better.
  171. Size Size = new Size(Width, DropDownControl.Height);
  172. dropDown.Size = Size;
  173. base.OnResize(e);
  174. }
  175. #endregion
  176. #region HELPER MEMBERS
  177. /// <summary>
  178. /// Uncheck all items.
  179. /// </summary>
  180. public void ClearSelection()
  181. {
  182. foreach (DKCheckBoxComboBoxItem Item in CheckBoxItems)
  183. if (Item.Checked)
  184. Item.Checked = false;
  185. }
  186. #endregion
  187. #region CHECKBOX PROPERTIES (DEFAULTS)
  188. private CheckBoxProperties _CheckBoxProperties;
  189. /// <summary>
  190. /// The properties that will be assigned to the checkboxes as default values.
  191. /// </summary>
  192. [Description("The properties that will be assigned to the checkboxes as default values.")]
  193. [Browsable(true)]
  194. public CheckBoxProperties CheckBoxProperties
  195. {
  196. get { return _CheckBoxProperties; }
  197. set { _CheckBoxProperties = value; _CheckBoxProperties_PropertyChanged(this, EventArgs.Empty); }
  198. }
  199. private void _CheckBoxProperties_PropertyChanged(object sender, EventArgs e)
  200. {
  201. foreach (DKCheckBoxComboBoxItem Item in CheckBoxItems)
  202. Item.ApplyProperties(CheckBoxProperties);
  203. }
  204. #endregion
  205. }
  206. /// <summary>
  207. /// A container control for the ListControl to ensure the ScrollBar on the ListControl does not
  208. /// Paint over the Size grip. Setting the Padding or Margin on the Popup or host control does
  209. /// not work as I expected.
  210. /// </summary>
  211. [ToolboxItem(false)]
  212. public class CheckBoxComboBoxListControlContainer : UserControl
  213. {
  214. #region CONSTRUCTOR
  215. public CheckBoxComboBoxListControlContainer()
  216. : base()
  217. {
  218. BackColor = SystemColors.Window;
  219. BorderStyle = BorderStyle.FixedSingle;
  220. AutoScaleMode = AutoScaleMode.Inherit;
  221. ResizeRedraw = true;
  222. // If you don't set this, then resize operations cause an error in the base class.
  223. MinimumSize = new Size(1, 1);
  224. MaximumSize = new Size(500, 500);
  225. }
  226. #endregion
  227. #region RESIZE OVERRIDE REQUIRED BY THE POPUP CONTROL
  228. /// <summary>
  229. /// Prescribed by the Popup class to ensure Resize operations work correctly.
  230. /// </summary>
  231. /// <param name="m"></param>
  232. protected override void WndProc(ref Message m)
  233. {
  234. if ((Parent as Popup).ProcessResizing(ref m))
  235. {
  236. return;
  237. }
  238. base.WndProc(ref m);
  239. }
  240. #endregion
  241. }
  242. /// <summary>
  243. /// This ListControl that pops up to the User. It contains the CheckBoxComboBoxItems.
  244. /// The items are docked DockStyle.Top in this control.
  245. /// </summary>
  246. [ToolboxItem(false)]
  247. public class CheckBoxComboBoxListControl : ScrollableControl
  248. {
  249. #region CONSTRUCTOR
  250. public CheckBoxComboBoxListControl(DKCheckBoxComboBox owner)
  251. : base()
  252. {
  253. DoubleBuffered = true;
  254. _CheckBoxComboBox = owner;
  255. BackColor = SystemColors.Window;
  256. // AutoScaleMode = AutoScaleMode.Inherit;
  257. AutoScroll = true;
  258. ResizeRedraw = true;
  259. // if you don't set this, a Resize operation causes an error in the base class.
  260. MinimumSize = new Size(1, 1);
  261. MaximumSize = new Size(500, 500);
  262. }
  263. #endregion
  264. #region PRIVATE PROPERTIES
  265. /// <summary>
  266. /// Simply a reference to the CheckBoxComboBox.
  267. /// </summary>
  268. private DKCheckBoxComboBox _CheckBoxComboBox;
  269. /// <summary>
  270. /// A Typed list of ComboBoxCheckBoxItems.
  271. /// </summary>
  272. private CheckBoxComboBoxItemList _Items = new CheckBoxComboBoxItemList();
  273. #endregion
  274. public CheckBoxComboBoxItemList Items { get { return _Items; } }
  275. #region RESIZE OVERRIDE REQUIRED BY THE POPUP CONTROL
  276. /// <summary>
  277. /// Prescribed by the Popup control to enable Resize operations.
  278. /// </summary>
  279. /// <param name="m"></param>
  280. protected override void WndProc(ref Message m)
  281. {
  282. if ((Parent.Parent as Popup).ProcessResizing(ref m))
  283. {
  284. return;
  285. }
  286. base.WndProc(ref m);
  287. }
  288. #endregion
  289. #region PROTECTED MEMBERS
  290. protected override void OnVisibleChanged(EventArgs e)
  291. {
  292. // Synchronises the CheckBox list with the items in the ComboBox.
  293. SynchroniseControlsWithComboBoxItems();
  294. base.OnVisibleChanged(e);
  295. }
  296. /// <summary>
  297. /// Maintains the controls displayed in the list by keeping them in sync with the actual
  298. /// items in the combobox. (e.g. removing and adding as well as ordering)
  299. /// </summary>
  300. public void SynchroniseControlsWithComboBoxItems()
  301. {
  302. SuspendLayout();
  303. Controls.Clear();
  304. #region Disposes all items that are no longer in the combo box list
  305. for (int Index = _Items.Count - 1; Index >= 0; Index--)
  306. {
  307. DKCheckBoxComboBoxItem Item = _Items[Index];
  308. if (!_CheckBoxComboBox.Items.Contains(Item.ComboBoxItem))
  309. {
  310. _Items.Remove(Item);
  311. Item.Dispose();
  312. }
  313. }
  314. #endregion
  315. #region Recreate the list in the same order of the combo box items
  316. CheckBoxComboBoxItemList NewList = new CheckBoxComboBoxItemList();
  317. foreach (object Object in _CheckBoxComboBox.Items)
  318. {
  319. DKCheckBoxComboBoxItem Item = _Items.Find(new Predicate<DKCheckBoxComboBoxItem>(
  320. delegate(DKCheckBoxComboBoxItem target)
  321. {
  322. return target.ComboBoxItem == Object;
  323. }));
  324. if (Item == null)
  325. {
  326. Item = new DKCheckBoxComboBoxItem(_CheckBoxComboBox, Object);
  327. Item.ApplyProperties(_CheckBoxComboBox.CheckBoxProperties);
  328. // Item.TextAlign = ContentAlignment.MiddleCenter;
  329. }
  330. NewList.Add(Item);
  331. Item.Dock = DockStyle.Top;
  332. }
  333. //NewList.CheckBoxCheckedChanged += _Items.CheckBoxCheckedChanged;
  334. _Items.Clear();
  335. _Items.AddRange(NewList);
  336. #endregion
  337. #region Add the items to the controls in reversed order to maintain correct docking order
  338. if (NewList.Count > 0)
  339. {
  340. // This reverse helps to maintain correct docking order.
  341. NewList.Reverse();
  342. // If you get an error here that "Cannot convert to the desired type, it probably
  343. // means the controls are not binding correctly.
  344. // The Checked property is binded to the ValueMember property. It must be a bool for example.
  345. Controls.AddRange(NewList.ToArray());
  346. }
  347. #endregion
  348. ResumeLayout();
  349. }
  350. #endregion
  351. }
  352. /// <summary>
  353. /// The CheckBox items displayed in the Popup of the ComboBox.
  354. /// </summary>
  355. [ToolboxItem(false)]
  356. public class DKCheckBoxComboBoxItem : CheckBox
  357. {
  358. #region CONSTRUCTOR
  359. /// <summary>
  360. ///
  361. /// </summary>
  362. /// <param name="owner">A reference to the CheckBoxComboBox.</param>
  363. /// <param name="comboBoxItem">A reference to the item in the ComboBox.Items that this object is extending.</param>
  364. public DKCheckBoxComboBoxItem(DKCheckBoxComboBox owner, object comboBoxItem)
  365. : base()
  366. {
  367. DoubleBuffered = true;
  368. _CheckBoxComboBox = owner;
  369. _ComboBoxItem = comboBoxItem;
  370. if (_CheckBoxComboBox.DataSource != null)
  371. AddBindings();
  372. else
  373. Text = comboBoxItem.ToString();
  374. }
  375. #endregion
  376. #region PRIVATE PROPERTIES
  377. /// <summary>
  378. /// A reference to the CheckBoxComboBox.
  379. /// </summary>
  380. private DKCheckBoxComboBox _CheckBoxComboBox;
  381. /// <summary>
  382. /// A reference to the Item in ComboBox.Items that this object is extending.
  383. /// </summary>
  384. private object _ComboBoxItem;
  385. #endregion
  386. #region PUBLIC PROPERTIES
  387. /// <summary>
  388. /// A reference to the Item in ComboBox.Items that this object is extending.
  389. /// </summary>
  390. public object ComboBoxItem
  391. {
  392. get { return _ComboBoxItem; }
  393. }
  394. #endregion
  395. #region BINDING HELPER
  396. /// <summary>
  397. /// When using Data Binding operations via the DataSource property of the ComboBox. This
  398. /// adds the required Bindings for the CheckBoxes.
  399. /// </summary>
  400. public void AddBindings()
  401. {
  402. // Note, the text uses "DisplayMemberSingleItem", not "DisplayMember" (unless its not assigned)
  403. DataBindings.Add(
  404. "Text",
  405. _ComboBoxItem,
  406. _CheckBoxComboBox.DisplayMemberSingleItem);
  407. // The ValueMember must be a bool type property usable by the CheckBox.Checked.
  408. DataBindings.Add(
  409. "Checked",
  410. _ComboBoxItem,
  411. _CheckBoxComboBox.ValueMember,
  412. false,
  413. // This helps to maintain proper selection state in the Binded object,
  414. // even when the controls are added and removed.
  415. DataSourceUpdateMode.OnPropertyChanged,
  416. false, null, null);
  417. }
  418. #endregion
  419. #region PROTECTED MEMBERS
  420. protected override void OnCheckedChanged(EventArgs e)
  421. {
  422. // Found that when this event is raised, the bool value of the binded item is not yet updated.
  423. if (_CheckBoxComboBox.DataSource != null)
  424. {
  425. PropertyInfo PI = ComboBoxItem.GetType().GetProperty(_CheckBoxComboBox.ValueMember);
  426. PI.SetValue(ComboBoxItem, Checked, null);
  427. }
  428. base.OnCheckedChanged(e);
  429. // Forces a refresh of the Text displayed in the main TextBox of the ComboBox,
  430. // since that Text will most probably represent a concatenation of selected values.
  431. // Also see DisplayMemberSingleItem on the CheckBoxComboBox for more information.
  432. if (_CheckBoxComboBox.DataSource != null)
  433. {
  434. string OldDisplayMember = _CheckBoxComboBox.DisplayMember;
  435. _CheckBoxComboBox.DisplayMember = null;
  436. _CheckBoxComboBox.DisplayMember = OldDisplayMember;
  437. }
  438. }
  439. #endregion
  440. #region HELPER MEMBERS
  441. internal void ApplyProperties(CheckBoxProperties properties)
  442. {
  443. this.Appearance = properties.Appearance;
  444. this.AutoCheck = properties.AutoCheck;
  445. this.AutoEllipsis = properties.AutoEllipsis;
  446. this.AutoSize = properties.AutoSize;
  447. this.CheckAlign = properties.CheckAlign;
  448. this.FlatAppearance.BorderColor = properties.FlatAppearanceBorderColor;
  449. this.FlatAppearance.BorderSize = properties.FlatAppearanceBorderSize;
  450. this.FlatAppearance.CheckedBackColor = properties.FlatAppearanceCheckedBackColor;
  451. this.FlatAppearance.MouseDownBackColor = properties.FlatAppearanceMouseDownBackColor;
  452. this.FlatAppearance.MouseOverBackColor = properties.FlatAppearanceMouseOverBackColor;
  453. this.FlatStyle = properties.FlatStyle;
  454. this.ForeColor = properties.ForeColor;
  455. this.RightToLeft = properties.RightToLeft;
  456. this.TextAlign = properties.TextAlign;
  457. this.ThreeState = properties.ThreeState;
  458. }
  459. #endregion
  460. }
  461. /// <summary>
  462. /// A Typed List of the CheckBox items.
  463. /// Simply a wrapper for the CheckBoxComboBox.Items. A list of CheckBoxComboBoxItem objects.
  464. /// This List is automatically synchronised with the Items of the ComboBox and extended to
  465. /// handle the additional boolean value. That said, do not Add or Remove using this List,
  466. /// it will be lost or regenerated from the ComboBox.Items.
  467. /// </summary>
  468. [ToolboxItem(false)]
  469. public class CheckBoxComboBoxItemList : List<DKCheckBoxComboBoxItem>
  470. {
  471. #region EVENTS, This could be moved to the list control if needed
  472. public event EventHandler CheckBoxCheckedChanged;
  473. protected void OnCheckBoxCheckedChanged(object sender, EventArgs e)
  474. {
  475. EventHandler handler = CheckBoxCheckedChanged;
  476. if (handler != null)
  477. handler(sender, e);
  478. }
  479. private void item_CheckedChanged(object sender, EventArgs e)
  480. {
  481. OnCheckBoxCheckedChanged(sender, e);
  482. }
  483. #endregion
  484. #region LIST MEMBERS & OBSOLETE INDICATORS
  485. [Obsolete("Do not add items to this list directly. Use the ComboBox items instead.", false)]
  486. public new void Add(DKCheckBoxComboBoxItem item)
  487. {
  488. item.CheckedChanged += new EventHandler(item_CheckedChanged);
  489. base.Add(item);
  490. }
  491. public new void AddRange(IEnumerable<DKCheckBoxComboBoxItem> collection)
  492. {
  493. foreach (DKCheckBoxComboBoxItem Item in collection)
  494. Item.CheckedChanged += new EventHandler(item_CheckedChanged);
  495. base.AddRange(collection);
  496. }
  497. public new void Clear()
  498. {
  499. foreach (DKCheckBoxComboBoxItem Item in this)
  500. Item.CheckedChanged -= item_CheckedChanged;
  501. base.Clear();
  502. }
  503. [Obsolete("Do not remove items from this list directly. Use the ComboBox items instead.", false)]
  504. public new bool Remove(DKCheckBoxComboBoxItem item)
  505. {
  506. item.CheckedChanged -= item_CheckedChanged;
  507. return base.Remove(item);
  508. }
  509. #endregion
  510. }
  511. [TypeConverter(typeof(ExpandableObjectConverter))]
  512. public class CheckBoxProperties
  513. {
  514. public CheckBoxProperties() { }
  515. #region PRIVATE PROPERTIES
  516. private Appearance _Appearance = Appearance.Normal;
  517. private bool _AutoSize = false;
  518. private bool _AutoCheck = true;
  519. private bool _AutoEllipsis = false;
  520. private ContentAlignment _CheckAlign = ContentAlignment.MiddleLeft;
  521. private Color _FlatAppearanceBorderColor = Color.Empty;
  522. private int _FlatAppearanceBorderSize = 1;
  523. private Color _FlatAppearanceCheckedBackColor = Color.Empty;
  524. private Color _FlatAppearanceMouseDownBackColor = Color.Empty;
  525. private Color _FlatAppearanceMouseOverBackColor = Color.Empty;
  526. private FlatStyle _FlatStyle = FlatStyle.Standard;
  527. private Color _ForeColor = SystemColors.ControlText;
  528. private RightToLeft _RightToLeft = RightToLeft.No;
  529. private ContentAlignment _TextAlign = ContentAlignment.MiddleLeft;
  530. private bool _ThreeState = false;
  531. #endregion
  532. #region PUBLIC PROPERTIES
  533. [DefaultValue(Appearance.Normal)]
  534. public Appearance Appearance
  535. {
  536. get { return _Appearance; }
  537. set { _Appearance = value; OnPropertyChanged(); }
  538. }
  539. [DefaultValue(true)]
  540. public bool AutoCheck
  541. {
  542. get { return _AutoCheck; }
  543. set { _AutoCheck = value; OnPropertyChanged(); }
  544. }
  545. [DefaultValue(false)]
  546. public bool AutoEllipsis
  547. {
  548. get { return _AutoEllipsis; }
  549. set { _AutoEllipsis = value; OnPropertyChanged(); }
  550. }
  551. [DefaultValue(false)]
  552. public bool AutoSize
  553. {
  554. get { return _AutoSize; }
  555. set { _AutoSize = true; OnPropertyChanged(); }
  556. }
  557. [DefaultValue(ContentAlignment.MiddleLeft)]
  558. public ContentAlignment CheckAlign
  559. {
  560. get { return _CheckAlign; }
  561. set { _CheckAlign = value; OnPropertyChanged(); }
  562. }
  563. [DefaultValue(typeof(Color), "")]
  564. public Color FlatAppearanceBorderColor
  565. {
  566. get { return _FlatAppearanceBorderColor; }
  567. set { _FlatAppearanceBorderColor = value; OnPropertyChanged(); }
  568. }
  569. [DefaultValue(1)]
  570. public int FlatAppearanceBorderSize
  571. {
  572. get { return _FlatAppearanceBorderSize; }
  573. set { _FlatAppearanceBorderSize = value; OnPropertyChanged(); }
  574. }
  575. [DefaultValue(typeof(Color), "")]
  576. public Color FlatAppearanceCheckedBackColor
  577. {
  578. get { return _FlatAppearanceCheckedBackColor; }
  579. set { _FlatAppearanceCheckedBackColor = value; OnPropertyChanged(); }
  580. }
  581. [DefaultValue(typeof(Color), "")]
  582. public Color FlatAppearanceMouseDownBackColor
  583. {
  584. get { return _FlatAppearanceMouseDownBackColor; }
  585. set { _FlatAppearanceMouseDownBackColor = value; OnPropertyChanged(); }
  586. }
  587. [DefaultValue(typeof(Color), "")]
  588. public Color FlatAppearanceMouseOverBackColor
  589. {
  590. get { return _FlatAppearanceMouseOverBackColor; }
  591. set { _FlatAppearanceMouseOverBackColor = value; OnPropertyChanged(); }
  592. }
  593. [DefaultValue(FlatStyle.Standard)]
  594. public FlatStyle FlatStyle
  595. {
  596. get { return _FlatStyle; }
  597. set { _FlatStyle = value; OnPropertyChanged(); }
  598. }
  599. [DefaultValue(typeof(SystemColors), "ControlText")]
  600. public Color ForeColor
  601. {
  602. get { return _ForeColor; }
  603. set { _ForeColor = value; OnPropertyChanged(); }
  604. }
  605. [DefaultValue(RightToLeft.No)]
  606. public RightToLeft RightToLeft
  607. {
  608. get { return _RightToLeft; }
  609. set { _RightToLeft = value; OnPropertyChanged(); }
  610. }
  611. [DefaultValue(ContentAlignment.MiddleLeft)]
  612. public ContentAlignment TextAlign
  613. {
  614. get { return _TextAlign; }
  615. set { _TextAlign = value; OnPropertyChanged(); }
  616. }
  617. [DefaultValue(false)]
  618. public bool ThreeState
  619. {
  620. get { return _ThreeState; }
  621. set { _ThreeState = value; OnPropertyChanged(); }
  622. }
  623. #endregion
  624. #region EVENTS AND EVENT CALLERS
  625. /// <summary>
  626. /// Called when any property changes.
  627. /// </summary>
  628. public event EventHandler PropertyChanged;
  629. protected void OnPropertyChanged()
  630. {
  631. EventHandler handler = PropertyChanged;
  632. if (handler != null)
  633. handler(this, EventArgs.Empty);
  634. }
  635. #endregion
  636. }
  637. }