Advertisement
Guest User

[VB.Net] ElektroListBox v2.1 bugfix

a guest
Dec 11th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 71.79 KB | None | 0 0
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 11-December-2014
  4. ' ***********************************************************************
  5. ' <copyright file="ElektroListBox.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " UserControl Features Summary "
  11.  
  12. #Region " Properties "
  13.  
  14. ' ReadOnly
  15.  
  16. ' TextFormat.Alignment
  17. ' TextFormat.FormatFlags
  18. ' TextFormat.LineAlignment
  19. ' TextFormat.Trimming
  20.  
  21. ' StateEnabled.BorderColor
  22. ' StateDisabled.BorderColor
  23. ' StateReadOnly.BorderColor
  24.  
  25. ' StateEnabled.Cursor
  26. ' StateDisabled.Cursor
  27. ' StateReadOnly.Cursor
  28.  
  29. ' StateEnabled.Grid.Enabled
  30. ' StateEnabled.Grid.Color
  31. ' StateDisabled.Grid.Enabled
  32. ' StateDisabled.Grid.Color
  33. ' StateReadOnly.Grid.Enabled
  34. ' StateReadOnly.Grid.Color
  35.  
  36. ' StateEnabled.Items.Background.Selected
  37. ' StateEnabled.Items.Background.Unselected
  38. ' StateEnabled.Items.Background.UnselectedAlternate
  39. ' StateEnabled.Items.Foreground.Selected
  40. ' StateEnabled.Items.Foreground.Unselected
  41. ' StateEnabled.Items.Foreground.UnselectedAlternate
  42.  
  43. ' StateDisabled.Items.Background.Selected
  44. ' StateDisabled.Items.Background.Unselected
  45. ' StateDisabled.Items.Background.UnselectedAlternate
  46. ' StateDisabled.Items.Foreground.Selected
  47. ' StateDisabled.Items.Foreground.Unselected
  48. ' StateDisabled.Items.Foreground.UnselectedAlternate
  49.  
  50. ' StateReadOnly.Items.Background.Selected
  51. ' StateReadOnly.Items.Background.Unselected
  52. ' StateReadOnly.Items.Background.UnselectedAlternate
  53. ' StateReadOnly.Items.Foreground.Selected
  54. ' StateReadOnly.Items.Foreground.Unselected
  55. ' StateReadOnly.Items.Foreground.UnselectedAlternate
  56.  
  57. #End Region
  58.  
  59. #Region " Methods "
  60.  
  61. ' HasDuplicatedItems
  62. ' RemoveDuplicatedItems
  63. ' MoveItem
  64. ' SetSelectedNoJump
  65. ' SetSelectedAllorNone
  66.  
  67. #End Region
  68.  
  69. #End Region
  70.  
  71. #Region " Option Statements "
  72.  
  73. Option Explicit On
  74. Option Strict On
  75. Option Infer Off
  76.  
  77. #End Region
  78.  
  79. #Region " Imports "
  80.  
  81. Imports System.ComponentModel
  82. Imports System.Runtime.InteropServices
  83. Imports System.Drawing.Drawing2D
  84.  
  85. #End Region
  86.  
  87. #Region " ElektroListBox "
  88.  
  89. Namespace UserControls
  90.  
  91.     ''' <summary>
  92.     ''' A custom <see cref="T:ListBox"/> user control.
  93.     ''' </summary>
  94.     Public Class ElektroListBox : Inherits ListBox
  95.  
  96. #Region " P/Invoking "
  97.  
  98.         ''' <summary>
  99.         ''' Platform Invocation methods (P/Invoke), access unmanaged code.
  100.         ''' This class does not suppress stack walks for unmanaged code permission.
  101.         ''' <see cref="System.Security.SuppressUnmanagedCodeSecurityAttribute"/>  must not be applied to this class.
  102.         ''' This class is for methods that can be used anywhere because a stack walk will be performed.
  103.         ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/ms182161.aspx
  104.         ''' </summary>
  105.         Protected Class NativeMethods
  106.  
  107. #Region " Methods "
  108.  
  109.             ''' <summary>
  110.             ''' Retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars.
  111.             ''' A window device context permits painting anywhere in a window,
  112.             ''' because the origin of the device context is the upper-left corner of the window instead of the client area.
  113.             ''' GetWindowDC assigns default attributes to the window device context each time it retrieves the device context.
  114.             ''' Previous attributes are lost.
  115.             ''' MSDN Documentation: http://msdn.microsoft.com/es-es/library/windows/desktop/dd144947%28v=vs.85%29.aspx
  116.             ''' </summary>
  117.             ''' <param name="hWnd">
  118.             ''' A handle to the window with a device context that is to be retrieved.
  119.             ''' If this value is NULL, GetWindowDC retrieves the device context for the entire screen.
  120.             ''' If this parameter is NULL, GetWindowDC retrieves the device context for the primary display monitor.
  121.             ''' </param>
  122.             ''' <returns>
  123.             ''' If the function succeeds, the return value is a handle to a device context for the specified window.
  124.             ''' If the function fails, the return value is <see cref="IntPtr.Zero"/>, indicating an error or an invalid hWnd parameter.
  125.             ''' </returns>
  126.             <DllImport("User32.dll")>
  127.             Friend Shared Function GetWindowDC(
  128.                    ByVal hWnd As IntPtr
  129.             ) As IntPtr
  130.             End Function
  131.  
  132.             ''' <summary>
  133.             ''' The ReleaseDC function releases a device context (DC), freeing it for use by other applications.
  134.             ''' The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs.
  135.             ''' It has no effect on class or private DCs.
  136.             ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162920%28v=vs.85%29.aspx
  137.             ''' </summary>
  138.             ''' <param name="hWnd">A handle to the window whose DC is to be released.</param>
  139.             ''' <param name="hDC">A handle to the DC to be released.</param>
  140.             ''' <returns><c>true</c> if the DC was released, <c>false</c> otherwise.</returns>
  141.             <DllImport("user32.dll")>
  142.             Friend Shared Function ReleaseDC(
  143.                    ByVal hWnd As IntPtr,
  144.                    ByVal hDC As IntPtr
  145.             ) As <MarshalAs(UnmanagedType.Bool)> Boolean
  146.             End Function
  147.  
  148.             ''' <summary>
  149.             ''' Creates a rectangular region.
  150.             ''' </summary>
  151.             ''' <param name="lpRect">
  152.             ''' Pointer to a <see cref="Rect"/> structure that contains the coordinates of the upper-left
  153.             ''' and lower-right corners of the rectangle that defines the region in logical units.
  154.             ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd183515%28v=vs.85%29.aspx
  155.             ''' </param>
  156.             ''' <returns>
  157.             ''' If the function succeeds, the return value is the handle to the region.
  158.             ''' If the function fails, the return value is <see cref="IntPtr.Zero"/>.
  159.             ''' </returns>
  160.             <DllImport("gdi32.dll")>
  161.             Friend Shared Function CreateRectRgnIndirect(
  162.                    ByRef lpRect As Rect
  163.             ) As IntPtr
  164.             End Function
  165. #End Region
  166.  
  167. #Region " Structures "
  168.  
  169.             ''' <summary>
  170.             ''' Defines the coordinates of the upper-left and lower-right corners of a rectangle.
  171.             ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162897%28v=vs.85%29.aspx
  172.             ''' </summary>
  173.             <StructLayout(LayoutKind.Sequential)>
  174.             Friend Structure Rect
  175.  
  176.                 ''' <summary>
  177.                 ''' The x-coordinate of the upper-left corner of the rectangle.
  178.                 ''' </summary>
  179.                 Public Left As Integer
  180.  
  181.                 ''' <summary>
  182.                 ''' The y-coordinate of the upper-left corner of the rectangle.
  183.                 ''' </summary>
  184.                 Public Top As Integer
  185.  
  186.                 ''' <summary>
  187.                 ''' The x-coordinate of the lower-right corner of the rectangle.
  188.                 ''' </summary>
  189.                 Public Right As Integer
  190.  
  191.                 ''' <summary>
  192.                 ''' The y-coordinate of the lower-right corner of the rectangle.
  193.                 ''' </summary>
  194.                 Public Bottom As Integer
  195.  
  196.             End Structure
  197.  
  198. #End Region
  199.  
  200.         End Class
  201.  
  202. #End Region
  203.  
  204. #Region " Properties "
  205.  
  206.         ''' <summary>
  207.         ''' Gets the enabled state's <see cref="T:StateLayout"/>.
  208.         ''' </summary>
  209.         ''' <value>The enabled state's <see cref="T:StateLayout"/>.</value>
  210.         <Category("Appearance")>
  211.         <Description("Enabled state.")>
  212.         <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
  213.         Public ReadOnly Property StateEnabled() As StateLayout
  214.             Get
  215.                 Return Me.stateEnabled1
  216.             End Get
  217.         End Property
  218.         ''' <summary>
  219.         ''' The enabled state's <see cref="T:StateLayout"/>.
  220.         ''' </summary>
  221.         Private ReadOnly stateEnabled1 As StateLayout
  222.  
  223.         ''' <summary>
  224.         ''' Gets the disabled state's <see cref="T:StateLayout"/>.
  225.         ''' </summary>
  226.         ''' <value>The disabled state's <see cref="T:StateLayout"/>.</value>
  227.         <Category("Appearance")>
  228.         <Description("Disabled state.")>
  229.         <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
  230.         Public ReadOnly Property StateDisabled() As StateLayout
  231.             Get
  232.                 Return Me.stateDisabled1
  233.             End Get
  234.         End Property
  235.         ''' <summary>
  236.         ''' The disabled state's <see cref="T:StateLayout"/>.
  237.         ''' </summary>
  238.         Private ReadOnly stateDisabled1 As StateLayout
  239.  
  240.         ''' <summary>
  241.         ''' Gets the readonly state's <see cref="T:StateLayout"/>.
  242.         ''' </summary>
  243.         ''' <value>The readonly state's <see cref="T:StateLayout"/>.</value>
  244.         <Category("Appearance")>
  245.         <Description("ReadOnly state.")>
  246.         <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
  247.         Public ReadOnly Property StateReadOnly() As StateLayout
  248.             Get
  249.                 Return Me.stateReadOnly1
  250.             End Get
  251.         End Property
  252.         ''' <summary>
  253.         ''' The readonly state's <see cref="T:StateLayout"/>.
  254.         ''' </summary>
  255.         Private ReadOnly stateReadOnly1 As StateLayout
  256.  
  257.         ''' <summary>
  258.         ''' Gets or sets a value indicating whether the Listbox is in ReadOnly mode.
  259.         ''' </summary>
  260.         <Category("Behavior")>
  261.         <Description("When enabling ReadOnly mode, the control is not selectable.")>
  262.         Public Property [ReadOnly]() As Boolean
  263.             Get
  264.                 Return Me.readOnly1
  265.             End Get
  266.             Set(ByVal value As Boolean)
  267.                 If Not Me.readOnly1 = value Then
  268.                     Me.readOnly1 = value
  269.                     Me.NotifyStateChanged(PropertyName.State)
  270.                 End If
  271.             End Set
  272.         End Property
  273.         ''' <summary>
  274.         ''' A value indicating whether the Listbox is in ReadOnly mode.
  275.         ''' </summary>
  276.         Private readOnly1 As Boolean
  277.  
  278.         ''' <summary>
  279.         ''' Gets or sets the cursor that is displayed when the mouse pointer is over the control.
  280.         ''' </summary>
  281.         ''' <value>The cursor that is displayed when the mouse pointer is over the control.</value>
  282.         ''' <PermissionSet>
  283.         '''   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  284.         '''   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  285.         '''   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
  286.         '''   <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  287.         ''' </PermissionSet>
  288.         <Category("Appearance")>
  289.         <Description("The cursor that appears when the pointer moves over the control.")>
  290.         <Browsable(False)>
  291.         <EditorBrowsableAttribute(EditorBrowsableState.Never)>
  292.         <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
  293.         Public Overrides Property Cursor As Cursor = Cursors.Default
  294.  
  295.         ''' <summary>
  296.         ''' Gets or sets the drawing mode for the control.
  297.         ''' </summary>
  298.         ''' <value>The drawing mode for the control.</value>
  299.         ''' <PermissionSet>
  300.         '''   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  301.         '''   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  302.         '''   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
  303.         '''   <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  304.         ''' </PermissionSet>
  305.         <Category("Behavior")>
  306.         <Description("Controls the listbox painting.")>
  307.         <Browsable(False)>
  308.         <EditorBrowsableAttribute(EditorBrowsableState.Never)>
  309.         <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
  310.         Public Overrides Property DrawMode As DrawMode
  311.             Get
  312.                 Return Windows.Forms.DrawMode.OwnerDrawVariable
  313.             End Get
  314.             Set(ByVal value As DrawMode)
  315.                 Exit Property
  316.             End Set
  317.         End Property
  318.  
  319.         ''' <summary>
  320.         ''' Gets or sets the height of an item in the <see cref="T:ElektroListBox"/>.
  321.         ''' </summary>
  322.         ''' <value>The height of an item in the <see cref="T:ElektroListBox"/>..</value>
  323.         ''' <PermissionSet>
  324.         '''   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  325.         '''   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  326.         '''   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
  327.         '''   <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  328.         ''' </PermissionSet>    
  329.         <Category("Appearance")>
  330.         <Description("The height of an item.")>
  331.         <Browsable(True)>
  332.         <EditorBrowsableAttribute(EditorBrowsableState.Always)>
  333.         <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  334.         Public Overrides Property ItemHeight As Integer
  335.             Get
  336.                 Return MyBase.ItemHeight
  337.             End Get
  338.             Set(ByVal value As Integer)
  339.                 MyBase.ItemHeight = value
  340.                 MyBase.RefreshItems()
  341.             End Set
  342.         End Property
  343.  
  344.         ''' <summary>
  345.         ''' Gets the text format <see cref="T:StringFormatLayout"/>.
  346.         ''' </summary>
  347.         ''' <value>The text format <see cref="T:StringFormatLayout"/>.</value>
  348.         <Category("Appearance")>
  349.         <Description("The text formatting.")>
  350.         <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
  351.         public ReadOnly Property TextFormat As StringFormatLayout
  352.             Get
  353.                 Return Me.textFormat1
  354.             End Get
  355.         End Property
  356.         ''' <summary>
  357.         ''' The text format <see cref="T:StringFormatLayout"/>.
  358.         ''' </summary>
  359.         Private ReadOnly textFormat1 As StringFormatLayout
  360.  
  361. #End Region
  362.  
  363. #Region " Constructors "
  364.  
  365.         ''' <summary>
  366.         ''' Initializes a new instance of the <see cref="T:ElektroListBox"/> class.
  367.         ''' </summary>
  368.         Public Sub New()
  369.  
  370.             MyBase.DoubleBuffered = True
  371.             MyBase.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
  372.             MyBase.SetStyle(ControlStyles.SupportsTransparentBackColor, False)
  373.  
  374.             Me.stateDisabled1 = New StateLayout(Me)
  375.             Me.stateEnabled1 = New StateLayout(Me)
  376.             Me.stateReadOnly1 = New StateLayout(Me)
  377.             Me.textFormat1 = New StringFormatLayout(Me)
  378.  
  379.         End Sub
  380.  
  381. #End Region
  382.  
  383. #Region " Types "
  384.  
  385. #Region " StateLayout "
  386.  
  387.         ''' <summary>
  388.         ''' Describes an state layout.
  389.         ''' </summary>
  390.         <ToolboxItem(False)>
  391.         Public NotInheritable Class StateLayout : Inherits Component
  392.  
  393. #Region " Properties "
  394.  
  395.             ''' <summary>
  396.             ''' Gets the <see cref="T:ElektroListBox"/>.
  397.             ''' </summary>
  398.             ''' <value>The <see cref="T:ElektroListBox"/>.</value>
  399.             Protected Property ListBox() As ElektroListBox
  400.  
  401.             ''' <summary>
  402.             ''' Gets the foreground layout.
  403.             ''' </summary>
  404.             ''' <value>The foreground layout.</value>
  405.             <Category("Appearance")>
  406.             <Description("The item foreground.")>
  407.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
  408.             Public ReadOnly Property Items As ItemLayout
  409.                 Get
  410.                     Return Me.items1
  411.                 End Get
  412.             End Property
  413.             ''' <summary>
  414.             ''' The foreground layout.
  415.             ''' </summary>
  416.             Private ReadOnly items1 As ItemLayout
  417.  
  418.             ''' <summary>
  419.             ''' Gets the cursor that appears when the pointer moves over the control.
  420.             ''' </summary>
  421.             ''' <value>The cursor that appears when the pointer moves over the control.</value>
  422.             <Category("Appearance")>
  423.             <Description("The cursor that appears when the pointer moves over the control.")>
  424.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  425.             Public Property Cursor As Cursor
  426.                 Get
  427.                     Return Me.cursor1
  428.                 End Get
  429.                 Set(ByVal value As Cursor)
  430.                     Me.cursor1 = value
  431.                     Me.ListBox.NotifyStateChanged(PropertyName.Cursor)
  432.                 End Set
  433.             End Property
  434.             ''' <summary>
  435.             ''' The cursor that appears when the pointer moves over the control.
  436.             ''' </summary>
  437.             Private cursor1 As Cursor = Cursors.Default
  438.  
  439.             ''' <summary>
  440.             ''' Gets or sets the border color.
  441.             ''' </summary>
  442.             ''' <value>The border color.</value>
  443.             <Category("Appearance")>
  444.             Public Property BorderColor() As Color
  445.                 Get
  446.                     Return borderColor1
  447.                 End Get
  448.                 Set(ByVal value As Color)
  449.                     Me.borderColor1 = value
  450.                     Me.ListBox.NotifyStateChanged(PropertyName.BorderColor)
  451.                 End Set
  452.             End Property
  453.             ''' <summary>
  454.             ''' The border color.
  455.             ''' </summary>
  456.             Private borderColor1 As Color = SystemColors.ControlDark
  457.  
  458.             ''' <summary>
  459.             ''' Gets the foreground layout.
  460.             ''' </summary>
  461.             ''' <value>The foreground layout.</value>
  462.             <Category("Appearance")>
  463.             <Description("The item foreground.")>
  464.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
  465.             Public ReadOnly Property Grid As GridLayout
  466.                 Get
  467.                     Return Me.grid1
  468.                 End Get
  469.             End Property
  470.             ''' <summary>
  471.             ''' The foreground layout.
  472.             ''' </summary>
  473.             Private ReadOnly grid1 As GridLayout
  474.  
  475. #End Region
  476.  
  477. #Region " Constructors "
  478.  
  479.             ''' <summary>
  480.             ''' Initializes a new instance of the <see cref="T:StateLayout"/> class.
  481.             ''' </summary>
  482.             ''' <param name="listBox">The <see cref="T:ElektroListBox"/>.</param>
  483.             Public Sub New(ByVal listBox As ElektroListBox)
  484.  
  485.                 Me.ListBox = listBox
  486.                 Me.items1 = New ItemLayout(ListBox)
  487.                 Me.grid1 = New GridLayout(ListBox)
  488.  
  489.             End Sub
  490.  
  491. #End Region
  492.  
  493. #Region " Hidden Members "
  494.  
  495.             ''' <summary>
  496.             ''' Retrieves the current lifetime service object that controls the lifetime policy for this instance.
  497.             ''' </summary>
  498.             <EditorBrowsable(EditorBrowsableState.Never)>
  499.             Public Shadows Function GetLifeTimeService() As Object
  500.                 Return MyBase.GetLifetimeService
  501.             End Function
  502.  
  503.             ''' <summary>
  504.             ''' Obtains a lifetime service object to control the lifetime policy for this instance.
  505.             ''' </summary>
  506.             <EditorBrowsable(EditorBrowsableState.Never)>
  507.             Public Shadows Function InitializeLifeTimeService() As Object
  508.                 Return MyBase.InitializeLifetimeService
  509.             End Function
  510.  
  511.             ''' <summary>
  512.             ''' Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
  513.             ''' </summary>
  514.             <EditorBrowsable(EditorBrowsableState.Never)>
  515.             Public Shadows Function CreateObjRef(requestedType As Type) As System.Runtime.Remoting.ObjRef
  516.                 Return MyBase.CreateObjRef(requestedType)
  517.             End Function
  518.             ''' <summary>
  519.             ''' Serves as a hash function for a particular type.
  520.             ''' </summary>
  521.             <EditorBrowsable(EditorBrowsableState.Never)>
  522.             Public Shadows Function GetHashCode() As Integer
  523.                 Return MyBase.GetHashCode
  524.             End Function
  525.             ''' <summary>
  526.             ''' Determines whether the specified System.Object instances are considered equal.
  527.             ''' </summary>
  528.             <EditorBrowsable(EditorBrowsableState.Never)>
  529.             Public Shadows Function Equals(ByVal obj As Object) As Boolean
  530.                 Return MyBase.Equals(obj)
  531.             End Function
  532.  
  533.             ''' <summary>
  534.             ''' Determines whether the specified System.Object instances are the same instance.
  535.             ''' </summary>
  536.             <EditorBrowsable(EditorBrowsableState.Never)>
  537.             Private Shadows Sub ReferenceEquals()
  538.             End Sub
  539.  
  540.             ''' <summary>
  541.             ''' Returns a String that represents the current object.
  542.             ''' </summary>
  543.             <EditorBrowsable(EditorBrowsableState.Never)>
  544.             Public Shadows Function ToString() As String
  545.                 Return MyBase.ToString
  546.             End Function
  547.  
  548.             ''' <summary>
  549.             ''' Gets the System.Type of the current instance.
  550.             ''' </summary>
  551.             ''' <returns>The exact runtime type of the current instance.</returns>
  552.             <EditorBrowsable(EditorBrowsableState.Never)>
  553.             Public Shadows Function [GetType]() As Type
  554.                 Return MyBase.GetType
  555.             End Function
  556.  
  557.             ''' <summary>
  558.             ''' Releases all resources used by the System.ComponentModel.Component.
  559.             ''' </summary>
  560.             <EditorBrowsable(EditorBrowsableState.Never)>
  561.             Public Shadows Sub Dispose()
  562.                 MyBase.Dispose()
  563.             End Sub
  564.  
  565.             ''' <summary>
  566.             ''' Gets or sets the System.ComponentModel.ISite of the System.ComponentModel.Component.
  567.             ''' </summary>
  568.             <EditorBrowsable(EditorBrowsableState.Never)>
  569.             Public Shadows Property Site As ISite = MyBase.site
  570.  
  571.             ''' <summary>
  572.             ''' Gets the System.ComponentModel.IContainer that contains the System.ComponentModel.Component.
  573.             ''' </summary>
  574.             <EditorBrowsable(EditorBrowsableState.Never)>
  575.             Public Shadows Property Container As IContainer = MyBase.container
  576.  
  577. #End Region
  578.  
  579.         End Class
  580.  
  581. #End Region
  582.  
  583. #Region " ItemLayout "
  584.  
  585.         ''' <summary>
  586.         ''' Describes an state layout.
  587.         ''' </summary>
  588.         <ToolboxItem(False)>
  589.         Public NotInheritable Class ItemLayout : Inherits Component
  590.  
  591. #Region " Properties "
  592.  
  593.             ''' <summary>
  594.             ''' Gets the background layout.
  595.             ''' </summary>
  596.             ''' <value>The background layout.</value>
  597.             <Category("Appearance")>
  598.             <Description("The item background.")>
  599.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
  600.             Public ReadOnly Property Background As ItemLayoutColors
  601.                 Get
  602.                     Return Me.background1
  603.                 End Get
  604.             End Property
  605.             ''' <summary>
  606.             ''' The background layout.
  607.             ''' </summary>
  608.             Private ReadOnly background1 As ItemLayoutColors
  609.  
  610.             ''' <summary>
  611.             ''' Gets the foreground layout.
  612.             ''' </summary>
  613.             ''' <value>The foreground layout.</value>
  614.             <Category("Appearance")>
  615.             <Description("The item foreground.")>
  616.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
  617.             Public ReadOnly Property Foreground As ItemLayoutColors
  618.                 Get
  619.                     Return Me.foreground1
  620.                 End Get
  621.             End Property
  622.             ''' <summary>
  623.             ''' The foreground layout.
  624.             ''' </summary>
  625.             Private ReadOnly foreground1 As ItemLayoutColors
  626.  
  627. #End Region
  628.  
  629. #Region " Constructors "
  630.  
  631.             ''' <summary>
  632.             ''' Initializes a new instance of the <see cref="T:ItemLayout"/> class.
  633.             ''' </summary>
  634.             ''' <param name="listBox">The <see cref="T:ElektroListBox"/>.</param>
  635.             ''' <exception cref="System.ArgumentNullException">layout</exception>
  636.             Public Sub New(ByVal listBox As ElektroListBox)
  637.  
  638.  
  639.                 Me.background1 = New ItemLayoutColors(listBox) With
  640.                                  {
  641.                                      .Selected = SystemColors.Highlight,
  642.                                      .Unselected = SystemColors.Window,
  643.                                      .UnselectedAlternate = SystemColors.Window
  644.                                  }
  645.  
  646.                 Me.foreground1 = New ItemLayoutColors(listBox) With
  647.                                  {
  648.                                      .Selected = SystemColors.HighlightText,
  649.                                      .Unselected = SystemColors.WindowText,
  650.                                      .UnselectedAlternate = SystemColors.WindowText
  651.                                  }
  652.  
  653.             End Sub
  654.  
  655. #End Region
  656.  
  657. #Region " Hidden Members "
  658.  
  659.             ''' <summary>
  660.             ''' Retrieves the current lifetime service object that controls the lifetime policy for this instance.
  661.             ''' </summary>
  662.             <EditorBrowsable(EditorBrowsableState.Never)>
  663.             Public Shadows Function GetLifeTimeService() As Object
  664.                 Return MyBase.GetLifetimeService
  665.             End Function
  666.  
  667.             ''' <summary>
  668.             ''' Obtains a lifetime service object to control the lifetime policy for this instance.
  669.             ''' </summary>
  670.             <EditorBrowsable(EditorBrowsableState.Never)>
  671.             Public Shadows Function InitializeLifeTimeService() As Object
  672.                 Return MyBase.InitializeLifetimeService
  673.             End Function
  674.  
  675.             ''' <summary>
  676.             ''' Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
  677.             ''' </summary>
  678.             <EditorBrowsable(EditorBrowsableState.Never)>
  679.             Public Shadows Function CreateObjRef(requestedType As Type) As System.Runtime.Remoting.ObjRef
  680.                 Return MyBase.CreateObjRef(requestedType)
  681.             End Function
  682.             ''' <summary>
  683.             ''' Serves as a hash function for a particular type.
  684.             ''' </summary>
  685.             <EditorBrowsable(EditorBrowsableState.Never)>
  686.             Public Shadows Function GetHashCode() As Integer
  687.                 Return MyBase.GetHashCode
  688.             End Function
  689.             ''' <summary>
  690.             ''' Determines whether the specified System.Object instances are considered equal.
  691.             ''' </summary>
  692.             <EditorBrowsable(EditorBrowsableState.Never)>
  693.             Public Shadows Function Equals(ByVal obj As Object) As Boolean
  694.                 Return MyBase.Equals(obj)
  695.             End Function
  696.  
  697.             ''' <summary>
  698.             ''' Determines whether the specified System.Object instances are the same instance.
  699.             ''' </summary>
  700.             <EditorBrowsable(EditorBrowsableState.Never)>
  701.             Private Shadows Sub ReferenceEquals()
  702.             End Sub
  703.  
  704.             ''' <summary>
  705.             ''' Returns a String that represents the current object.
  706.             ''' </summary>
  707.             <EditorBrowsable(EditorBrowsableState.Never)>
  708.             Public Shadows Function ToString() As String
  709.                 Return MyBase.ToString
  710.             End Function
  711.  
  712.             ''' <summary>
  713.             ''' Gets the System.Type of the current instance.
  714.             ''' </summary>
  715.             ''' <returns>The exact runtime type of the current instance.</returns>
  716.             <EditorBrowsable(EditorBrowsableState.Never)>
  717.             Public Shadows Function [GetType]() As Type
  718.                 Return MyBase.GetType
  719.             End Function
  720.  
  721.             ''' <summary>
  722.             ''' Releases all resources used by the System.ComponentModel.Component.
  723.             ''' </summary>
  724.             <EditorBrowsable(EditorBrowsableState.Never)>
  725.             Public Shadows Sub Dispose()
  726.                 MyBase.Dispose()
  727.             End Sub
  728.  
  729.             ''' <summary>
  730.             ''' Gets or sets the System.ComponentModel.ISite of the System.ComponentModel.Component.
  731.             ''' </summary>
  732.             <EditorBrowsable(EditorBrowsableState.Never)>
  733.             Public Shadows Property Site As ISite = MyBase.site
  734.  
  735.             ''' <summary>
  736.             ''' Gets the System.ComponentModel.IContainer that contains the System.ComponentModel.Component.
  737.             ''' </summary>
  738.             <EditorBrowsable(EditorBrowsableState.Never)>
  739.             Public Shadows Property Container As IContainer = MyBase.container
  740.  
  741. #End Region
  742.  
  743.         End Class
  744.  
  745. #End Region
  746.  
  747. #Region " ItemLayoutColors "
  748.  
  749.         ''' <summary>
  750.         ''' Describes an item layout colors.
  751.         ''' </summary>
  752.         <ToolboxItem(False)>
  753.         Public NotInheritable Class ItemLayoutColors : Inherits Component
  754.  
  755. #Region " Properties "
  756.  
  757.             ''' <summary>
  758.             ''' Gets the <see cref="T:ElektroListBox"/>.
  759.             ''' </summary>
  760.             ''' <value>The <see cref="T:ElektroListBox"/>.</value>
  761.             Protected Property ListBox() As ElektroListBox
  762.  
  763.             ''' <summary>
  764.             ''' Gets or sets the selected color.
  765.             ''' </summary>
  766.             ''' <value>The selected color.</value>
  767.             <Category("Appearance")>
  768.             <Description("The background color for a selected item.")>
  769.             Public Property Selected() As Color
  770.                 Get
  771.                     Return Me.selected1
  772.                 End Get
  773.                 Set(ByVal value As Color)
  774.                     If (value <> Me.selected1) Then
  775.                         Me.selected1 = value
  776.                         Me.ListBox.NotifyStateChanged(PropertyName.Selected)
  777.                     End If
  778.                 End Set
  779.             End Property
  780.             ''' <summary>
  781.             ''' The selected color.
  782.             ''' </summary>
  783.             Private selected1 As Color
  784.  
  785.             ''' <summary>
  786.             ''' Gets or sets the unselected color.
  787.             ''' </summary>
  788.             ''' <value>The unselected color.</value>
  789.             <Category("Appearance")>
  790.             <Description("The background color for a non selected item.")>
  791.             Public Property Unselected() As Color
  792.                 Get
  793.                     Return Me.unselected1
  794.                 End Get
  795.                 Set(ByVal value As Color)
  796.                     If (value <> Me.unselected1) Then
  797.                         Me.unselected1 = value
  798.                         Me.ListBox.NotifyStateChanged(PropertyName.Unselected)
  799.                     End If
  800.                 End Set
  801.             End Property
  802.             ''' <summary>
  803.             ''' The unselected color.
  804.             ''' </summary>
  805.             Private unselected1 As Color
  806.  
  807.             ''' <summary>
  808.             ''' Gets or sets the alternate unselected color.
  809.             ''' </summary>
  810.             ''' <value>The alternate unselected color.</value>
  811.             <Category("Appearance")>
  812.             <Description("The alternate background color for a non selected item.")>
  813.             Public Property UnselectedAlternate() As Color
  814.                 Get
  815.                     Return Me.unselectedAlternate1
  816.                 End Get
  817.                 Set(ByVal value As Color)
  818.                     If (value <> Me.unselectedAlternate1) Then
  819.                         Me.unselectedAlternate1 = value
  820.                         Me.ListBox.NotifyStateChanged(PropertyName.UnselectedAlternate)
  821.                     End If
  822.                 End Set
  823.             End Property
  824.             ''' <summary>
  825.             ''' The alternate unselected color.
  826.             ''' </summary>
  827.             Private unselectedAlternate1 As Color
  828.  
  829. #End Region
  830.  
  831. #Region " Constructors "
  832.  
  833.             ''' <summary>
  834.             ''' Initializes a new instance of the <see cref="T:ItemLayoutColors"/> class.
  835.             ''' </summary>
  836.             ''' <param name="listBox">The <see cref="T:ElektroListBox"/>.</param>
  837.             ''' <exception cref="System.ArgumentNullException">layout</exception>
  838.             Public Sub New(ByVal listBox As ElektroListBox)
  839.  
  840.                 Me.ListBox = listBox
  841.  
  842.             End Sub
  843.  
  844. #End Region
  845.  
  846. #Region " Hidden Members "
  847.  
  848.             ''' <summary>
  849.             ''' Retrieves the current lifetime service object that controls the lifetime policy for this instance.
  850.             ''' </summary>
  851.             <EditorBrowsable(EditorBrowsableState.Never)>
  852.             Public Shadows Function GetLifeTimeService() As Object
  853.                 Return MyBase.GetLifetimeService
  854.             End Function
  855.  
  856.             ''' <summary>
  857.             ''' Obtains a lifetime service object to control the lifetime policy for this instance.
  858.             ''' </summary>
  859.             <EditorBrowsable(EditorBrowsableState.Never)>
  860.             Public Shadows Function InitializeLifeTimeService() As Object
  861.                 Return MyBase.InitializeLifetimeService
  862.             End Function
  863.  
  864.             ''' <summary>
  865.             ''' Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
  866.             ''' </summary>
  867.             <EditorBrowsable(EditorBrowsableState.Never)>
  868.             Public Shadows Function CreateObjRef(requestedType As Type) As System.Runtime.Remoting.ObjRef
  869.                 Return MyBase.CreateObjRef(requestedType)
  870.             End Function
  871.             ''' <summary>
  872.             ''' Serves as a hash function for a particular type.
  873.             ''' </summary>
  874.             <EditorBrowsable(EditorBrowsableState.Never)>
  875.             Public Shadows Function GetHashCode() As Integer
  876.                 Return MyBase.GetHashCode
  877.             End Function
  878.             ''' <summary>
  879.             ''' Determines whether the specified System.Object instances are considered equal.
  880.             ''' </summary>
  881.             <EditorBrowsable(EditorBrowsableState.Never)>
  882.             Public Shadows Function Equals(ByVal obj As Object) As Boolean
  883.                 Return MyBase.Equals(obj)
  884.             End Function
  885.  
  886.             ''' <summary>
  887.             ''' Determines whether the specified System.Object instances are the same instance.
  888.             ''' </summary>
  889.             <EditorBrowsable(EditorBrowsableState.Never)>
  890.             Private Shadows Sub ReferenceEquals()
  891.             End Sub
  892.  
  893.             ''' <summary>
  894.             ''' Returns a String that represents the current object.
  895.             ''' </summary>
  896.             <EditorBrowsable(EditorBrowsableState.Never)>
  897.             Public Shadows Function ToString() As String
  898.                 Return MyBase.ToString
  899.             End Function
  900.  
  901.             ''' <summary>
  902.             ''' Gets the System.Type of the current instance.
  903.             ''' </summary>
  904.             ''' <returns>The exact runtime type of the current instance.</returns>
  905.             <EditorBrowsable(EditorBrowsableState.Never)>
  906.             Public Shadows Function [GetType]() As Type
  907.                 Return MyBase.GetType
  908.             End Function
  909.  
  910.             ''' <summary>
  911.             ''' Releases all resources used by the System.ComponentModel.Component.
  912.             ''' </summary>
  913.             <EditorBrowsable(EditorBrowsableState.Never)>
  914.             Public Shadows Sub Dispose()
  915.                 MyBase.Dispose()
  916.             End Sub
  917.  
  918.             ''' <summary>
  919.             ''' Gets or sets the System.ComponentModel.ISite of the System.ComponentModel.Component.
  920.             ''' </summary>
  921.             <EditorBrowsable(EditorBrowsableState.Never)>
  922.             Public Shadows Property Site As ISite = MyBase.site
  923.  
  924.             ''' <summary>
  925.             ''' Gets the System.ComponentModel.IContainer that contains the System.ComponentModel.Component.
  926.             ''' </summary>
  927.             <EditorBrowsable(EditorBrowsableState.Never)>
  928.             Public Shadows Property Container As IContainer = MyBase.container
  929.  
  930. #End Region
  931.  
  932.         End Class
  933.  
  934. #End Region
  935.  
  936. #Region " StringFormatLayout "
  937.  
  938.         ''' <summary>
  939.         ''' Describes an StringFormat layout.
  940.         ''' </summary>
  941.         <ToolboxItem(False)>
  942.         Public NotInheritable Class StringFormatLayout : Inherits Component
  943.  
  944. #Region " Properties "
  945.  
  946.             ''' <summary>
  947.             ''' Gets the <see cref="T:ElektroListBox"/>.
  948.             ''' </summary>
  949.             ''' <value>The <see cref="T:ElektroListBox"/>.</value>
  950.             Protected Property ListBox() As ElektroListBox
  951.  
  952.             ''' <summary>
  953.             ''' Gets or sets the alignment of a text string relative to its layout rectangle.
  954.             ''' </summary>
  955.             ''' <value>The alignment of a text string relative to its layout rectangle.</value>
  956.             <Category("Appearance")>
  957.             <Description("The alignment of a text string relative to its layout rectangle.")>
  958.             <Browsable(True)>
  959.             <EditorBrowsable(EditorBrowsableState.Always)>
  960.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  961.             Public Property Alignment As StringAlignment
  962.                 Get
  963.                     Return Me.alignment1
  964.                 End Get
  965.                 Set(ByVal value As StringAlignment)
  966.                     Me.alignment1 = value
  967.                     Me.ListBox.NotifyStateChanged(PropertyName.StringFormat)
  968.                 End Set
  969.             End Property
  970.             ''' <summary>
  971.             ''' The alignment of a text string relative to its layout rectangle.
  972.             ''' </summary>
  973.             Private alignment1 As StringAlignment = StringAlignment.Near
  974.  
  975.             ''' <summary>
  976.             ''' Gets or sets the alignment of a text string relative to its layout rectangle.
  977.             ''' </summary>
  978.             ''' <value>The alignment of a text string relative to its layout rectangle.</value>
  979.             <Category("Appearance")>
  980.             <Description("The alignment of a text string relative to its layout rectangle.")>
  981.             <Browsable(True)>
  982.             <EditorBrowsable(EditorBrowsableState.Always)>
  983.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  984.             Public Property LineAlignment As StringAlignment
  985.                 Get
  986.                     Return Me.lineAlignment1
  987.                 End Get
  988.                 Set(ByVal value As StringAlignment)
  989.                     Me.lineAlignment1 = value
  990.                     Me.ListBox.NotifyStateChanged(PropertyName.StringFormat)
  991.                 End Set
  992.             End Property
  993.             ''' <summary>
  994.             ''' The alignment of a text string relative to its layout rectangle.
  995.             ''' </summary>
  996.             Private lineAlignment1 As StringAlignment = StringAlignment.Center
  997.  
  998.             ''' <summary>
  999.             ''' Gets or sets a value indicating how to trim characters from a string that does not completely fit into a layout shape.
  1000.             ''' </summary>
  1001.             ''' <value>A value indicating how to trim characters from a string that does not completely fit into a layout shape.</value>
  1002.             <Category("Appearance")>
  1003.             <Description("Specifies how to trim characters from a string that does not completely fit into a layout shape.")>
  1004.             <Browsable(True)>
  1005.             <EditorBrowsable(EditorBrowsableState.Always)>
  1006.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  1007.             Public Property Trimming As StringTrimming
  1008.                 Get
  1009.                     Return Me.trimming1
  1010.                 End Get
  1011.                 Set(ByVal value As StringTrimming)
  1012.                     Me.trimming1 = value
  1013.                     Me.ListBox.NotifyStateChanged(PropertyName.StringFormat)
  1014.                 End Set
  1015.             End Property
  1016.             ''' <summary>
  1017.             ''' A value indicating how to trim characters from a string that does not completely fit into a layout shape.
  1018.             ''' </summary>
  1019.             Private trimming1 As StringTrimming = StringTrimming.None
  1020.  
  1021.             ''' <summary>
  1022.             ''' Gets or sets the display and layout information for text strings.
  1023.             ''' </summary>
  1024.             ''' <value>The display and layout information for text strings.</value>
  1025.             <Category("Appearance")>
  1026.             <Description("Specifies the display and layout information for text strings.")>
  1027.             <Browsable(True)>
  1028.             <EditorBrowsable(EditorBrowsableState.Always)>
  1029.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  1030.             Public Property FormatFlags As StringFormatFlags
  1031.                 Get
  1032.                     Return Me.formatFlags1
  1033.                 End Get
  1034.                 Set(ByVal value As StringFormatFlags)
  1035.                     Me.formatFlags1 = value
  1036.                     Me.ListBox.NotifyStateChanged(PropertyName.StringFormat)
  1037.                 End Set
  1038.             End Property
  1039.             ''' <summary>
  1040.             ''' The display and layout information for text strings
  1041.             ''' </summary>
  1042.             Private formatFlags1 As StringFormatFlags = StringFormatFlags.NoWrap
  1043.  
  1044. #End Region
  1045.  
  1046. #Region " Constructors "
  1047.  
  1048.             ''' <summary>
  1049.             ''' Initializes a new instance of the <see cref="T:StateLayout"/> class.
  1050.             ''' </summary>
  1051.             ''' <param name="listBox">The <see cref="T:ElektroListBox"/>.</param>
  1052.             Public Sub New(ByVal listBox As ElektroListBox)
  1053.  
  1054.                 Me.ListBox = listBox
  1055.  
  1056.             End Sub
  1057.  
  1058. #End Region
  1059.  
  1060. #Region " Hidden Members "
  1061.  
  1062.             ''' <summary>
  1063.             ''' Retrieves the current lifetime service object that controls the lifetime policy for this instance.
  1064.             ''' </summary>
  1065.             <EditorBrowsable(EditorBrowsableState.Never)>
  1066.             Public Shadows Function GetLifeTimeService() As Object
  1067.                 Return MyBase.GetLifetimeService
  1068.             End Function
  1069.  
  1070.             ''' <summary>
  1071.             ''' Obtains a lifetime service object to control the lifetime policy for this instance.
  1072.             ''' </summary>
  1073.             <EditorBrowsable(EditorBrowsableState.Never)>
  1074.             Public Shadows Function InitializeLifeTimeService() As Object
  1075.                 Return MyBase.InitializeLifetimeService
  1076.             End Function
  1077.  
  1078.             ''' <summary>
  1079.             ''' Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
  1080.             ''' </summary>
  1081.             <EditorBrowsable(EditorBrowsableState.Never)>
  1082.             Public Shadows Function CreateObjRef(requestedType As Type) As System.Runtime.Remoting.ObjRef
  1083.                 Return MyBase.CreateObjRef(requestedType)
  1084.             End Function
  1085.             ''' <summary>
  1086.             ''' Serves as a hash function for a particular type.
  1087.             ''' </summary>
  1088.             <EditorBrowsable(EditorBrowsableState.Never)>
  1089.             Public Shadows Function GetHashCode() As Integer
  1090.                 Return MyBase.GetHashCode
  1091.             End Function
  1092.             ''' <summary>
  1093.             ''' Determines whether the specified System.Object instances are considered equal.
  1094.             ''' </summary>
  1095.             <EditorBrowsable(EditorBrowsableState.Never)>
  1096.             Public Shadows Function Equals(ByVal obj As Object) As Boolean
  1097.                 Return MyBase.Equals(obj)
  1098.             End Function
  1099.  
  1100.             ''' <summary>
  1101.             ''' Determines whether the specified System.Object instances are the same instance.
  1102.             ''' </summary>
  1103.             <EditorBrowsable(EditorBrowsableState.Never)>
  1104.             Private Shadows Sub ReferenceEquals()
  1105.             End Sub
  1106.  
  1107.             ''' <summary>
  1108.             ''' Returns a String that represents the current object.
  1109.             ''' </summary>
  1110.             <EditorBrowsable(EditorBrowsableState.Never)>
  1111.             Public Shadows Function ToString() As String
  1112.                 Return MyBase.ToString
  1113.             End Function
  1114.  
  1115.             ''' <summary>
  1116.             ''' Gets the System.Type of the current instance.
  1117.             ''' </summary>
  1118.             ''' <returns>The exact runtime type of the current instance.</returns>
  1119.             <EditorBrowsable(EditorBrowsableState.Never)>
  1120.             Public Shadows Function [GetType]() As Type
  1121.                 Return MyBase.GetType
  1122.             End Function
  1123.  
  1124.             ''' <summary>
  1125.             ''' Releases all resources used by the System.ComponentModel.Component.
  1126.             ''' </summary>
  1127.             <EditorBrowsable(EditorBrowsableState.Never)>
  1128.             Public Shadows Sub Dispose()
  1129.                 MyBase.Dispose()
  1130.             End Sub
  1131.  
  1132.             ''' <summary>
  1133.             ''' Gets or sets the System.ComponentModel.ISite of the System.ComponentModel.Component.
  1134.             ''' </summary>
  1135.             <EditorBrowsable(EditorBrowsableState.Never)>
  1136.             Public Shadows Property Site As ISite = MyBase.site
  1137.  
  1138.             ''' <summary>
  1139.             ''' Gets the System.ComponentModel.IContainer that contains the System.ComponentModel.Component.
  1140.             ''' </summary>
  1141.             <EditorBrowsable(EditorBrowsableState.Never)>
  1142.             Public Shadows Property Container As IContainer = MyBase.container
  1143.  
  1144. #End Region
  1145.  
  1146.         End Class
  1147.  
  1148. #End Region
  1149.  
  1150. #Region " GridLayout "
  1151.  
  1152.         ''' <summary>
  1153.         ''' Describes a Grid layout.
  1154.         ''' </summary>
  1155.         <ToolboxItem(False)>
  1156.         Public NotInheritable Class GridLayout : Inherits Component
  1157.  
  1158. #Region " Properties "
  1159.  
  1160.             ''' <summary>
  1161.             ''' Gets the <see cref="T:ElektroListBox"/>.
  1162.             ''' </summary>
  1163.             ''' <value>The <see cref="T:ElektroListBox"/>.</value>
  1164.             Protected Property ListBox() As ElektroListBox
  1165.  
  1166.             ''' <summary>
  1167.             ''' Gets or sets a value indicating whether grid lines drawing are enabled to separate items.
  1168.             ''' </summary>
  1169.             ''' <value>A value indicating whether grid lines drawing are enabled to separate items.</value>
  1170.             <Category("Appearance")>
  1171.             <Description("Enable or disable the grid lines.")>
  1172.             <Browsable(True)>
  1173.             <EditorBrowsable(EditorBrowsableState.Always)>
  1174.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  1175.             Public Property Enabled As Boolean
  1176.                 Get
  1177.                     Return Me.enabled1
  1178.                 End Get
  1179.                 Set(ByVal value As Boolean)
  1180.                     Me.enabled1 = value
  1181.                     Me.ListBox.NotifyStateChanged(PropertyName.Grid)
  1182.                 End Set
  1183.             End Property
  1184.             ''' <summary>
  1185.             ''' A value indicating whether grid lines drawing are enabled to separate items.
  1186.             ''' </summary>
  1187.             Private enabled1 As Boolean = False
  1188.  
  1189.             ''' <summary>
  1190.             ''' Gets or sets the grid lines color.
  1191.             ''' </summary>
  1192.             ''' <value>The grid lines color.</value>
  1193.             <Category("Appearance")>
  1194.             <Description("The alignment of a text string relative to its layout rectangle.")>
  1195.             <Browsable(True)>
  1196.             <EditorBrowsable(EditorBrowsableState.Always)>
  1197.             <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
  1198.             Public Property Color As Color
  1199.                 Get
  1200.                     Return Me.color1
  1201.                 End Get
  1202.                 Set(ByVal value As Color)
  1203.                     Me.color1 = value
  1204.                     Me.ListBox.NotifyStateChanged(PropertyName.Grid)
  1205.                 End Set
  1206.             End Property
  1207.             ''' <summary>
  1208.             ''' The grid lines color.
  1209.             ''' </summary>
  1210.             Private color1 As Color = Color.Black
  1211.  
  1212. #End Region
  1213.  
  1214. #Region " Constructors "
  1215.  
  1216.             ''' <summary>
  1217.             ''' Initializes a new instance of the <see cref="T:GridLayout"/> class.
  1218.             ''' </summary>
  1219.             ''' <param name="listBox">The <see cref="T:ElektroListBox"/>.</param>
  1220.             Public Sub New(ByVal listBox As ElektroListBox)
  1221.  
  1222.                 Me.ListBox = listBox
  1223.  
  1224.             End Sub
  1225.  
  1226. #End Region
  1227.  
  1228. #Region " Hidden Members "
  1229.  
  1230.             ''' <summary>
  1231.             ''' Retrieves the current lifetime service object that controls the lifetime policy for this instance.
  1232.             ''' </summary>
  1233.             <EditorBrowsable(EditorBrowsableState.Never)>
  1234.             Public Shadows Function GetLifeTimeService() As Object
  1235.                 Return MyBase.GetLifetimeService
  1236.             End Function
  1237.  
  1238.             ''' <summary>
  1239.             ''' Obtains a lifetime service object to control the lifetime policy for this instance.
  1240.             ''' </summary>
  1241.             <EditorBrowsable(EditorBrowsableState.Never)>
  1242.             Public Shadows Function InitializeLifeTimeService() As Object
  1243.                 Return MyBase.InitializeLifetimeService
  1244.             End Function
  1245.  
  1246.             ''' <summary>
  1247.             ''' Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
  1248.             ''' </summary>
  1249.             <EditorBrowsable(EditorBrowsableState.Never)>
  1250.             Public Shadows Function CreateObjRef(requestedType As Type) As System.Runtime.Remoting.ObjRef
  1251.                 Return MyBase.CreateObjRef(requestedType)
  1252.             End Function
  1253.             ''' <summary>
  1254.             ''' Serves as a hash function for a particular type.
  1255.             ''' </summary>
  1256.             <EditorBrowsable(EditorBrowsableState.Never)>
  1257.             Public Shadows Function GetHashCode() As Integer
  1258.                 Return MyBase.GetHashCode
  1259.             End Function
  1260.             ''' <summary>
  1261.             ''' Determines whether the specified System.Object instances are considered equal.
  1262.             ''' </summary>
  1263.             <EditorBrowsable(EditorBrowsableState.Never)>
  1264.             Public Shadows Function Equals(ByVal obj As Object) As Boolean
  1265.                 Return MyBase.Equals(obj)
  1266.             End Function
  1267.  
  1268.             ''' <summary>
  1269.             ''' Determines whether the specified System.Object instances are the same instance.
  1270.             ''' </summary>
  1271.             <EditorBrowsable(EditorBrowsableState.Never)>
  1272.             Private Shadows Sub ReferenceEquals()
  1273.             End Sub
  1274.  
  1275.             ''' <summary>
  1276.             ''' Returns a String that represents the current object.
  1277.             ''' </summary>
  1278.             <EditorBrowsable(EditorBrowsableState.Never)>
  1279.             Public Shadows Function ToString() As String
  1280.                 Return MyBase.ToString
  1281.             End Function
  1282.  
  1283.             ''' <summary>
  1284.             ''' Gets the System.Type of the current instance.
  1285.             ''' </summary>
  1286.             ''' <returns>The exact runtime type of the current instance.</returns>
  1287.             <EditorBrowsable(EditorBrowsableState.Never)>
  1288.             Public Shadows Function [GetType]() As Type
  1289.                 Return MyBase.GetType
  1290.             End Function
  1291.  
  1292.             ''' <summary>
  1293.             ''' Releases all resources used by the System.ComponentModel.Component.
  1294.             ''' </summary>
  1295.             <EditorBrowsable(EditorBrowsableState.Never)>
  1296.             Public Shadows Sub Dispose()
  1297.                 MyBase.Dispose()
  1298.             End Sub
  1299.  
  1300.             ''' <summary>
  1301.             ''' Gets or sets the System.ComponentModel.ISite of the System.ComponentModel.Component.
  1302.             ''' </summary>
  1303.             <EditorBrowsable(EditorBrowsableState.Never)>
  1304.             Public Shadows Property Site As ISite = MyBase.site
  1305.  
  1306.             ''' <summary>
  1307.             ''' Gets the System.ComponentModel.IContainer that contains the System.ComponentModel.Component.
  1308.             ''' </summary>
  1309.             <EditorBrowsable(EditorBrowsableState.Never)>
  1310.             Public Shadows Property Container As IContainer = MyBase.container
  1311.  
  1312. #End Region
  1313.  
  1314.         End Class
  1315.  
  1316. #End Region
  1317.  
  1318. #End Region
  1319.  
  1320. #Region " Enumerations "
  1321.  
  1322.         ''' <summary>
  1323.         ''' Specifies an <see cref="T:ElektroListBox"/> item state.
  1324.         ''' </summary>
  1325.         Public Enum ItemState As Integer
  1326.  
  1327.             ''' <summary>
  1328.             ''' Selects the listbox Item.
  1329.             ''' </summary>
  1330.             Selected = -&H1 ' True
  1331.  
  1332.             ''' <summary>
  1333.             ''' Unselects the listbox Item.
  1334.             ''' </summary>
  1335.             Unselected = &H0 ' False
  1336.  
  1337.         End Enum
  1338.  
  1339.         ''' <summary>
  1340.         ''' Indicates the <see cref="T:ElektroListBox"/> items to select.
  1341.         ''' </summary>
  1342.         Public Enum ListBoxItems As Integer
  1343.  
  1344.             ''' <summary>
  1345.             ''' Selects all the items.
  1346.             ''' </summary>
  1347.             All = -&H1 ' True
  1348.  
  1349.             ''' <summary>
  1350.             ''' Unselects all the items.
  1351.             ''' </summary>
  1352.             None = &H0 ' False
  1353.  
  1354.         End Enum
  1355.  
  1356.         ''' <summary>
  1357.         ''' Specifies a Windows Message.
  1358.         ''' </summary>
  1359.         Private Enum WindowsMessages As Integer
  1360.  
  1361.             ''' <summary>
  1362.             ''' Posted when the user presses the left mouse button while the cursor is in the client area of a window.
  1363.             ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  1364.             ''' Otherwise, the message is posted to the window that has captured the mouse.
  1365.             ''' MSDN Documentation: http://msdn.microsoft.com/es-es/library/windows/desktop/ms645607%28v=vs.85%29.aspx
  1366.             ''' </summary>
  1367.             WM_LBUTTONDOWN = &H201
  1368.  
  1369.             ''' <summary>
  1370.             ''' Posted to the window with the keyboard focus when a nonsystem key is pressed.
  1371.             ''' A nonsystem key is a key that is pressed when the ALT key is not pressed.
  1372.             ''' MSDN Documentation: http://msdn.microsoft.com/es-es/library/windows/desktop/ms646280%28v=vs.85%29.aspx
  1373.             ''' </summary>
  1374.             WM_KEYDOWN = &H100
  1375.  
  1376.             ' ''' <summary>
  1377.             ' ''' Sent when the system or another application makes a request to paint a portion of an application's window.
  1378.             ' ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd145213%28v=vs.85%29.aspx
  1379.             ' ''' </summary>
  1380.             ' WM_PAINT = &HF
  1381.  
  1382.             ' ''' <summary>
  1383.             ' ''' Sent to a window when its frame must be painted.
  1384.             ' ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd145212%28v=vs.85%29.aspx
  1385.             ' ''' </summary>
  1386.             WM_NCPAINT = &H85
  1387.  
  1388.         End Enum
  1389.  
  1390.         ''' <summary>
  1391.         ''' Specifies a property name of an the <see cref="T:ItemLayout"/>.
  1392.         ''' </summary>
  1393.         Private Enum PropertyName
  1394.  
  1395.             ''' <summary>
  1396.             ''' The selected item's color.
  1397.             ''' </summary>
  1398.             Selected
  1399.  
  1400.             ''' <summary>
  1401.             ''' The unselected item's color.
  1402.             ''' </summary>
  1403.             Unselected
  1404.  
  1405.             ''' <summary>
  1406.             ''' The unselected alternate item's color.
  1407.             ''' </summary>
  1408.             UnselectedAlternate
  1409.  
  1410.             ''' <summary>
  1411.             ''' The control's state (Enabled, Disabled, ReadOnly).
  1412.             ''' </summary>
  1413.             State
  1414.  
  1415.             ''' <summary>
  1416.             ''' The control's cursor.
  1417.             ''' </summary>
  1418.             Cursor
  1419.  
  1420.             ''' <summary>
  1421.             ''' The control's border color.
  1422.             ''' </summary>
  1423.             BorderColor
  1424.  
  1425.             ''' <summary>
  1426.             ''' The string formatting.
  1427.             ''' </summary>
  1428.             StringFormat
  1429.  
  1430.             ''' <summary>
  1431.             ''' The grid lines.
  1432.             ''' </summary>
  1433.             Grid
  1434.  
  1435.         End Enum
  1436.  
  1437. #End Region
  1438.  
  1439. #Region " Events "
  1440.  
  1441. #End Region
  1442.  
  1443. #Region " Public Methods "
  1444.  
  1445.         ''' <summary>
  1446.         ''' Returns a value indicating whether this <see cref="T:ElektroListBox"/> contains duplicated items.
  1447.         ''' </summary>
  1448.         Public Function HasDuplicatedItems() As Boolean
  1449.  
  1450.             Return CBool(Me.Items.Count - Me.Items.Cast(Of String).Distinct().Count)
  1451.  
  1452.         End Function
  1453.  
  1454.         ''' <summary>
  1455.         ''' Removes all duplicated items in this <see cref="T:ElektroListBox"/>.
  1456.         ''' </summary>
  1457.         Public Sub RemoveDuplicatedItems()
  1458.  
  1459.             If Me.HasDuplicatedItems() Then
  1460.  
  1461.                 Dim items As IEnumerable(Of String) = Me.Items.Cast(Of String).Distinct()
  1462.  
  1463.                 Me.Items.Clear()
  1464.                 Me.Items.AddRange(items.ToArray)
  1465.  
  1466.             End If
  1467.  
  1468.         End Sub
  1469.  
  1470.         ''' <summary>
  1471.         ''' Selects or unselects a ListBox Item without jumping at Item position.
  1472.         ''' </summary>
  1473.         ''' <param name="ItemIndex">Indicates the index of the Item to set.</param>
  1474.         ''' <param name="ItemState">Indicates the state for the item.</param>
  1475.         ''' <exception cref="System.ArgumentOutOfRangeException">itemIndex</exception>
  1476.         Public Sub SetSelectedNoJump(ByVal itemIndex As Integer,
  1477.                                      ByVal itemState As ItemState)
  1478.  
  1479.             If (itemIndex > Me.Items.Count) Then
  1480.                 Throw New ArgumentOutOfRangeException("itemIndex")
  1481.             End If
  1482.  
  1483.             Me.SetSelectedNoJump({itemIndex}, itemState)
  1484.  
  1485.         End Sub
  1486.  
  1487.         ''' <summary>
  1488.         ''' Selects or unselects ListBox Items without jumping at Item position.
  1489.         ''' </summary>
  1490.         ''' <param name="ItemIndex">Indicates the index of the Items to set.</param>
  1491.         ''' <param name="ItemState">Indicates the state for the items.</param>
  1492.         ''' <exception cref="System.ArgumentOutOfRangeException">itemIndex</exception>
  1493.         Public Sub SetSelectedNoJump(ByVal itemIndex As IEnumerable(Of Integer),
  1494.                                      ByVal itemState As ItemState)
  1495.  
  1496.             If itemIndex.Count = 0 Then
  1497.                 Exit Sub
  1498.             ElseIf itemIndex.Max > Me.Items.Count Then
  1499.                 Throw New ArgumentOutOfRangeException("itemIndex")
  1500.             End If
  1501.  
  1502.             ' Store the selected item index.
  1503.             Dim i As Integer = Me.TopIndex
  1504.  
  1505.             ' Disable drawing on control.
  1506.             Me.BeginUpdate()
  1507.  
  1508.             For Each index As Integer In itemIndex
  1509.  
  1510.                 ' Select or Unselect the item.
  1511.                 Me.SetSelected(index, CBool(itemState))
  1512.  
  1513.             Next index
  1514.  
  1515.             ' Jump to the previous selected item.
  1516.             Me.TopIndex = i
  1517.  
  1518.             ' Eenable drawing.
  1519.             Me.EndUpdate()
  1520.  
  1521.         End Sub
  1522.  
  1523.         ''' <summary>
  1524.         ''' Selects or unselects all the items in this <see cref="T:ElektroListBox"/>.
  1525.         ''' </summary>
  1526.         ''' <param name="ListBoxItems">Indicates the Items to select or unselect.</param>
  1527.         Public Sub SetSelectedAllorNone(ByVal listBoxItems As ListBoxItems)
  1528.  
  1529.             If ((Me.SelectedItems.Count = 0) AndAlso (listBoxItems = ElektroListBox.ListBoxItems.None)) _
  1530.             OrElse ((Me.SelectedItems.Count = Me.Items.Count) AndAlso (listBoxItems = ElektroListBox.ListBoxItems.All)) Then
  1531.  
  1532.                 Exit Sub
  1533.  
  1534.             End If
  1535.  
  1536.             Me.SetSelectedNoJump(Enumerable.Range(0, Me.Items.Count), DirectCast(listBoxItems, ItemState))
  1537.  
  1538.         End Sub
  1539.  
  1540.         ''' <summary>
  1541.         ''' Moves an item to other position.
  1542.         ''' </summary>
  1543.         ''' <param name="oldIndex">The item index.</param>
  1544.         ''' <param name="newIndex">The new item index.</param>
  1545.         ''' <exception cref="System.ArgumentOutOfRangeException">oldIndex or newIndex</exception>
  1546.         Public Sub MoveItem(ByVal oldIndex As Integer, ByVal newIndex As Integer)
  1547.  
  1548.             Dim itemCount As Integer = Me.Items.Count
  1549.  
  1550.             If (oldIndex < itemCount) OrElse (oldIndex > itemCount) Then
  1551.                 Throw New ArgumentOutOfRangeException("oldIndex")
  1552.  
  1553.             ElseIf (newIndex < itemCount) OrElse (newIndex > itemCount) Then
  1554.                 Throw New ArgumentOutOfRangeException("newIndex")
  1555.  
  1556.             Else
  1557.                 Dim oldItem As Object = Me.Items.Item(oldIndex)
  1558.                 Dim newItem As Object = Me.Items.Item(newIndex)
  1559.  
  1560.                 Me.Items.Item(oldIndex) = newItem
  1561.                 Me.Items.Item(newIndex) = oldItem
  1562.  
  1563.             End If
  1564.  
  1565.         End Sub
  1566.  
  1567. #End Region
  1568.  
  1569. #Region " Private Methods "
  1570.  
  1571.         ''' <summary>
  1572.         ''' Gets the current state layout.
  1573.         ''' </summary>
  1574.         ''' <returns>StateLayout.</returns>
  1575.         Private Function GetStateLayout() As StateLayout
  1576.  
  1577.             If MyBase.Enabled AndAlso Not Me.[ReadOnly] Then ' Is Enabled
  1578.                 Return Me.stateEnabled1
  1579.  
  1580.             ElseIf Not MyBase.Enabled Then ' Is Disabled
  1581.                 Return Me.stateDisabled1
  1582.  
  1583.             ElseIf Me.[ReadOnly] Then ' Is ReadOnly
  1584.                 Return Me.stateReadOnly1
  1585.  
  1586.             Else
  1587.                 Return Nothing
  1588.  
  1589.             End If
  1590.  
  1591.         End Function
  1592.  
  1593.         ''' <summary>
  1594.         ''' Notifies a property change.
  1595.         ''' </summary>
  1596.         ''' <param name="propertyName">Name of the property.</param>
  1597.         Private Sub NotifyStateChanged(ByVal propertyName As PropertyName)
  1598.  
  1599. #If DEBUG Then
  1600.  
  1601.             Debug.WriteLine(String.Format("[{0}]: Property state changed. Property name: {1}",
  1602.                                           Me.Name, propertyName.ToString))
  1603.  
  1604. #End If
  1605.  
  1606.             Select Case propertyName
  1607.  
  1608.                 Case ElektroListBox.PropertyName.Selected,
  1609.                      ElektroListBox.PropertyName.Unselected,
  1610.                      ElektroListBox.PropertyName.UnselectedAlternate,
  1611.                      ElektroListBox.PropertyName.StringFormat,
  1612.                      ElektroListBox.PropertyName.Grid
  1613.                     Me.Invalidate(invalidateChildren:=False)
  1614.  
  1615.                 Case ElektroListBox.PropertyName.State,
  1616.                      ElektroListBox.PropertyName.Cursor
  1617.                     Me.SetCursor()
  1618.                     Me.DrawBorder(Nothing)
  1619.  
  1620.                 Case ElektroListBox.PropertyName.BorderColor
  1621.                     Me.DrawBorder(Nothing)
  1622.  
  1623.             End Select
  1624.  
  1625.         End Sub
  1626.  
  1627.         ''' <summary>
  1628.         ''' Sets the control's cursor.
  1629.         ''' </summary>
  1630.         Private Sub SetCursor()
  1631.  
  1632.             Me.Cursor = Me.GetStateLayout.Cursor
  1633.  
  1634.         End Sub
  1635.  
  1636.         ''' <summary>
  1637.         ''' Draws a border on the control's surface.
  1638.         ''' </summary>
  1639.         ''' <param name="m">The Windows <see cref="T:System.Windows.Forms.Message"/> to process.</param>
  1640.         Private Sub DrawBorder(Optional ByRef m As Message = Nothing)
  1641.  
  1642.             Dim handle As IntPtr = If(m <> Nothing,
  1643.                                       m.HWnd,
  1644.                                       Me.Handle)
  1645.  
  1646.             Dim HDC As IntPtr = NativeMethods.GetWindowDC(handle)
  1647.  
  1648.             Dim point As Point = Me.PointToScreen(New Point(0, 0))
  1649.  
  1650.             Dim rect As NativeMethods.Rect
  1651.             With rect
  1652.                 .Left = point.X
  1653.                 .Top = point.Y
  1654.                 .Right = .Left + Me.Width - 4
  1655.                 .Bottom = .Top + Me.Height - 4
  1656.             End With
  1657.  
  1658.             Dim region As IntPtr = NativeMethods.CreateRectRgnIndirect(rect)
  1659.  
  1660.             If hdc <> IntPtr.Zero Then
  1661.  
  1662.                 Using g As Graphics = Graphics.FromHdc(hdc)
  1663.  
  1664.                     g.CompositingQuality = CompositingQuality.Invalid
  1665.                     g.SmoothingMode = SmoothingMode.None
  1666.                     g.PixelOffsetMode = PixelOffsetMode.None
  1667.                     g.InterpolationMode = InterpolationMode.NearestNeighbor
  1668.  
  1669.                     Using p As New Pen(Me.GetStateLayout.BorderColor)
  1670.  
  1671.                         g.DrawRectangle(p, 0, 0, Me.Width - p.Width, Me.Height - p.Width)
  1672.  
  1673.                     End Using ' p
  1674.  
  1675.                 End Using ' g
  1676.  
  1677.                 If m <> Nothing Then
  1678.                     m.WParam = region
  1679.                     NativeMethods.ReleaseDC(handle, HDC)
  1680.                     MyBase.WndProc(m) ' Call it to draw what it needs.
  1681.                 Else
  1682.                     NativeMethods.ReleaseDC(handle, HDC)
  1683.                 End If
  1684.  
  1685.             End If
  1686.  
  1687.         End Sub
  1688.  
  1689.         ''' <summary>
  1690.         ''' Colorizes the <see cref="T:ElektroListBox"/>.
  1691.         ''' </summary>
  1692.         ''' <param name="e">The <see cref="DrawItemEventArgs"/> instance containing the event data.</param>
  1693.         Private Sub DrawItems(ByVal e As DrawItemEventArgs)
  1694.  
  1695.             If Not (Me.Items.Count <> 0) Then
  1696.                 Exit Sub
  1697.             End If
  1698.  
  1699.             Dim state As StateLayout = Me.GetStateLayout
  1700.  
  1701.             Dim backColor As Color
  1702.             Dim foreColor As Color
  1703.             Dim gridLineColor As Color = Me.stateEnabled1.Grid.Color
  1704.             Dim gridEnabled As Boolean = Me.stateEnabled1.Grid.Enabled
  1705.             Dim alternate As Boolean = CBool(e.Index Mod 2 <> 0)
  1706.  
  1707.             If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then ' selected item
  1708.                 backColor = state.Items.Background.Selected
  1709.                 foreColor = state.Items.Foreground.Selected
  1710.  
  1711.             ElseIf (e.State And DrawItemState.Selected) = DrawItemState.None Then ' unselected item
  1712.                 If alternate Then ' Alternate color
  1713.                     backColor = state.Items.Background.UnselectedAlternate
  1714.                     foreColor = state.Items.Foreground.UnselectedAlternate
  1715.                 Else
  1716.                     backColor = state.Items.Background.Unselected
  1717.                     foreColor = state.Items.Foreground.Unselected
  1718.                 End If
  1719.  
  1720.             End If
  1721.  
  1722.             With e
  1723.  
  1724.                 .Graphics.CompositingQuality = CompositingQuality.Invalid
  1725.                 .Graphics.SmoothingMode = SmoothingMode.None
  1726.                 .Graphics.PixelOffsetMode = PixelOffsetMode.None
  1727.                 .Graphics.InterpolationMode = InterpolationMode.NearestNeighbor
  1728.  
  1729.                 ' .DrawBackground()
  1730.  
  1731.                 Using backgroundBrush As New SolidBrush(backColor)
  1732.  
  1733.                     ' Draw the item background.
  1734.                     .Graphics.FillRectangle(backgroundBrush, e.Bounds)
  1735.  
  1736.                     If gridEnabled Then ' Draw the item grid line.
  1737.  
  1738.                         Using pen As New Pen(gridLineColor)
  1739.  
  1740.                             .Graphics.CompositingQuality = CompositingQuality.Invalid
  1741.                             .Graphics.SmoothingMode = SmoothingMode.None
  1742.                             .Graphics.PixelOffsetMode = PixelOffsetMode.None
  1743.                             .Graphics.InterpolationMode = InterpolationMode.NearestNeighbor
  1744.  
  1745.                             If e.Index = 0 Then
  1746.                                 .Graphics.DrawLine(pen,
  1747.                                                    New Point(e.Bounds.X, e.Bounds.Y - 1),
  1748.                                                    New Point(e.Bounds.Right, e.Bounds.Top - 1))
  1749.                             Else
  1750.                                 .Graphics.DrawLine(pen,
  1751.                                                    New Point(e.Bounds.X, e.Bounds.Y),
  1752.                                                    New Point(e.Bounds.Right, e.Bounds.Top))
  1753.                             End If
  1754.  
  1755.                         End Using ' pen
  1756.  
  1757.                     End If ' gridEnabled
  1758.  
  1759.                 End Using ' backgroundBrush
  1760.  
  1761.                 ' Draw the item text.
  1762.                 Using foregroundBrush As New SolidBrush(foreColor)
  1763.  
  1764.                     .Graphics.DrawString(MyBase.GetItemText(MyBase.Items(e.Index)),
  1765.                                           e.Font,
  1766.                                           foregroundBrush,
  1767.                                           e.Bounds, New StringFormat With
  1768.                                                         {
  1769.                                                             .Alignment = Me.textFormat1.Alignment,
  1770.                                                             .FormatFlags = Me.textFormat1.FormatFlags,
  1771.                                                             .LineAlignment = Me.textFormat1.LineAlignment,
  1772.                                                             .Trimming = Me.textFormat1.Trimming
  1773.                                                         })
  1774.  
  1775.                 End Using ' foregroundBrush
  1776.  
  1777.                 ' Draw the item's focused rectangle.
  1778.                 .DrawFocusRectangle()
  1779.  
  1780.             End With
  1781.  
  1782.         End Sub
  1783.  
  1784. #End Region
  1785.  
  1786. #Region " Event Handlers "
  1787.  
  1788.         ''' <summary>
  1789.         ''' Handles the <see cref="E:EnabledChanged"/> event of the <see cref="T:ElektroListBox"/> control.
  1790.         ''' </summary>
  1791.         ''' <param name="sender">The source of the event.</param>
  1792.         ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  1793.         Private Sub MyBase_EnabledChanged(ByVal sender As Object, ByVal e As EventArgs) _
  1794.         Handles MyBase.EnabledChanged
  1795.  
  1796.             Me.NotifyStateChanged(PropertyName.State)
  1797.  
  1798.         End Sub
  1799.  
  1800.         ''' <summary>
  1801.         ''' Handles the DrawItem event of the the <see cref="T:ElektroListBox"/>.
  1802.         ''' </summary>
  1803.         ''' <param name="sender">The source of the event.</param>
  1804.         ''' <param name="e">The <see cref="DrawItemEventArgs"/> instance containing the event data.</param>
  1805.         Private Sub MyBase_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs) _
  1806.         Handles MyBase.DrawItem
  1807.  
  1808.             Me.DrawItems(e)
  1809.  
  1810.         End Sub
  1811.  
  1812. #End Region
  1813.  
  1814. #Region " Windows Procedure "
  1815.  
  1816.         ''' <summary>
  1817.         ''' Processes messages for this window.
  1818.         ''' </summary>
  1819.         ''' <param name="m">The Windows <see cref="T:System.Windows.Forms.Message"/> to process.</param>
  1820.         Protected Overrides Sub WndProc(ByRef m As Message)
  1821.  
  1822.             Select Case m.Msg
  1823.  
  1824.                 Case WindowsMessages.WM_LBUTTONDOWN, WindowsMessages.WM_KEYDOWN
  1825.                     If Me.[ReadOnly] Then
  1826.                         ' Disable left click or keyboard on the ListBox.
  1827.                         Return
  1828.                     End If
  1829.  
  1830.                 Case WindowsMessages.WM_NCPAINT
  1831.                     If Not Me.BorderStyle = Windows.Forms.BorderStyle.None Then
  1832.                         Me.DrawBorder(m)
  1833.                     End If
  1834.                     Return
  1835.  
  1836.             End Select
  1837.  
  1838.             MyBase.WndProc(m)
  1839.  
  1840.         End Sub
  1841.  
  1842. #End Region
  1843.  
  1844.     End Class
  1845.  
  1846.  
  1847. End Namespace
  1848.  
  1849. #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement