Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)

Iniciado por Eleкtro, 18 Diciembre 2012, 22:23 PM

0 Miembros y 5 Visitantes están viendo este tema.

Eleкtro

Código (vbnet) [Seleccionar]
' ***********************************************************************
' Author   : Elektro
' Created  : 01-12-2014
' Modified : 01-12-2014
' ***********************************************************************
' <copyright file="FormBorderManager.vb" company="Elektro Studios">
'     Copyright (c) Elektro Studios. All rights reserved.
' </copyright>
' ***********************************************************************

#Region " Usage Examples "

'Public Class Form1

'    ' Disable resizing on all border edges.
'    Private FormBorders As New FormBorderManager(Me) With
'            {
'                .Edges = New FormBorderManager.FormEdges With
'                         {
'                             .Top = FormBorderManager.WindowHitTestRegions.TitleBar,
'                             .Left = FormBorderManager.WindowHitTestRegions.TitleBar,
'                             .Right = FormBorderManager.WindowHitTestRegions.TitleBar,
'                             .Bottom = FormBorderManager.WindowHitTestRegions.TitleBar,
'                             .TopLeft = FormBorderManager.WindowHitTestRegions.TitleBar,
'                             .TopRight = FormBorderManager.WindowHitTestRegions.TitleBar,
'                             .BottomLeft = FormBorderManager.WindowHitTestRegions.TitleBar,
'                             .BottomRight = FormBorderManager.WindowHitTestRegions.TitleBar
'                         }
'            }

'    Private Shadows Sub Load(sender As Object, e As EventArgs) Handles MyBase.Load

'        ' Disables the moving on all border edges.
'        FormBorders.SetAllEdgesToNonMoveable()

'    End Sub

'End Class

#End Region

#Region " Imports "

Imports System.ComponentModel

#End Region

#Region " FormBorderManager "

''' <summary>
''' Class FormBorderManager.
''' Manages each Form border to indicate their Hit-Region.
''' </summary>
<Description("Manages each Form border to indicate their Hit-Region")>
Public Class FormBorderManager : Inherits NativeWindow : Implements IDisposable

#Region " Members "

#Region " Miscellaneous "

    ''' <summary>
    ''' The form to manage their borders.
    ''' </summary>
    Private WithEvents form As Form = Nothing

#End Region

#Region " Properties "

    ''' <summary>
    ''' Gets or sets the Hit-Region of the edges.
    ''' </summary>
    ''' <value>The Form edges.</value>
    Public Property Edges As New FormEdges

    ''' <summary>
    ''' The Edges of the Form.
    ''' </summary>
    Partial Public NotInheritable Class FormEdges

        ''' <summary>
        ''' Gets or sets the Hit-Region of the Top form border.
        ''' </summary>
        Public Property Top As WindowHitTestRegions = WindowHitTestRegions.TopSizeableBorder

        ''' <summary>
        ''' Gets or sets the Hit-Region of the Left form border.
        ''' </summary>
        Public Property Left As WindowHitTestRegions = WindowHitTestRegions.LeftSizeableBorder

        ''' <summary>
        ''' Gets or sets the Hit-Region of the Right form border.
        ''' </summary>
        Public Property Right As WindowHitTestRegions = WindowHitTestRegions.RightSizeableBorder

        ''' <summary>
        ''' Gets or sets the Hit-Region of the Bottom form border.
        ''' </summary>
        Public Property Bottom As WindowHitTestRegions = WindowHitTestRegions.BottomSizeableBorder

        ''' <summary>
        ''' Gets or sets the Hit-Region of the Top-Left form border.
        ''' </summary>
        Public Property TopLeft As WindowHitTestRegions = WindowHitTestRegions.TopLeftSizeableCorner

        ''' <summary>
        ''' Gets or sets the Hit-Region of the Top-Right form border.
        ''' </summary>
        Public Property TopRight As WindowHitTestRegions = WindowHitTestRegions.TopRightSizeableCorner

        ''' <summary>
        ''' Gets or sets the Hit-Region of the Bottom-Left form border.
        ''' </summary>
        Public Property BottomLeft As WindowHitTestRegions = WindowHitTestRegions.BottomLeftSizeableCorner

        ''' <summary>
        ''' Gets or sets the Hit-Region of the Bottom-Right form border.
        ''' </summary>
        Public Property BottomRight As WindowHitTestRegions = WindowHitTestRegions.BottomRightSizeableCorner

    End Class

#End Region

#Region " Enumerations "

    ''' <summary>
    ''' Known Windows Message Identifiers.
    ''' </summary>
    <Description("Messages to process in WndProc")>
    Private Enum KnownMessages As Integer

        ''' <summary>
        ''' Sent to a window in order to determine what part of the window corresponds to a particular screen coordinate.
        ''' This can happen, for example, when the cursor moves, when a mouse button is pressed or released,
        ''' or in response to a call to a function such as WindowFromPoint.
        ''' If the mouse is not captured, the message is sent to the window beneath the cursor.
        ''' Otherwise, the message is sent to the window that has captured the mouse.
        ''' <paramref name="WParam" />
        ''' This parameter is not used.
        ''' <paramref name="LParam" />
        ''' The low-order word specifies the x-coordinate of the cursor.
        ''' The coordinate is relative to the upper-left corner of the screen.
        ''' The high-order word specifies the y-coordinate of the cursor.
        ''' The coordinate is relative to the upper-left corner of the screen.
        ''' </summary>
        WM_NCHITTEST = &H84

    End Enum

    ''' <summary>
    ''' Indicates the position of the cursor hot spot.
    ''' Options available when a form is tested for mose positions with 'WM_NCHITTEST' message.
    ''' </summary>
    <Description("Return value of the 'WM_NCHITTEST' message")>
    Public Enum WindowHitTestRegions

        ''' <summary>
        ''' HTERROR: On the screen background or on a dividing line between windows.
        ''' (same as HTNOWHERE, except that the DefWindowProc function produces a system beep to indicate an error).
        ''' </summary>
        [Error] = -2

        ''' <summary>
        ''' HTTRANSPARENT: In a window currently covered by another window in the same thread.
        ''' (the message will be sent to underlying windows in the same thread
        ''' until one of them returns a code that is not HTTRANSPARENT).
        ''' </summary>
        TransparentOrCovered = -1

        ''' <summary>
        ''' HTNOWHERE: On the screen background or on a dividing line between windows.
        ''' </summary>
        NoWhere = 0

        ''' <summary>
        ''' HTCLIENT: In a client area.
        ''' </summary>
        ClientArea = 1

        ''' <summary>
        ''' HTCAPTION: In a title bar.
        ''' </summary>
        TitleBar = 2

        ''' <summary>
        ''' HTSYSMENU: In a window menu or in a Close button in a child window.
        ''' </summary>
        SystemMenu = 3

        ''' <summary>
        ''' HTGROWBOX: In a size box (same as HTSIZE).
        ''' </summary>
        GrowBox = 4

        ''' <summary>
        ''' HTMENU: In a menu.
        ''' </summary>
        Menu = 5

        ''' <summary>
        ''' HTHSCROLL: In a horizontal scroll bar.
        ''' </summary>
        HorizontalScrollBar = 6

        ''' <summary>
        ''' HTVSCROLL: In the vertical scroll bar.
        ''' </summary>
        VerticalScrollBar = 7

        ''' <summary>
        ''' HTMINBUTTON: In a Minimize button.
        ''' </summary>
        MinimizeButton = 8

        ''' <summary>
        ''' HTMAXBUTTON: In a Maximize button.
        ''' </summary>
        MaximizeButton = 9

        ''' <summary>
        ''' HTLEFT: In the left border of a resizable window.
        ''' (the user can click the mouse to resize the window horizontally).
        ''' </summary>
        LeftSizeableBorder = 10

        ''' <summary>
        ''' HTRIGHT: In the right border of a resizable window.
        ''' (the user can click the mouse to resize the window horizontally).
        ''' </summary>
        RightSizeableBorder = 11

        ''' <summary>
        ''' HTTOP: In the upper-horizontal border of a window.
        ''' </summary>
        TopSizeableBorder = 12

        ''' <summary>
        ''' HTTOPLEFT: In the upper-left corner of a window border.
        ''' </summary>
        TopLeftSizeableCorner = 13

        ''' <summary>
        ''' HTTOPRIGHT: In the upper-right corner of a window border.
        ''' </summary>
        TopRightSizeableCorner = 14

        ''' <summary>
        ''' HTBOTTOM: In the lower-horizontal border of a resizable window.
        ''' (the user can click the mouse to resize the window vertically).
        ''' </summary>
        BottomSizeableBorder = 15

        ''' <summary>
        ''' HTBOTTOMLEFT: In the lower-left corner of a border of a resizable window.
        ''' (the user can click the mouse to resize the window diagonally).
        ''' </summary>
        BottomLeftSizeableCorner = 16

        ''' <summary>
        ''' HTBOTTOMRIGHT: In the lower-right corner of a border of a resizable window.
        ''' (the user can click the mouse to resize the window diagonally).
        ''' </summary>
        BottomRightSizeableCorner = 17

        ''' <summary>
        ''' HTBORDER: In the border of a window that does not have a sizing border.
        ''' </summary>
        NonSizableBorder = 18

        ' ''' <summary>
        ' ''' HTOBJECT: Not implemented.
        ' ''' </summary>
        ' [Object] = 19

        ''' <summary>
        ''' HTCLOSE: In a Close button.
        ''' </summary>
        CloseButton = 20

        ''' <summary>
        ''' HTHELP: In a Help button.
        ''' </summary>
        HelpButton = 21

        ''' <summary>
        ''' HTSIZE: In a size box (same as HTGROWBOX).
        ''' (Same as GrowBox).
        ''' </summary>
        SizeBox = GrowBox

        ''' <summary>
        ''' HTREDUCE: In a Minimize button.
        ''' (Same as MinimizeButton).
        ''' </summary>
        ReduceButton = MinimizeButton

        ''' <summary>
        ''' HTZOOM: In a Maximize button.
        ''' (Same as MaximizeButton).
        ''' </summary>
        ZoomButton = MaximizeButton

    End Enum

#End Region

#End Region

#Region " Constructor "

    ''' <summary>
    ''' Initializes a new instance of the <see cref="FormBorderManager"/> class.
    ''' </summary>
    ''' <param name="form">The form to assign.</param>
    Public Sub New(ByVal form As Form)

        ' Assign the Formulary.
        Me.form = form

        ' Assign the form handle.
        Me.SetFormHandle()

    End Sub

#End Region

#Region " Event Handlers "

    ''' <summary>
    ''' Assign the handle of the target form to this NativeWindow,
    ''' necessary to override WndProc.
    ''' </summary>
    Private Sub SetFormHandle() _
    Handles Form.HandleCreated, Form.Load, Form.Shown

        Try
            If Not MyBase.Handle.Equals(Me.form.Handle) Then
                MyBase.AssignHandle(Me.form.Handle)
            End If
        Catch ' ex As InvalidOperationException
        End Try

    End Sub

    ''' <summary>
    ''' Releases the Handle.
    ''' </summary>
    Private Sub OnHandleDestroyed() _
    Handles Form.HandleDestroyed

        MyBase.ReleaseHandle()

    End Sub

#End Region

#Region " WndProc "

    ''' <summary>
    ''' Invokes the default window procedure associated with this window to process messages for this Window.
    ''' </summary>
    ''' <param name="m">
    ''' A <see cref="T:System.Windows.Forms.Message" /> that is associated with the current Windows message.
    ''' </param>
    Protected Overrides Sub WndProc(ByRef m As Message)

        MyBase.WndProc(m)

        Select Case m.Msg

            Case KnownMessages.WM_NCHITTEST

                Select Case CType(m.Result, WindowHitTestRegions)

                    Case WindowHitTestRegions.TopSizeableBorder ' The mouse hotspot is pointing to Top border.
                        m.Result = New IntPtr(Edges.Top)

                    Case WindowHitTestRegions.LeftSizeableBorder ' The mouse hotspot is pointing to Left border.
                        m.Result = New IntPtr(Edges.Left)

                    Case WindowHitTestRegions.RightSizeableBorder ' The mouse hotspot is pointing to Right border.
                        m.Result = New IntPtr(Edges.Right)

                    Case WindowHitTestRegions.BottomSizeableBorder ' The mouse hotspot is pointing to Bottom border.
                        m.Result = New IntPtr(Edges.Bottom)

                    Case WindowHitTestRegions.TopLeftSizeableCorner ' The mouse hotspot is pointing to Top-Left border.
                        m.Result = New IntPtr(Edges.TopLeft)

                    Case WindowHitTestRegions.TopRightSizeableCorner ' The mouse hotspot is pointing to Top-Right border.
                        m.Result = New IntPtr(Edges.TopRight)

                    Case WindowHitTestRegions.BottomLeftSizeableCorner ' The mouse hotspot is pointing to Bottom-Left border.
                        m.Result = New IntPtr(Edges.BottomLeft)

                    Case WindowHitTestRegions.BottomRightSizeableCorner ' The mouse hotspot is pointing to Bottom-Right border.
                        m.Result = New IntPtr(Edges.BottomRight)

                End Select

        End Select

    End Sub

#End Region

#Region " Public Methods "

    ''' <summary>
    ''' Disables the resizing on all border edges.
    ''' </summary>
    Public Sub SetAllEdgesToNonResizable()

        DisposedCheck()

        Me.Edges.Top = WindowHitTestRegions.TitleBar
        Me.Edges.Left = WindowHitTestRegions.TitleBar
        Me.Edges.Right = WindowHitTestRegions.TitleBar
        Me.Edges.Bottom = WindowHitTestRegions.TitleBar
        Me.Edges.TopLeft = WindowHitTestRegions.TitleBar
        Me.Edges.TopRight = WindowHitTestRegions.TitleBar
        Me.Edges.BottomLeft = WindowHitTestRegions.TitleBar
        Me.Edges.BottomRight = WindowHitTestRegions.TitleBar

    End Sub

    ''' <summary>
    ''' Enables the resizing on all border edges.
    ''' </summary>
    Public Sub SetAllEdgesToResizable()

        DisposedCheck()

        Me.Edges.Top = WindowHitTestRegions.TopSizeableBorder
        Me.Edges.Left = WindowHitTestRegions.LeftSizeableBorder
        Me.Edges.Right = WindowHitTestRegions.RightSizeableBorder
        Me.Edges.Bottom = WindowHitTestRegions.BottomSizeableBorder
        Me.Edges.TopLeft = WindowHitTestRegions.TopLeftSizeableCorner
        Me.Edges.TopRight = WindowHitTestRegions.TopRightSizeableCorner
        Me.Edges.BottomLeft = WindowHitTestRegions.BottomLeftSizeableCorner
        Me.Edges.BottomRight = WindowHitTestRegions.BottomRightSizeableCorner

    End Sub

    ''' <summary>
    ''' Enabled the moving on all border edges.
    ''' </summary>
    Public Sub SetAllEdgesToMoveable()

        DisposedCheck()

        Me.Edges.Top = WindowHitTestRegions.TopSizeableBorder
        Me.Edges.Left = WindowHitTestRegions.LeftSizeableBorder
        Me.Edges.Right = WindowHitTestRegions.RightSizeableBorder
        Me.Edges.Bottom = WindowHitTestRegions.BottomSizeableBorder
        Me.Edges.TopLeft = WindowHitTestRegions.TopLeftSizeableCorner
        Me.Edges.TopRight = WindowHitTestRegions.TopRightSizeableCorner
        Me.Edges.BottomLeft = WindowHitTestRegions.BottomLeftSizeableCorner
        Me.Edges.BottomRight = WindowHitTestRegions.BottomRightSizeableCorner

    End Sub

    ''' <summary>
    ''' Disables the moving on all border edges.
    ''' </summary>
    Public Sub SetAllEdgesToNonMoveable()

        DisposedCheck()

        Me.Edges.Top = WindowHitTestRegions.NoWhere
        Me.Edges.Left = WindowHitTestRegions.NoWhere
        Me.Edges.Right = WindowHitTestRegions.NoWhere
        Me.Edges.Bottom = WindowHitTestRegions.NoWhere
        Me.Edges.TopLeft = WindowHitTestRegions.NoWhere
        Me.Edges.TopRight = WindowHitTestRegions.NoWhere
        Me.Edges.BottomLeft = WindowHitTestRegions.NoWhere
        Me.Edges.BottomRight = WindowHitTestRegions.NoWhere

    End Sub

#End Region

#Region " Hidden methods "

    ' These methods and properties are purposely hidden from Intellisense just to look better without unneeded methods.
    ' NOTE: The methods can be re-enabled at any-time if needed.

    ''' <summary>
    ''' Assigns the handle.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub AssignHandle()
    End Sub

    ''' <summary>
    ''' Creates the handle.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub CreateHandle()
    End Sub

    ''' <summary>
    ''' Creates the object reference.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub CreateObjRef()
    End Sub

    ''' <summary>
    ''' Definitions the WND proc.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub DefWndProc()
    End Sub

    ''' <summary>
    ''' Destroys the window and its handle.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub DestroyHandle()
    End Sub

    ''' <summary>
    ''' Equalses this instance.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub Equals()
    End Sub

    ''' <summary>
    ''' Gets the hash code.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub GetHashCode()
    End Sub

    ''' <summary>
    ''' Gets the lifetime service.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub GetLifetimeService()
    End Sub

    ''' <summary>
    ''' Initializes the lifetime service.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub InitializeLifetimeService()
    End Sub

    ''' <summary>
    ''' Releases the handle associated with this window.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub ReleaseHandle()
    End Sub

    ''' <summary>
    ''' Gets the handle for this window.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Property Handle()

#End Region

#Region " IDisposable "

    ''' <summary>
    ''' To detect redundant calls when disposing.
    ''' </summary>
    Private IsDisposed As Boolean = False

    ''' <summary>
    ''' Prevent calls to methods after disposing.
    ''' </summary>
    ''' <exception cref="System.ObjectDisposedException"></exception>
    Private Sub DisposedCheck()
        If Me.IsDisposed Then
            Throw New ObjectDisposedException(Me.GetType().FullName)
        End If
    End Sub

    ''' <summary>
    ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    ''' </summary>
    Public Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

    ''' <summary>
    ''' Releases unmanaged and - optionally - managed resources.
    ''' </summary>
    ''' <param name="IsDisposing">
    ''' <c>true</c> to release both managed and unmanaged resources;
    ''' <c>false</c> to release only unmanaged resources.
    ''' </param>

    Protected Sub Dispose(IsDisposing As Boolean)

        If Not Me.IsDisposed Then

            If IsDisposing Then
                Me.form = Nothing
                MyBase.ReleaseHandle()
                MyBase.DestroyHandle()
            End If

        End If

        Me.IsDisposed = True

    End Sub

#End Region

End Class

#End Region








Eleкtro

#361
Una Helper Class con utilidades variadas relacionadas con los colores:

Código (vbnet) [Seleccionar]

' ***********************************************************************
' Author   : Elektro
' Created  : 01-13-2014
' Modified : 01-13-2014
' ***********************************************************************

' --------------
' Public Methods
' --------------
'
' Screen.GetPixelColor
' Screen.GetPixelBrush
' Screen.GetPixelPen
'
' ColorConvert.ColorToBrush
' ColorConvert.ColorToPen
' ColorConvert.BrushToColor
' ColorConvert.PentoColor
'
' StringConvert.ColorToString
' StringConvert.BrushToString
' StringConvert.PenToString
' StringConvert.StringToColor
' StringConvert.StringToBrush
' StringConvert.StringToPen
' StringConvert.StringToString
'
' RandomGenerators.ARGB
' RandomGenerators.RGB
' RandomGenerators.QB
' RandomGenerators.ConsoleColor
' RandomGenerators.Brush
' RandomGenerators.Pen


La Class no cabe en un post, aquí la pueden ver ~> http://pastebin.com/88Q0wGPf

Ejemplos de uso:

Código (vbnet) [Seleccionar]
' Gets the color of the pixel at the 50,100 coordinates:
Dim c As Color = ColorTools.Screen.GetPixelColor(50, 100)

' Generates a random Brush
Dim br As SolidBrush = ColorTools.RandomGenerators.Brush

' Converts a SolidBrush to a Color:
Dim c As Color = ColorTools.ColorConvert.BrushToColor(New SolidBrush(Color.Red))

' Converts an HTML Color-String to a Color:
PictureBox1.BackColor = ColorTools.StringConvert.StringToColor("#FF00FFFF",
                                                               ColorTools.StringConvert.ValueFormat.HTML,
                                                               ColorTools.StringConvert.StringSyntax.None)

' Converts an Hex Color-String to a Color:
MsgBox(ColorTools.StringConvert.StringToColor("0x003399",
                                              ColorTools.StringConvert.ValueFormat.Hexadecimal,
                                              ColorTools.StringConvert.StringSyntax.None))

' Converts a Byte Color-String with VisyalStudio's property grid syntax to a Color:
MsgBox(ColorTools.StringConvert.StringToColor("255; 255; 255; 255",
                                              ColorTools.StringConvert.ValueFormat.Byte,
                                              ColorTools.StringConvert.StringSyntax.VisualStudioPropertyGrid).
                                              Name)

' Converts a HEX Color-String with VB.NET syntax to a Color:
MsgBox(ColorTools.StringConvert.StringToColor("Color.FromArgb(&HFF, &H5F, &HEC, &H12)",
                                              ColorTools.StringConvert.ValueFormat.Hexadecimal,
                                              ColorTools.StringConvert.StringSyntax.VBNET).
                                              ToString)

' Converts an HTML Color-String with C# Syntax to a Brush:
Dim br As Brush = ColorTools.StringConvert.StringToBrush("ColorTranslator.FromHtml(""#F71608"");",
                                                         ColorTools.StringConvert.ValueFormat.HTML,
                                                         ColorTools.StringConvert.StringSyntax.VBNET)

' Converts a Color-String to other Color-String:
MsgBox(ColorTools.StringConvert.StringToString("ColorTranslator.FromHtml(""#AF0CCAFE"");",
                                               ColorTools.StringConvert.ValueFormat.HTML,
                                               ColorTools.StringConvert.StringSyntax.CSharp,
                                               ColorTools.StringConvert.ValueFormat.Byte,
                                               ColorTools.StringConvert.StringSyntax.None,
                                               True))













CatadorDeVeneno

A mi no me deja descargar, ¿me podrias facilitar un enlace por MP?
Muy buen aporte!!
Muchas gracias!!

Eleкtro

Cita de: CatadorDeVeneno en 13 Enero 2014, 18:11 PMA mi no me deja descargar, ¿me podrias facilitar un enlace por MP?

Hola,
He actualizado el enlace en la primera página ~> http://www.mediafire.com/download/ms5r82x12y32p8a/My%20Code%20Snippets.rar

Saludos!








Eleкtro

#364
Una forma muy, muy sencilla de implementar una evaluación Trial del programa, usando la librería CryptoLicensing.

NOTA: El tipo de protección y checkeos, ya sea una evaluación trial, un límite de máquinas o un límite de usos, o una comprobación hardware-id ...todo se genera desde la aplicación de CryptoLicensing y queda registrado en la propiedad "LicenseCode"... mi ayudante está pensado para una evaluación muy sencilla y básica sin posibilidad de validar, es decir, no está pensado para evaluar licencias válidas ...sinó más bien para restringir la aplicación a un máximo de usos y/o duración de ejecución y/o dias, todavía no he indagado mucho en el modo de uso de la librería.

Código (vbnet) [Seleccionar]
' CryptoLicense Helper
' ( By Elektro )
'
' Usage Examples:
' Dim MyLicense As New Licenser

#Region " Imports "

Imports LogicNP.CryptoLicensing
Imports System.Windows.Forms

#End Region

''' <summary>
''' Manages the license of this Application.
''' </summary>
Public Class Licenser

#Region " Members "

   ''' <summary>
   ''' The license object.
   ''' </summary>
   Public WithEvents License As CryptoLicense =
       New CryptoLicense() With
       {
           .ValidationKey = "AMAAMACSde6/zo6beBTzxAC5D9qrf6OyReAJwGB30gMr5ViI1/+ZXRzwt7M+KnraMKNkaREDAAEAAQ==",
           .LicenseCode = "FgCAABguQrc4Es8BAQETTsmKhj/OGCuTbJzExXb9GO7sx3yR6wQIGynJ76g7DyxOU0zgSZ82lYtuIa8r9m8="
       }

   ''' <summary>
   ''' The license message to display on a MessageBox.
   ''' </summary>
   Private LicenseMessage As String = String.Empty

#End Region

#Region " Constructor "

   ''' <summary>
   ''' Initializes a new instance of the <see cref="Licenser"/> class.
   ''' </summary>
   Public Sub New()

       Select Case License.Status

           Case LicenseStatus.Valid
               OnValid()

           Case LicenseStatus.InValid
               OnInvalid()

           Case LicenseStatus.Expired
               OnExpired()

           Case LicenseStatus.UsageDaysExceeded
               OnUsageDaysExceeded()

           Case LicenseStatus.ExecutionsExceeded
               OnExecutionsExceeded()

       End Select

   End Sub

#End Region

#Region " Methods "

   ''' <summary>
   ''' Called when license status is valid.
   ''' </summary>
   Private Sub OnValid()

       If License.RemainingUsageDays <> Short.MaxValue Then

           LicenseMessage = String.Format("{0} days remaining.",
                                          CStr(License.RemainingUsageDays))
           ShowLicenseMessage(False)

       End If

   End Sub

   ''' <summary>
   ''' Called when license status is invalid.
   ''' </summary>
   Private Sub OnInvalid()

       LicenseMessage = "Invalid License."
       ShowLicenseMessage(True)
       Terminate()

   End Sub

   ''' <summary>
   ''' Called when license status expired.
   ''' </summary>
   Private Sub OnExpired()

       LicenseMessage = String.Format("License has expired on {0}.",
                                      CStr(License.DateExpires))
       ShowLicenseMessage(True)
       Terminate()

   End Sub

   ''' <summary>
   ''' Called when license status usage days exceeded.
   ''' </summary>
   Private Sub OnUsageDaysExceeded()

       LicenseMessage = String.Format("This software is limited to 7 days, this is the {0} day.",
                                      CStr(License.CurrentUsageDays))
       ShowLicenseMessage(True)
       Terminate()

   End Sub

   ''' <summary>
   ''' Called when license status executions exceeded.
   ''' </summary>
   Private Sub OnExecutionsExceeded()

       LicenseMessage = String.Format("This software is limited to 5 executions, this is the {0} execution.",
                                      CStr(License.CurrentExecutions))
       ShowLicenseMessage(True)
       Terminate()

   End Sub

#End Region

#Region " Miscellaneous Methods "

   ''' <summary>
   ''' Shows the license message on a MessageBox.
   ''' </summary>
   Private Sub ShowLicenseMessage(Optional ByVal ShowBuyComment As Boolean = False)

       LicenseMessage = String.Format("{0}{1}",
                                      LicenseMessage,
                                      If(ShowBuyComment,
                                         Environment.NewLine & "Please buy this software.",
                                         Nothing))

       MessageBox.Show(LicenseMessage, "License Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

   End Sub

   ''' <summary>
   ''' Terminates the application.
   ''' </summary>
   Private Sub Terminate()

       Application.Exit() ' Terminate the application.

   End Sub

#End Region

#Region " Event Handlers "

   ''' <summary>
   ''' Handles the RunTimeExceeded event of the License.
   ''' </summary>
   ''' <param name="sender">The source of the event.</param>
   ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
   Private Sub License_RunTimeExceeded(ByVal sender As Object, e As EventArgs) _
   Handles License.RunTimeExceeded

       LicenseMessage = "Maximum usage time exceeded."
       ShowLicenseMessage(True)
       Terminate()

   End Sub

#End Region

End Class








Eleкtro

Determina si el ratón está dentro del rango de pixels de un Control.

Código (vbnet) [Seleccionar]
    ' Mouse Is Over Control?
    ' ( By Elektro )
    '
    ' Usage Examples:
    ' MsgBox(MouseIsOverControl(PictureBox1))
    '
    ''' <summary>
    ''' Determinates whether the mouse pointer is over a pixel range of a specified control.
    ''' </summary>
    ''' <param name="Control">The control.</param>
    ''' <returns>
    ''' <c>true</c> if mouse is inside the pixel range, <c>false</c> otherwise.
    ''' </returns>
    Private Function MouseIsOverControl(ByVal [Control] As Control) As Boolean

        Return [Control].ClientRectangle.Contains([Control].PointToClient(MousePosition))

    End Function





Crea un Bitmap y lo rellena con un color específico.

Código (vbnet) [Seleccionar]
    ' Create Solid Bitmap
    ' ( By Elektro )
    '
    ' Usage Examples:
    ' PictureBox1.BackgroundImage = CreateSolidBitmap(New Size(16, 16), Color.Red)
    '
    ''' <summary>
    ''' Creates a bitmap filled with a solid color.
    ''' </summary>
    ''' <param name="FillColor">Color to fill the Bitmap.</param>
    ''' <returns>A Bitmap filled with the specified color.</returns>
    Private Function CreateSolidBitmap(ByVal [Size] As Size,
                                       ByVal FillColor As Color) As Bitmap

        ' Create a bitmap.
        Dim bmp As New Bitmap([Size].Width, [Size].Height)

        ' Create a graphics object.
        Using g As Graphics = Graphics.FromImage(bmp)

            ' Create a brush using the specified color.
            Using br As New SolidBrush(FillColor)

                ' Fill the graphics object with the brush.
                g.FillRectangle(br, 0, 0, bmp.Width, bmp.Height)

            End Using ' br

        End Using ' g

        Return bmp

    End Function





Crea una serie de ToolStripItems en tiempo de ejecución.

Código (vbnet) [Seleccionar]
    ' Create ToolStripItems at execution-time.
    ' ( By Elektro )
    '
    ''' <summary>
    ''' Handles the MouseEnter event of the ToolStripMenuItem control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
    Private Sub ToolStripMenuItem1_MouseEnter(sender As Object, e As EventArgs) _
    Handles ToolStripMenuItem1.MouseEnter

        ' Cast the Sender object.
        Dim MenuItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)

        ' Remove previous Item handlers.
        For Each Item As ToolStripItem In MenuItem.DropDown.Items
            RemoveHandler Item.Click, AddressOf DropDownItems_Click
        Next Item

        ' Clear previous items.
        MenuItem.DropDown.Items.Clear()

        ' Set the DropDown Backcolor.
        MenuItem.DropDown.BackColor = MenuItem.BackColor

        ' Create new items.
        For X As Integer = 0 To 5

            ' Add the Item and set the Text, Image, and OnClick event handler.
            Dim Item As ToolStripItem =
                MenuItem.DropDown.Items.Add([Enum].Parse(GetType(ConsoleColor), X).ToString,
                                            New Bitmap(1, 1),
                                            AddressOf DropDownItems_Click)

            ' Set other item properties.
            With Item
                .Tag = X
            End With

        Next X

    End Sub

    ''' <summary>
    ''' Handles the Click event of the DropDownItems.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
    Private Sub DropDownItems_Click(sender As Object, e As EventArgs)

        MsgBox(String.Format("Item clicked: {0} | {1}", CStr(sender.Tag), CStr(sender.Text)))

    End Sub








Eleкtro

Unos Snippets que he escrito para algunos de los controles de usuario de DotNetBar.

Ejemplo de como crear y mostrar un Ballon.

Código (vbnet) [Seleccionar]
    ' DotNetBar [Ballon] Example to create a new Ballon.
    ' ( By Elektro )
    '
    ' Instructions:
    ' 1. Add a reference to 'DevComponents.DotNetBar.dll'.

    ''' <summary>
    ''' The DotNetBar Ballon object.
    ''' </summary>
    Private WithEvents BallonTip As Balloon = Nothing

    ''' <summary>
    ''' Handles the MouseEnter event of the TextBox1 control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
    Private Sub TextBox1_MouseEnter(ByVal sender As Object, ByVal e As EventArgs) _
    Handles TextBox1.MouseEnter

        BallonTip = New Balloon()

        ' Set the properties to customize the Ballon.
        With BallonTip

            .Owner = Me
            .Style = eBallonStyle.Balloon
            .AutoCloseTimeOut = 5 ' In seconds.

            .BorderColor = Color.YellowGreen
            .BackColor = Color.FromArgb(80, 80, 80)
            .BackColor2 = Color.FromArgb(40, 40, 40)
            .BackColorGradientAngle = 90

            .CaptionIcon = Nothing
            .CaptionImage = Nothing
            .CaptionText = "I'm a BallonTip"
            .CaptionFont = .Owner.Font
            .CaptionColor = Color.YellowGreen

            .Text = "I'm the BallonTip text"
            .ForeColor = Color.WhiteSmoke

            .AutoResize() ' Autoresize the Ballon, after setting the text.
            .Show(sender, False) ' Show it.

        End With

    End Sub

    ''' <summary>
    ''' Handles the MouseLeave event of the TextBox1 control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
    Private Sub DisposeBallon(ByVal sender As Object, ByVal e As EventArgs) _
    Handles TextBox1.MouseLeave

        If BallonTip IsNot Nothing AndAlso BallonTip.Visible Then
            BallonTip.Dispose()
        End If

    End Sub






Muestra un SuperTooltipInfo en unas coordenadas específicas.

Código (vbnet) [Seleccionar]
    ' DotNetBar [SuperTooltipInfo] Show SuperTooltipInfo at MousePosition
    ' ( By Elektro )
    '
    ' Instructions:
    ' 1. Add a reference to 'DevComponents.DotNetBar.dll'.
    ' 2. Add a 'SuperToolTip' control in the Designer.
    '
    ' Usage Examples:
    ' ShowSuperTooltipInfo(SuperTooltip1,
    '                      "I'm the Header", "I'm the Body", , "I'm the Footer", ,
    '                      eTooltipColor.Blue, MousePosition, 2, False)
    '
    ''' <summary>
    ''' Shows a SuperTooltipInfo on the specified location.
    ''' </summary>
    ''' <param name="SuperToolTip">Indicates the SuperTooltip control.</param>
    ''' <param name="HeaderText">Indicates the header text.</param>
    ''' <param name="BodyText">Indicates the body text.</param>
    ''' <param name="BodyImage">Indicates the body image.</param>
    ''' <param name="FooterText">Indicates the footer text.</param>
    ''' <param name="FooterImage">Indicates the footer image.</param>
    ''' <param name="BackColor">Indicates the Tooltip background color.</param>
    ''' <param name="Location">Indicates the location where to show the Tooltip.</param>
    ''' <param name="Duration">Indicates the Tooltip duration.</param>
    ''' <param name="PositionBelowControl">If set to <c>true</c> the tooltip is shown below the control.</param>
    Private Sub ShowSuperTooltip(ByVal SuperToolTip As SuperTooltip,
                                 Optional ByVal HeaderText As String = "",
                                 Optional ByVal BodyText As String = "",
                                 Optional ByVal BodyImage As Image = Nothing,
                                 Optional ByVal FooterText As String = "",
                                 Optional ByVal FooterImage As Image = Nothing,
                                 Optional ByVal BackColor As eTooltipColor = eTooltipColor.System,
                                 Optional ByVal Location As Point = Nothing,
                                 Optional ByVal Duration As Integer = 2,
                                 Optional ByVal PositionBelowControl As Boolean = False)

        ' Save the current SuperToolTip contorl properties to restore them at end.
        Dim CurrentProp_IgnoreFormActiveState As Boolean = SuperToolTip.IgnoreFormActiveState
        Dim CurrentProp_PositionBelowControl As Boolean = SuperToolTip.PositionBelowControl

        ' Create an invisible Form.
        Dim TooltipForm As New Form
        With TooltipForm
            .Size = New Size(0, 0)
            .Opacity = 0
            .Location = Location ' Move the Form to the specified location.
        End With

        ' Create a SuperTooltipInfo.
        Dim MySuperTooltip As New SuperTooltipInfo()
        With MySuperTooltip
            .HeaderText = HeaderText
            .BodyText = BodyText
            .BodyImage = BodyImage
            .FooterText = FooterText
            .FooterImage = FooterImage
            .Color = BackColor
        End With

        ' Set the Supertooltip properties.
        With SuperToolTip
            .IgnoreFormActiveState = True ' Ignore the form state to display the tooltip.
            .PositionBelowControl = PositionBelowControl
            .TooltipDuration = Duration
            .SetSuperTooltip(TooltipForm, MySuperTooltip) ' Assign the SuperTooltip to the invisible form.
            .ShowTooltip(TooltipForm) ' Show the SuperTooltipInfo on the form.
        End With

        ' Restore the SuperTooltip properties.
        With SuperToolTip
            .IgnoreFormActiveState = CurrentProp_IgnoreFormActiveState
            .PositionBelowControl = CurrentProp_PositionBelowControl
        End With

        ' Dispose the invisible Form.
        TooltipForm.Dispose()

    End Sub





Ejemplo de como añadir soporte para mover un SideBar usando la rueda del ratón.

Código (vbnet) [Seleccionar]
    ' DotNetBar [SideBar] Scroll SideBar using MouseWheel.
    ' ( By Elektro )
    '
    ' Instructions:
    ' 1. Reference 'DevComponents.DotNetBar.dll'.
    ' 2. Add a 'SideBar' control (with panel and buttons inside).

    ''' <summary>
    ''' Handles the MouseMove event of the SideBar1 control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
    Private Sub SideBar1_MouseMove(sender As Object, e As MouseEventArgs) _
    Handles SideBar1.MouseMove

        SideBar1.Focus()

    End Sub

    ''' <summary>
    ''' Handles the MouseWheel event of the SideBar control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
    Private Sub SideBar1_MouseWheel(sender As Object, e As MouseEventArgs) _
    Handles SideBar1.MouseWheel

        Dim TopItemIndex As Integer = sender.ExpandedPanel.TopItemIndex
        Dim ItemCount As Integer = sender.ExpandedPanel.SubItems.Count

        Select Case e.Delta

            Case Is < 0
                If TopItemIndex < ItemCount - 1 Then
                    TopItemIndex += 1
                End If

            Case Else
                If TopItemIndex > 0 Then
                    TopItemIndex -= 1
                End If

        End Select

    End Sub





Ejemplo de como crear y o eliminar tabs de un SuperTabControl en tiempo de ejecución.

Código (vbnet) [Seleccionar]
    ' DotNetBar [Ballon] Example to create a new Ballon.
    ' ( By Elektro )
    '
    ' Instructions:
    ' 1. Add a reference to 'DevComponents.DotNetBar.dll'.
    ' 2. Add a 'SuperTabControl' control.

    Private Sub Test(sender As Object, e As EventArgs) Handles MyBase.Shown

        ' Create a new Tab.
        Dim tab As SuperTabItem = SuperTabControl1.CreateTab("New Tab")

        ' Create a new Tab-Panel.
        Dim tabpanel As SuperTabControlPanel = DirectCast(tab.AttachedControl, SuperTabControlPanel)

        ' Create a random control.
        Dim wbr As New WebBrowser() With {.Dock = DockStyle.Fill}
        wbr.Navigate("google.com")

        'Add the control to the Tab-Panel.
        tabpanel.Controls.Add(wbr)

        ' Remove the Tab.
        ' SuperTabControl1.Tabs.Remove(tab)

        ' And remember to dispose the Tab-Panel and the added Controls.
        ' tabpanel.Dispose()
        ' wbr.Dispose()

    End Sub





Ejemplo de como crear una Bar en tiempo de ejecución.

Código (vbnet) [Seleccionar]
    ' DotNetBar [DotNetBarManager] Example to create a new Bar at execution-time.
    ' ( By Elektro )
    '
    ' Instructions:
    ' 1. Add a reference to 'DevComponents.DotNetBar.dll'.
    ' 2. Add a 'DotNetBarManager' control.

    Private Sub Test(sender As Object, e As EventArgs) Handles MyBase.Shown

        Dim bar As Bar
        Dim menu As ButtonItem
        Dim submenu As ButtonItem

        bar = New Bar("My Menu Bar")

        bar.ColorScheme.DockSiteBackColor = Color.YellowGreen
        bar.ColorScheme.DockSiteBackColor2 = Color.YellowGreen

        bar.ColorScheme.MenuBarBackground = Color.FromArgb(80, 80, 80)
        bar.ColorScheme.MenuBarBackground2 = Color.FromArgb(40, 40, 40)

        bar.ColorScheme.MenuSide = Color.Silver
        bar.ColorScheme.MenuSide2 = Color.FromArgb(80, 80, 80)

        bar.ColorScheme.ItemText = Color.Black
        bar.ColorScheme.ItemBackground = Color.Silver
        bar.ColorScheme.ItemBackground2 = Color.Silver

        bar.ColorScheme.ItemHotText = Color.Black
        bar.ColorScheme.ItemHotBackground = Color.YellowGreen
        bar.ColorScheme.ItemHotBackground2 = Color.YellowGreen

        bar.MenuBar = True
        bar.Stretch = True

        DotNetBarManager1.UseGlobalColorScheme = False
        DotNetBarManager1.Bars.Add(bar)
        bar.DockSide = eDockSide.Top

        menu = New ButtonItem("bFile", "&File")
        bar.Items.Add(menu)

        submenu = New ButtonItem("bOpen", "&Open")
        menu.SubItems.Add(submenu)

        submenu = New ButtonItem("bClose", "&Close")
        menu.SubItems.Add(submenu)

        submenu = New ButtonItem("bExit", "&Exit")

        submenu.BeginGroup = True
        menu.SubItems.Add(submenu)

        menu = New ButtonItem("bEdit", "&Edit")
        bar.Items.Add(menu)

        submenu = New ButtonItem("bCut", "&Cut")
        menu.SubItems.Add(submenu)

        submenu = New ButtonItem("bCopy", "&Copy")
        menu.SubItems.Add(submenu)

        submenu = New ButtonItem("bPaste", "&Paste")
        menu.SubItems.Add(submenu)

        submenu = New ButtonItem("bClear", "&Clear")

        submenu.BeginGroup = True
        menu.SubItems.Add(submenu)

        bar.RecalcLayout()

    End Sub






Ejemplo de como crear y asignar un SuperTooltipInfo

Código (vbnet) [Seleccionar]
        ' DotNetBar [SuperTooltipInfo] Example to create a new SuperTooltipInfo.
        ' ( By Elektro )
        '
        ' Instructions:
        ' 1. Add a reference to 'DevComponents.DotNetBar.dll'.
        ' 2. Add a 'SuperToolTip' control in the Designer.

        ' SuperTooltipInfo type describes Super-Tooltip
        Dim superTooltip As New SuperTooltipInfo()

        With superTooltip

            .HeaderText = "Header text"
            .BodyText = "Body text with <strong>text-markup</strong> support. Header and footer support text-markup too."
            .FooterText = "My footer text"

        End With

        ' Assign tooltip to a control or DotNetBar component
        SuperTooltip1.SetSuperTooltip(TextBox1, superTooltip)

        ' To remove tooltip from a control or component use
        '  SuperTooltip1.SetSuperTooltip(TextBox1, Nothing)





Ejemplo de como crear y mostrar un ContextMenu.

Código (vbnet) [Seleccionar]
    ' DotNetBar [ContextMenuBar] Create a new ContextMenu.
    ' ( By Elektro )
    '
    ' Instructions:
    ' 1. Add a reference to 'DevComponents.DotNetBar.dll'.

    Private Sub Test() Handles MyBase.Shown

        ' Create context menu item that is assigned to controls or items
        Dim ContextMenu As New ButtonItem("myContextMenuItemName")

        ' Create a Context MenuItem
        Dim MenuItem As New ButtonItem("MenuItemName1")
        MenuItem.Text = "Context MenuItem 1"
        AddHandler MenuItem.Click, AddressOf MenuItemClick

        ' Add item to Context Menu
        ContextMenu.SubItems.Add(MenuItem)

        ' Create second Context MenuItem
        MenuItem = New ButtonItem("MenuItemName2", "Context MenuItem 2")
        AddHandler MenuItem.Click, AddressOf MenuItemClick

        ' Add item to Context Menu
        ContextMenu.SubItems.Add(MenuItem)

        ' Add Context Menu to Context MenuBar
        ContextMenuBar1.Items.Add(ContextMenu)

        ' Assign context menu to text-box
        ContextMenuBar1.SetContextMenuEx(TextBox1, ContextMenu)

    End Sub








Eleкtro

Otro snippet para los controles de DotNetBar, para el 'KeyboardControl' en concreto.

Ejemplo de como crear una un Layout personalizado del teclado.

Código (vbnet) [Seleccionar]
    ' DotNetBar [KeyboardControl] Example to create a Keyboard Layout at execution-time.
    '
    ' Instructions:
    ' 1. Add a reference to 'DevComponents.DotNetBar.dll'.
    ' 2. Add a 'KeyboardControl' control.

    Private Sub Test(sender As Object, e As EventArgs) Handles MyBase.Shown

        ' Set the new Keyboard Layout
        KeyboardControl1.Keyboard = CreateDefaultKeyboard()

    End Sub

    ''' <summary>
    ''' Creates the default keyboard.
    ''' </summary>
    ''' <returns>Keyboard.</returns>
    Public Shared Function CreateDefaultKeyboard() As Keyboard
        Dim keyboard As New Keyboard

        ' Actually there are 4 layout objects,
        ' but for code simplicity this variable is reused for creating each of them.
        Dim kc As LinearKeyboardLayout

        '#Region "Normal style configuration (no modifier keys pressed)"

        kc = New LinearKeyboardLayout()
        keyboard.Layouts.Add(kc)

        kc.AddKey("q")
        kc.AddKey("w")
        kc.AddKey("e")
        kc.AddKey("r")
        kc.AddKey("t")
        kc.AddKey("y")
        kc.AddKey("u")
        kc.AddKey("i")
        kc.AddKey("o")
        kc.AddKey("p")
        kc.AddKey("Backspace", info:="{BACKSPACE}", width:=21)

        kc.AddLine()
        kc.AddSpace(4)

        kc.AddKey("a")
        kc.AddKey("s")
        kc.AddKey("d")
        kc.AddKey("f")
        kc.AddKey("g")
        kc.AddKey("h")
        kc.AddKey("j")
        kc.AddKey("k")
        kc.AddKey("l")
        kc.AddKey("'")
        kc.AddKey("Enter", info:="{ENTER}", width:=17)

        kc.AddLine()

        kc.AddKey("Shift", info:="", style:=KeyStyle.Dark, layout:=1)
        kc.AddKey("z")
        kc.AddKey("x")
        kc.AddKey("c")
        kc.AddKey("v")
        kc.AddKey("b")
        kc.AddKey("n")
        kc.AddKey("m")
        kc.AddKey(",")
        kc.AddKey(".")
        kc.AddKey("?")
        kc.AddKey("Shift", info:="", style:=KeyStyle.Dark, layout:=1)

        kc.AddLine()

        kc.AddKey("Ctrl", info:="", style:=KeyStyle.Dark, layout:=2)
        kc.AddKey("&123", info:="", style:=KeyStyle.Dark, layout:=3)
        kc.AddKey(":-)", info:=":-{)}", style:=KeyStyle.Dark)
        'kc.AddKey("Alt", info: "%", style: KeyStyle.Dark);
        kc.AddKey(" ", width:=76)
        kc.AddKey("<", info:="{LEFT}", style:=KeyStyle.Dark)
        kc.AddKey(">", info:="{RIGHT}", style:=KeyStyle.Dark)

        '#End Region

        '#Region "Shift modifier pressed"

        kc = New LinearKeyboardLayout()
        keyboard.Layouts.Add(kc)

        kc.AddKey("Q", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("W", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("E", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("R", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("T", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("Y", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("U", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("I", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("O", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("P", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("Backspace", info:="{BACKSPACE}", width:=21)

        kc.AddLine()
        kc.AddSpace(4)

        kc.AddKey("A", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("S", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("D", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("F", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("G", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("H", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("J", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("K", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("L", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("""", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("Enter", info:="{ENTER}", width:=17)

        kc.AddLine()

        kc.AddKey("Shift", info:="", style:=KeyStyle.Pressed, layout:=0, layoutEx:=4)
        kc.AddKey("Z", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("X", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("C", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("V", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("B", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("N", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("M", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(";", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(":", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("!", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("Shift", info:="", style:=KeyStyle.Pressed, layout:=0, layoutEx:=4)

        kc.AddLine()

        kc.AddKey("Ctrl", info:="", style:=KeyStyle.Dark, layout:=2)
        kc.AddKey("&123", info:="", style:=KeyStyle.Dark, layout:=3)
        kc.AddKey(":-)", info:=":-{)}", style:=KeyStyle.Dark, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(" ", width:=76, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("<", info:="+{LEFT}", style:=KeyStyle.Dark, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(">", info:="+{RIGHT}", style:=KeyStyle.Dark, layout:=KeyboardLayout.PreviousLayout)

        '#End Region

        '#Region "Ctrl modifier pressed"

        kc = New LinearKeyboardLayout()
        keyboard.Layouts.Add(kc)

        kc.AddKey("q", info:="^q", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("w", info:="^w", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("e", info:="^e", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("r", info:="^r", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("t", info:="^t", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("y", info:="^y", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("u", info:="^u", hint:="Underline", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("i", info:="^i", hint:="Italic", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("o", info:="^o", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("p", info:="^p", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("Backspace", info:="^{BACKSPACE}", width:=21, layout:=KeyboardLayout.PreviousLayout)

        kc.AddLine()
        kc.AddSpace(4)

        kc.AddKey("a", info:="^a", hint:="Select all", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("s", info:="^s", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("d", info:="^d", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("f", info:="^f", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("g", info:="^g", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("h", info:="^h", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("j", info:="^j", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("k", info:="^k", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("l", info:="^l", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("'", info:="^'", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("Enter", info:="^{ENTER}", width:=17, layout:=KeyboardLayout.PreviousLayout)

        kc.AddLine()

        kc.AddKey("Shift", info:="", layout:=1)
        kc.AddKey("z", info:="^z", hint:="Undo", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("x", info:="^x", hint:="Cut", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("c", info:="^c", hint:="Copy", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("v", info:="^v", hint:="Paste", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("b", info:="^b", hint:="Bold", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("n", info:="^n", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("m", info:="^m", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(",", info:="^,", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(".", info:="^.", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("?", info:="^?", layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("Shift", info:="", layout:=1)

        kc.AddLine()

        kc.AddKey("Ctrl", info:="", style:=KeyStyle.Pressed, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("&123", info:="", style:=KeyStyle.Dark, layout:=3)
        kc.AddKey(":-)", info:="^:-{)}", style:=KeyStyle.Dark, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(" ", info:="^ ", width:=76, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("<", info:="^{LEFT}", style:=KeyStyle.Dark, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(">", info:="^{RIGHT}", style:=KeyStyle.Dark, layout:=KeyboardLayout.PreviousLayout)

        '#End Region

        '#Region "Symbols and numbers (&123) modifier pressed"

        kc = New LinearKeyboardLayout()
        keyboard.Layouts.Add(kc)

        kc.AddKey("!")
        kc.AddKey("@")
        kc.AddKey("#")
        kc.AddKey("$")
        kc.AddKey("½")
        kc.AddKey("-")
        kc.AddKey("+", info:="{+}")

        kc.AddSpace(5)

        kc.AddKey("1", style:=KeyStyle.Light)
        kc.AddKey("2", style:=KeyStyle.Light)
        kc.AddKey("3", style:=KeyStyle.Light)

        kc.AddSpace(5)

        kc.AddKey("Bcks", info:="{BACKSPACE}", style:=KeyStyle.Dark)

        kc.AddLine()

        ' second line
        kc.AddKey(";")
        kc.AddKey(":")
        kc.AddKey("""")
        kc.AddKey("%", info:="{%}")
        kc.AddKey("&")
        kc.AddKey("/")
        kc.AddKey("*")

        kc.AddSpace(5)

        kc.AddKey("4", style:=KeyStyle.Light)
        kc.AddKey("5", style:=KeyStyle.Light)
        kc.AddKey("6", style:=KeyStyle.Light)

        kc.AddSpace(5)

        kc.AddKey("Enter", info:="{ENTER}", style:=KeyStyle.Dark)

        kc.AddLine()

        ' third line
        kc.AddKey("(", info:="{(}")
        kc.AddKey(")", info:="{)}")
        kc.AddKey("[", info:="{[}")
        kc.AddKey("]", info:="{]}")
        kc.AddKey("_")
        kc.AddKey("\")
        kc.AddKey("=")

        kc.AddSpace(5)

        kc.AddKey("7", style:=KeyStyle.Light)
        kc.AddKey("8", style:=KeyStyle.Light)
        kc.AddKey("9", style:=KeyStyle.Light)

        kc.AddSpace(5)

        kc.AddKey("Tab", info:="{TAB}", style:=KeyStyle.Dark)

        kc.AddLine()

        ' forth line
        kc.AddKey("...", style:=KeyStyle.Dark, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey("&123", info:="", style:=KeyStyle.Pressed, layout:=KeyboardLayout.PreviousLayout)
        kc.AddKey(":-)", info:=":-{)}", style:=KeyStyle.Dark)
        kc.AddKey("<", info:="{LEFT}", style:=KeyStyle.Dark)
        kc.AddKey(">", info:="{RIGHT}", style:=KeyStyle.Dark)
        kc.AddKey("Space", info:="^ ", width:=21)

        kc.AddSpace(5)

        kc.AddKey("0", style:=KeyStyle.Light, width:=21)
        kc.AddKey(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, style:=KeyStyle.Dark)

        kc.AddSpace(5)

        kc.AddLine()

        '#End Region

        '#Region "Shift modifier toggled"

        kc = New LinearKeyboardLayout()
        keyboard.Layouts.Add(kc)

        kc.AddKey("Q")
        kc.AddKey("W")
        kc.AddKey("E")
        kc.AddKey("R")
        kc.AddKey("T")
        kc.AddKey("Y")
        kc.AddKey("U")
        kc.AddKey("I")
        kc.AddKey("O")
        kc.AddKey("P")
        kc.AddKey("Backspace", info:="{BACKSPACE}", width:=21)

        kc.AddLine()
        kc.AddSpace(4)

        kc.AddKey("A")
        kc.AddKey("S")
        kc.AddKey("D")
        kc.AddKey("F")
        kc.AddKey("G")
        kc.AddKey("H")
        kc.AddKey("J")
        kc.AddKey("K")
        kc.AddKey("L")
        kc.AddKey("'")
        kc.AddKey("Enter", info:="{ENTER}", width:=17)

        kc.AddLine()

        kc.AddKey("Shift", info:="", style:=KeyStyle.Toggled, layout:=0)
        kc.AddKey("Z")
        kc.AddKey("X")
        kc.AddKey("C")
        kc.AddKey("V")
        kc.AddKey("B")
        kc.AddKey("N")
        kc.AddKey("M")
        kc.AddKey(",")
        kc.AddKey(".")
        kc.AddKey("?")
        kc.AddKey("Shift", info:="", style:=KeyStyle.Toggled, layout:=0)

        kc.AddLine()

        kc.AddKey("Ctrl", info:="", style:=KeyStyle.Dark, layout:=2)
        kc.AddKey("&123", info:="", style:=KeyStyle.Dark, layout:=3)
        kc.AddKey(":-)", info:=":-{)}", style:=KeyStyle.Dark)
        kc.AddKey(" ", width:=76)
        kc.AddKey("<", info:="+{LEFT}", style:=KeyStyle.Dark)
        kc.AddKey(">", info:="+{RIGHT}", style:=KeyStyle.Dark)

        '#End Region

        Return keyboard

    End Function








Eleкtro

#368
RecycleBin Manager (Versión mejorada ...y acabada)

Un ayudante para obtener información sobre la papelera de reciclaje principal o el resto de papeleras así como de los elementos eliminados,
además de realizar otras operaciones como eliminar permanentemente o deshacer la eliminación (invocando verbos).

Aquí pueden ver el código ~> http://pastebin.com/eRync5pA


Índice de miembros públicos:
Código (vbnet) [Seleccionar]
' ----------
' Properties
' ----------
'
' MainBin.Files
' MainBin.Folders
' MainBin.Items
' MainBin.ItemsCount
' MainBin.LastDeletedFile
' MainBin.LastDeletedFolder
' MainBin.LastDeletedItem
' MainBin.Size

' -------
' Methods
' -------
'
' MainBin.Empty()
' MainBin.RefreshIcon()
'
' Tools.Empty()
' Tools.GetSize()
' Tools.GetDeletedFiles()
' Tools.GetDeletedFolders()
' Tools.GetDeletedItems()
' Tools.GetItemsCount()
' Tools.GetLastDeletedFile()
' Tools.GetLastDeletedFolder()
' Tools.GetLastDeletedItem()
' Tools.DeleteItem
' Tools.UndeleteItem
' Tools.InvokeItemVerb



Ejemplos de uso:

1.
Código (vbnet) [Seleccionar]
    ' Empties all the Recycle Bins.
    RecycleBinManager.MainBin.Empty()

    ' Empties the Recycle Bin of the "E" drive.
    RecycleBinManager.Tools.Empty("E", RecycleBinManager.Tools.RecycleBinFlags.DontShowConfirmation)

    ' Updates the Main Recycle Bin icon.
    RecycleBinManager.MainBin.RefreshIcon()


    ' Gets the accumulated size (in bytes) of the Main Recycle Bin.
    Dim RecycledSize As Long = RecycleBinManager.MainBin.Size

    ' Gets the accumulated size (in bytes) of the Recycle Bin on "E" drive.
    Dim RecycledSizeE As Long = RecycleBinManager.Tools.GetSize("E")


    ' Gets the total deleted items count of the Main recycle bin.
    Dim RecycledItemsCount As Long = RecycleBinManager.MainBin.ItemsCount

    ' Gets the total deleted items count of the Recycle Bin on "E" drive.
    Dim RecycledItemsCountE As Long = RecycleBinManager.Tools.GetDeletedItems("E").Count


    ' Get all the deleted items inside the Main Recycle Bin.
    Dim RecycledItems As ShellObject() = RecycleBinManager.MainBin.Items

    ' Get all the deleted files inside the Main Recycle Bin.
    Dim RecycledFiles As ShellFile() = RecycleBinManager.MainBin.Files

    ' Get all the deleted folders inside the Main Recycle Bin.
    Dim RecycledFolders As ShellFolder() = RecycleBinManager.MainBin.Folders


    ' Get all the deleted items inside the Recycle Bin on "E" drive.
    Dim RecycledItemsE As ShellObject() = RecycleBinManager.Tools.GetDeletedItems("E")

    ' Get all the deleted files inside the Recycle Bin on "E" drive.
    Dim RecycledFilesE As ShellFile() = RecycleBinManager.Tools.GetDeletedFiles("E")

    ' Get all the deleted folders inside the Recycle Bin on "E" drive.
    Dim RecycledFoldersE As ShellFolder() = RecycleBinManager.Tools.GetDeletedFolders("E")


    ' Gets the Last deleted Item inside the Main Recycle Bin.
    MsgBox(RecycleBinManager.MainBin.LastDeletedItem.Name)

    ' Gets the Last deleted Item inside the Recycle Bin on "E" drive
    MsgBox(RecycleBinManager.Tools.GetLastDeletedItem("E").Name)


    ' Undeletes an item.
    RecycleBinManager.Tools.UndeleteItem(RecycleBinManager.MainBin.LastDeletedItem)

    ' Permanently deletes an item.
    RecycleBinManager.Tools.DeleteItem(RecycleBinManager.MainBin.LastDeletedItem)

    ' Invokes an Item-Verb
    RecycleBinManager.Tools.InvokeItemVerb(RecycleBinManager.MainBin.LastDeletedItem, "properties")


2.
Código (vbnet) [Seleccionar]
    Private Sub Test() Handles MyBase.Shown

        Dim sb As New System.Text.StringBuilder

        ' Get all the deleted items inside all the Recycle Bins.
        Dim RecycledItems As ShellObject() = RecycleBinManager.MainBin.Items

        ' Loop through the deleted Items (Ordered by las deleted).
        For Each Item As ShellFile In (From itm In RecycledItems
                                       Order By itm.Properties.GetProperty("System.Recycle.DateDeleted").ValueAsObject
                                       Descending)

            ' Append the property bags information.
            sb.AppendLine(String.Format("Full Name....: {0}",
                                        Item.Name))

            sb.AppendLine(String.Format("Item Name....: {0}",
                                        Item.Properties.System.ItemNameDisplay.Value))

            sb.AppendLine(String.Format("Deleted From.: {0}",
                                        Item.Properties.GetProperty("System.Recycle.DeletedFrom").ValueAsObject))

            sb.AppendLine(String.Format("Item Type....: {0}",
                                       Item.Properties.System.ItemTypeText.Value))

            sb.AppendLine(String.Format("Item Size....: {0}",
                                        CStr(Item.Properties.System.Size.Value)))

            sb.AppendLine(String.Format("Attributes...: {0}",
                                        [Enum].Parse(GetType(IO.FileAttributes),
                                                     Item.Properties.System.FileAttributes.Value).ToString))

            sb.AppendLine(String.Format("Date Deleted.: {0}",
                                        Item.Properties.GetProperty("System.Recycle.DateDeleted").ValueAsObject))

            sb.AppendLine(String.Format("Date Modified: {0}",
                                        CStr(Item.Properties.System.DateModified.Value)))

            sb.AppendLine(String.Format("Date Created.: {0}",
                                        CStr(Item.Properties.System.DateCreated.Value)))

            MsgBox(sb.ToString)
            sb.Clear()

        Next Item

    End Sub








Eleкtro

#369
Dado una colección de números, devuelve todos los números que no están dentro de un rango especificado.

Código (vbnet) [Seleccionar]
    ' Get Numbers Not In Range.
    ' ( By Elektro )
    '
    ' Usage Examples:
    '
    ' MsgBox(String.Join(", ", GetNumbersNotInRange({1, 3, 5, 7, 9}, 0, 10).ToArray)) ' Result: 0, 2, 4, 6, 8, 10
    '
    ''' <summary>
    ''' Given a numeric collection, gets all the numbers which are not in a specified range.
    ''' </summary>
    ''' <param name="NumbersInRange">Indicates the numbers collection which are in range.</param>
    ''' <param name="MinRange">Indicates the minimum range.</param>
    ''' <param name="MaxRange">Indicates the maximum range.</param>
    ''' <returns>System.Collections.Generic.IEnumerable(Of System.Int32).</returns>
    Private Function GetNumbersNotInRange(ByVal NumbersInRange As IEnumerable(Of Integer),
                                          ByVal MinRange As Integer,
                                          ByVal MaxRange As Integer) As IEnumerable(Of Integer)

        Return From Number As Integer
               In Enumerable.Range(MinRange, MaxRange + 1)
               Where Not NumbersInRange.Contains(Number)

    End Function