PopupComboBox.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:NativeMethods.cs
  5. * 2.功能描述:
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2014/09/04 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Drawing;
  15. using System.Text;
  16. using System.Windows.Forms;
  17. using System.Security.Permissions;
  18. namespace Dongke.IBOSS.PRD.Basics.BaseControls
  19. {
  20. /// <summary>
  21. /// CodeProject.com "Simple pop-up control" "http://www.codeproject.com/cs/miscctrl/simplepopup.asp".
  22. /// Represents a Windows combo box control with a custom popup control attached.
  23. /// </summary>
  24. [ToolboxBitmap(typeof(System.Windows.Forms.ComboBox)), ToolboxItem(true), ToolboxItemFilter("System.Windows.Forms"), Description("Displays an editable text box with a drop-down list of permitted values.")]
  25. public abstract partial class PopupComboBox : DKComboBox
  26. {
  27. /// <summary>
  28. /// Initializes a new instance of the <see cref="PopupControl.PopupComboBox" /> class.
  29. /// </summary>
  30. public PopupComboBox()
  31. {
  32. InitializeComponent();
  33. base.DropDownHeight = base.DropDownWidth = 1;
  34. base.IntegralHeight = false;
  35. }
  36. /// <summary>
  37. /// The pop-up wrapper for the dropDownControl.
  38. /// Made PROTECTED instead of PRIVATE so descendent classes can set its Resizable property.
  39. /// Note however the pop-up properties must be set after the dropDownControl is assigned, since this
  40. /// popup wrapper is recreated when the dropDownControl is assigned.
  41. /// </summary>
  42. protected Popup dropDown;
  43. private Control dropDownControl;
  44. /// <summary>
  45. /// Gets or sets the drop down control.
  46. /// </summary>
  47. /// <value>The drop down control.</value>
  48. public Control DropDownControl
  49. {
  50. get
  51. {
  52. return dropDownControl;
  53. }
  54. set
  55. {
  56. if (dropDownControl == value)
  57. return;
  58. dropDownControl = value;
  59. dropDown = new Popup(value);
  60. }
  61. }
  62. /// <summary>
  63. /// Shows the drop down.
  64. /// </summary>
  65. public virtual void ShowDropDown()
  66. {
  67. if (dropDown != null)
  68. {
  69. dropDown.Show(this);
  70. }
  71. }
  72. /// <summary>
  73. /// Hides the drop down.
  74. /// </summary>
  75. public virtual void HideDropDown()
  76. {
  77. if (dropDown != null)
  78. {
  79. dropDown.Hide();
  80. }
  81. }
  82. /// <summary>
  83. /// Processes Windows messages.
  84. /// </summary>
  85. /// <param name="m">The Windows <see cref="T:System.Windows.Forms.Message" /> to process.</param>
  86. [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  87. protected override void WndProc(ref Message m)
  88. {
  89. if (m.Msg == (NativeMethods.WM_REFLECT + NativeMethods.WM_COMMAND))
  90. {
  91. if (NativeMethods.HIWORD(m.WParam) == NativeMethods.CBN_DROPDOWN)
  92. {
  93. // Blocks a redisplay when the user closes the control by clicking
  94. // on the combobox.
  95. TimeSpan TimeSpan = DateTime.Now.Subtract(dropDown.LastClosedTimeStamp);
  96. if (TimeSpan.TotalMilliseconds > 500)
  97. ShowDropDown();
  98. return;
  99. }
  100. }
  101. base.WndProc(ref m);
  102. }
  103. #region " Unused Properties "
  104. /// <summary>This property is not relevant for this class.</summary>
  105. /// <returns>This property is not relevant for this class.</returns>
  106. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
  107. public new int DropDownWidth
  108. {
  109. get { return base.DropDownWidth; }
  110. set { base.DropDownWidth = value; }
  111. }
  112. /// <summary>This property is not relevant for this class.</summary>
  113. /// <returns>This property is not relevant for this class.</returns>
  114. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
  115. public new int DropDownHeight
  116. {
  117. get { return base.DropDownHeight; }
  118. set
  119. {
  120. dropDown.Height = value;
  121. base.DropDownHeight = value;
  122. }
  123. }
  124. /// <summary>This property is not relevant for this class.</summary>
  125. /// <returns>This property is not relevant for this class.</returns>
  126. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
  127. public new bool IntegralHeight
  128. {
  129. get { return base.IntegralHeight; }
  130. set { base.IntegralHeight = value; }
  131. }
  132. /// <summary>This property is not relevant for this class.</summary>
  133. /// <returns>This property is not relevant for this class.</returns>
  134. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
  135. public new ObjectCollection Items
  136. {
  137. get { return base.Items; }
  138. }
  139. /// <summary>This property is not relevant for this class.</summary>
  140. /// <returns>This property is not relevant for this class.</returns>
  141. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
  142. public new int ItemHeight
  143. {
  144. get { return base.ItemHeight; }
  145. set { base.ItemHeight = value; }
  146. }
  147. #endregion
  148. }
  149. }