Advertisement
Guest User

[VB.Net] ElektroListBox v2.1

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