elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)
0 Usuarios y 2 Visitantes están viendo este tema.
Páginas: 1 ... 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [26] 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 ... 58 Ir Abajo Respuesta Imprimir
Autor Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)  (Leído 480,143 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #250 en: 6 Julio 2013, 05:56 am »

Un RichTextBox optimizado para usarse como alternativa de Label , es un Label con posibilidad de añadir texto en distintos colores y en distintas fuentes.



Código
  1. '  /*               *\
  2. ' |#* RichTextLabel *#|
  3. '  \*               */
  4. '
  5. ' // By Elektro H@cker
  6. '
  7. '   Description:
  8. '   ............
  9. ' · A RichTextbox used as a Label to set text using various colors.
  10. '
  11. '   Methods:
  12. '   ........
  13. ' · AppendText (Overload)
  14.  
  15. ' Examples:
  16. ' RichTextLabel1.AppendText("My ", Color.White, , New Font("Arial", 12, FontStyle.Bold))
  17. ' RichTextLabel1.AppendText("RichText-", Color.White, , New Font("Arial", 12, FontStyle.Bold))
  18. ' RichTextLabel1.AppendText("Label", Color.YellowGreen, Color.Black, New Font("Lucida console", 16, FontStyle.Italic))
  19.  
  20. Imports System.ComponentModel
  21.  
  22. Public Class RichTextLabel : Inherits RichTextBox
  23.  
  24.    Public Sub New()
  25.        MyBase.Enabled = False
  26.        MyBase.Size = New Point(200, 20)
  27.    End Sub
  28.  
  29. #Region " Overrided Properties "
  30.  
  31.    ''' <summary>
  32.    ''' Turn the control backcolor to transparent.
  33.    ''' </summary>
  34.    Protected Overrides ReadOnly Property CreateParams() As CreateParams
  35.        Get
  36.            Dim cp As CreateParams = MyBase.CreateParams
  37.            cp.ExStyle = (cp.ExStyle Or 32)
  38.            Return cp
  39.        End Get
  40.    End Property
  41.  
  42. #End Region
  43.  
  44. #Region " Shadowed Properties "
  45.  
  46.    ' AcceptsTab
  47.    ' Just hidden from the designer and editor.
  48.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  49.    Public Shadows Property AcceptsTab() As Boolean
  50.        Get
  51.            Return MyBase.AcceptsTab
  52.        End Get
  53.        Set(value As Boolean)
  54.            MyBase.AcceptsTab = False
  55.        End Set
  56.    End Property
  57.  
  58.    ' AutoWordSelection
  59.    ' Just hidden from the designer and editor.
  60.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  61.    Public Shadows Property AutoWordSelection() As Boolean
  62.        Get
  63.            Return MyBase.AutoWordSelection
  64.        End Get
  65.        Set(value As Boolean)
  66.            MyBase.AutoWordSelection = False
  67.        End Set
  68.    End Property
  69.  
  70.    ' BackColor
  71.    ' Not hidden, but little hardcoded 'cause the createparams transparency.
  72.    <Browsable(True), EditorBrowsable(EditorBrowsableState.Always)>
  73.    Public Shadows Property BackColor() As Color
  74.        Get
  75.            Return MyBase.BackColor
  76.        End Get
  77.        Set(value As Color)
  78.            MyBase.SelectionStart = 0
  79.            MyBase.SelectionLength = MyBase.TextLength
  80.            MyBase.SelectionBackColor = value
  81.            MyBase.BackColor = value
  82.        End Set
  83.    End Property
  84.  
  85.    ' BorderStyle
  86.    ' Just hidden from the designer and editor.
  87.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  88.    Public Shadows Property BorderStyle() As BorderStyle
  89.        Get
  90.            Return MyBase.BorderStyle
  91.        End Get
  92.        Set(value As BorderStyle)
  93.            MyBase.BorderStyle = BorderStyle.None
  94.        End Set
  95.    End Property
  96.  
  97.    ' Cursor
  98.    ' Hidden from the designer and editor,
  99.    ' because while the control is disabled the cursor always be the default even if changed.
  100.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  101.    Public Shadows Property Cursor() As Cursor
  102.        Get
  103.            Return MyBase.Cursor
  104.        End Get
  105.        Set(value As Cursor)
  106.            MyBase.Cursor = Cursors.Default
  107.        End Set
  108.    End Property
  109.  
  110.    ' Enabled
  111.    ' Hidden from the but not from the editor,
  112.    ' because to prevent exceptions when doing loops over a control collection to disable/enable controls.
  113.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Always)>
  114.    Public Shadows Property Enabled() As Boolean
  115.        Get
  116.            Return MyBase.Enabled
  117.        End Get
  118.        Set(value As Boolean)
  119.            MyBase.Enabled = False
  120.        End Set
  121.    End Property
  122.  
  123.    ' HideSelection
  124.    ' Just hidden from the designer and editor.
  125.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  126.    Public Shadows Property HideSelection() As Boolean
  127.        Get
  128.            Return MyBase.HideSelection
  129.        End Get
  130.        Set(value As Boolean)
  131.            MyBase.HideSelection = True
  132.        End Set
  133.    End Property
  134.  
  135.    ' MaxLength
  136.    ' Just hidden from the designer and editor.
  137.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  138.    Public Shadows Property MaxLength() As Integer
  139.        Get
  140.            Return MyBase.MaxLength
  141.        End Get
  142.        Set(value As Integer)
  143.            MyBase.MaxLength = 2147483646
  144.        End Set
  145.    End Property
  146.  
  147.    ' ReadOnly
  148.    ' Just hidden from the designer and editor.
  149.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  150.    Public Shadows Property [ReadOnly]() As Boolean
  151.        Get
  152.            Return MyBase.ReadOnly
  153.        End Get
  154.        Set(value As Boolean)
  155.            MyBase.ReadOnly = True
  156.        End Set
  157.    End Property
  158.  
  159.    ' ScrollBars
  160.    ' Just hidden from the designer and editor.
  161.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  162.    Public Shadows Property ScrollBars() As RichTextBoxScrollBars
  163.        Get
  164.            Return MyBase.ScrollBars
  165.        End Get
  166.        Set(value As RichTextBoxScrollBars)
  167.            MyBase.ScrollBars = RichTextBoxScrollBars.None
  168.        End Set
  169.    End Property
  170.  
  171.    ' ShowSelectionMargin
  172.    ' Just hidden from the designer and editor.
  173.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  174.    Public Shadows Property ShowSelectionMargin() As Boolean
  175.        Get
  176.            Return MyBase.ShowSelectionMargin
  177.        End Get
  178.        Set(value As Boolean)
  179.            MyBase.ShowSelectionMargin = False
  180.        End Set
  181.    End Property
  182.  
  183.    ' TabStop
  184.    ' Just hidden from the designer and editor.
  185.    <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
  186.    Public Shadows Property TabStop() As Boolean
  187.        Get
  188.            Return MyBase.TabStop
  189.        End Get
  190.        Set(value As Boolean)
  191.            MyBase.TabStop = False
  192.        End Set
  193.    End Property
  194.  
  195. #End Region
  196.  
  197. #Region " Funcs & Procs "
  198.  
  199.    ''' <summary>
  200.    ''' Append text to the current text.
  201.    ''' </summary>
  202.    ''' <param name="text">The text to append</param>
  203.    ''' <param name="forecolor">The font color</param>
  204.    ''' <param name="backcolor">The Background color</param>
  205.    ''' <param name="font">The font of the appended text</param>
  206.    Public Overloads Sub AppendText(ByVal text As String, _
  207.                          ByVal forecolor As Color, _
  208.                          Optional ByVal backcolor As Color = Nothing, _
  209.                          Optional ByVal font As Font = Nothing)
  210.  
  211.        Dim index As Int32 = MyBase.TextLength
  212.        MyBase.AppendText(text)
  213.        MyBase.SelectionStart = index
  214.        MyBase.SelectionLength = MyBase.TextLength - index
  215.        MyBase.SelectionColor = forecolor
  216.  
  217.        If Not backcolor = Nothing _
  218.        Then MyBase.SelectionBackColor = backcolor _
  219.        Else MyBase.SelectionBackColor = DefaultBackColor
  220.  
  221.        If font IsNot Nothing Then MyBase.SelectionFont = font
  222.  
  223.        ' Reset selection
  224.        MyBase.SelectionStart = MyBase.TextLength
  225.        MyBase.SelectionLength = 0
  226.  
  227.    End Sub
  228.  
  229. #End Region
  230.  
  231. End Class


« Última modificación: 6 Julio 2013, 07:52 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #251 en: 6 Julio 2013, 09:22 am »

Una Class que hice para manejar las API's del Caret.



Código
  1. #Region " Caret "
  2.  
  3. ' [ Caret Class ]
  4. '
  5. ' // By Elektro H@cker
  6. '
  7. ' Examples:
  8. ' Dim bmp As New Bitmap("C:\Image.jpg")
  9. ' Caret.Create(TextBox1, 7)
  10. ' Caret.Create(TextBox1, bmp, 20)
  11. ' Caret.BlinkTime(500)
  12. ' Caret.Hide(TextBox1)
  13. ' Caret.Show(TextBox1)
  14. ' Caret.Destroy()
  15.  
  16. Public Class Caret
  17.  
  18. #Region " API's "
  19.  
  20.    Private Declare Function CreateCaret Lib "user32" (ByVal hwnd As IntPtr, ByVal hBitmap As IntPtr, ByVal nWidth As Int64, ByVal nHeight As Int64) As Int64
  21.    Private Declare Function HideCaret Lib "user32" (ByVal hwnd As IntPtr) As Int64
  22.    Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As IntPtr) As Int64
  23.    Private Declare Function SetCaretBlinkTime Lib "user32" (ByVal wMSeconds As Int64) As Int64
  24.    Private Declare Function SetCaretPos Lib "user32" (ByVal x As Int64, ByVal y As Int64) As Int64
  25.    Private Declare Function DestroyCaret Lib "user32" () As Int64
  26.  
  27. #End Region
  28.  
  29. #Region " Funcs & Procs "
  30.  
  31.    ''' <summary>
  32.    ''' Create a new caret.
  33.    ''' </summary>
  34.    ''' <param name="ctrl">The name of the control.</param>
  35.    ''' <param name="Width">The Width of the caret cursor.</param>
  36.    ''' <param name="Height">The name of the caret cursor.</param>
  37.    Public Shared Sub Create(ByVal ctrl As Control, _
  38.                             ByVal Width As Int32, _
  39.                             Optional ByVal Height As Int32 = 0)
  40.  
  41.        If Height = 0 Then
  42.            CreateCaret(ctrl.Handle, IntPtr.Zero, Width, (ctrl.Font.Size * 2))
  43.        Else
  44.            CreateCaret(ctrl.Handle, IntPtr.Zero, Width, Height)
  45.        End If
  46.  
  47.        Show(ctrl)
  48.  
  49.    End Sub
  50.  
  51.    ''' <summary>
  52.    ''' Create a new caret with Bitmap image.
  53.    ''' </summary>
  54.    ''' <param name="ctrl">The name of the control.</param>
  55.    ''' <param name="bmp">The Bitmap image to use.</param>
  56.    ''' <param name="Width">The Width of the caret cursor.</param>
  57.    ''' <param name="Height">The name of the caret cursor.</param>
  58.    Public Shared Sub Create(ByVal ctrl As Control, _
  59.                             ByVal bmp As Bitmap, _
  60.                             ByVal Width As Int32, _
  61.                             Optional ByVal Height As Int32 = 0)
  62.  
  63.  
  64.        If Height = 0 Then
  65.            bmp = Resize_Bitmap(bmp, Width, (ctrl.Font.Size * 2))
  66.            CreateCaret(ctrl.Handle, bmp.GetHbitmap, Width, (ctrl.Font.Size * 2))
  67.        Else
  68.            bmp = Resize_Bitmap(bmp, Width, Height)
  69.            CreateCaret(ctrl.Handle, bmp.GetHbitmap, Width, Height)
  70.        End If
  71.  
  72.        Show(ctrl)
  73.  
  74.    End Sub
  75.  
  76.    ''' <summary>
  77.    ''' Hide the caret.
  78.    ''' </summary>
  79.    ''' <param name="ctrl">The name of the control.</param>
  80.    Public Shared Sub Hide(ByVal ctrl As Control)
  81.        HideCaret(ctrl.Handle)
  82.    End Sub
  83.  
  84.    ''' <summary>
  85.    ''' Show the caret.
  86.    ''' </summary>
  87.    ''' <param name="ctrl">The name of the control.</param>
  88.    Public Shared Sub Show(ByVal ctrl As Control)
  89.        ShowCaret(ctrl.Handle)
  90.    End Sub
  91.  
  92.    ''' <summary>
  93.    ''' Set the blinking time of the caret.
  94.    ''' </summary>
  95.    ''' <param name="ms">Blink interval in Milliseconds.</param>
  96.    Public Shared Sub BlinkTime(ByVal ms As Int64)
  97.        SetCaretBlinkTime(ms)
  98.    End Sub
  99.  
  100.    ''' <summary>
  101.    ''' Set the position of the caret.
  102.    ''' </summary>
  103.    ''' <param name="x">X coordinate.</param>
  104.    ''' <param name="y">Y coordinate.</param>
  105.    Public Shared Sub Position(ByVal X As Int32, ByVal Y As Int32)
  106.        SetCaretPos(X, Y)
  107.    End Sub
  108.  
  109.    ''' <summary>
  110.    ''' Destroy the caret.
  111.    ''' </summary>
  112.    Public Shared Sub Destroy()
  113.        DestroyCaret()
  114.    End Sub
  115.  
  116.    ' Resizes a Bitmap Image
  117.    Private Shared Function Resize_Bitmap(ByVal bmp As Bitmap, ByVal Width As Int32, ByVal Height As Int32) As Bitmap
  118.        Dim Bitmap_Source As New Bitmap(bmp)
  119.        Dim Bitmap_Dest As New Bitmap(CInt(Width), CInt(Height))
  120.        Dim Graphic As Graphics = Graphics.FromImage(Bitmap_Dest)
  121.        Graphic.DrawImage(Bitmap_Source, 0, 0, Bitmap_Dest.Width + 1, Bitmap_Dest.Height + 1)
  122.        Return Bitmap_Dest
  123.    End Function
  124.  
  125. #End Region
  126.  
  127. End Class
  128.  
  129. #End Region


« Última modificación: 6 Julio 2013, 09:36 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #252 en: 7 Julio 2013, 21:53 pm »

Validar una fecha:

Código
  1. #Region " Validate Date "
  2.  
  3.    ' [ Validate Date Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(Validate_Date("29-02-2013")) ' Result: False
  10.    ' MsgBox(Validate_Date("29-02-2016")) ' Result: True
  11.    ' MsgBox(Validate_Date("01/01/2014")) ' Result: True
  12.  
  13.    Private Function Validate_Date(ByVal [Date] As String) As Boolean
  14.        Return Date.TryParse([Date], New Date)
  15.    End Function
  16.  
  17. #End Region

PD: @Novlucker, sé que es muy cortito, pero útil para quien no sepa! :P
« Última modificación: 8 Julio 2013, 12:50 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #253 en: 10 Julio 2013, 20:30 pm »

Integración para deshacer/rehacer (Undo/Redo) para estos controles:

Código:
   TextBox
    ComboBox
    DateTimePicker
    NumericUpDown
    MaskedTextBox
    ListBox (single and multi-select)
    CheckBox
    RadioButton
    MonthCalendar


INSTRUCCIONES:
1. copiar las siguientes classes en el proyecto:


Código
  1. '******************************************************************************************************************
  2. ' Undo/Redo framework (c) Copyright 2009 Etienne Nijboer
  3. '******************************************************************************************************************
  4.  
  5. Public Enum UndoRedoCommandType
  6.    ctNone
  7.    ctUndo
  8.    ctRedo
  9. End Enum
  10.  
  11. Public Class UndoRedoManager
  12.  
  13. #Region "UndoRedoMonitor auto register types"
  14.  
  15.    Private Shared RegisteredUndoRedoMonitorTypes As List(Of Type) = Nothing
  16.  
  17.    ' ScanAssembly
  18.    ' The first created UndoRedoMonitor will scan the assembly for BaseUndoRedoMonitors and
  19.    ' store these types in the monitor type list.
  20.    '
  21.    Private Shared Sub ScanAssembly()
  22.        If RegisteredUndoRedoMonitorTypes Is Nothing Then
  23.            RegisteredUndoRedoMonitorTypes = New List(Of Type)
  24.            Dim AssemblyTypes() As Type = Reflection.Assembly.GetExecutingAssembly().GetTypes()
  25.            Dim BaseUndoRedoMonitorType As Type = GetType(BaseUndoRedoMonitor)
  26.            For Each typeItem As Type In AssemblyTypes
  27.                If typeItem.BaseType Is BaseUndoRedoMonitorType Then
  28.                    RegisteredUndoRedoMonitorTypes.Add(typeItem)
  29.                End If
  30.            Next
  31.        End If
  32.    End Sub
  33.  
  34. #End Region
  35.  
  36.    Private Control As Control = Nothing
  37.    Private UndoRedoMonitors As List(Of BaseUndoRedoMonitor)
  38.    Private ExcludeControls As List(Of Control)
  39.  
  40.    ' InitializeUndoRedoMonitors
  41.    ' When a new UndoRedoManager instance is created, a new instance of each registered monitor
  42.    ' is created and used only within the scope of this UndoRedoManager, preventing temporary data
  43.    ' moved to another UndoRedoManager. This is because Each form, or group control like a panel
  44.    ' to make seperate undo/redo groups on a single form, can have it's own UndoRedoManager. It is
  45.    ' of course also possible to use one global UndoRedoManager for multiple forms. This lets you
  46.    ' control how data is seperated or combined, depending on the relation between te undo/redo commands.
  47.    Private Sub InitializeUndoRedoMonitors()
  48.        ScanAssembly()
  49.        UndoRedoMonitors = New List(Of BaseUndoRedoMonitor)
  50.        For Each typeItem In RegisteredUndoRedoMonitorTypes
  51.            UndoRedoMonitors.Add(Activator.CreateInstance(typeItem, Me))
  52.        Next
  53.    End Sub
  54.  
  55.    Public Sub New()
  56.        InitializeUndoRedoMonitors()
  57.    End Sub
  58.  
  59.    Public Sub New(ByVal AControl As Control)
  60.        Me.New(AControl, New List(Of Control))
  61.    End Sub
  62.  
  63.    Public Sub New(ByVal AControl As Control, ByVal AExcludeControls As List(Of Control))
  64.        Me.New()
  65.        ExcludeControls = AExcludeControls
  66.        MonitorControl(AControl)
  67.    End Sub
  68.  
  69.    Public Sub New(ByVal AControl As Control, ByVal ParamArray AExcludeControls() As Control)
  70.        Me.New(AControl, AExcludeControls.ToList)
  71.    End Sub
  72.  
  73.    ' MonitorControl
  74.    ' If a given control is not in the list of controls to exclude from undo/redo actions,
  75.    ' an attempt is made to attach it to a matching UndoRedoMonitor. If no direct match is
  76.    ' found, a same attempt is made for each control contained within the control recursively.
  77.    Private Sub MonitorControl(ByVal AControl As Control)
  78.        If Not ExcludeControls.Contains(AControl) Then
  79.            If Not BindMonitor(AControl) Then
  80.                For Each ctl As Control In AControl.Controls
  81.                    MonitorControl(ctl)
  82.                Next
  83.            End If
  84.        End If
  85.    End Sub
  86.  
  87.    ' BindMonitor
  88.    ' An attempt is made to bind the control to a each registered monitor. When a match is  
  89.    ' found the search ends and the function will return true, false otherwise meaning there
  90.    ' is no specific UndoRedoMonitor for this control.
  91.    Private Function BindMonitor(ByVal AControl As Control) As Boolean
  92.        Dim index As Integer = UndoRedoMonitors.Count - 1, result As Boolean = False
  93.        While index >= 0 And Not result
  94.            result = UndoRedoMonitors(index).Monitor(AControl)
  95.            index -= 1
  96.        End While
  97.        Return result
  98.    End Function
  99.  
  100.    Public Sub Monitor(ByVal AControl As Control)
  101.        MonitorControl(AControl)
  102.    End Sub
  103.  
  104.    Private undoStack As Stack(Of BaseUndoRedoCommand) = New Stack(Of BaseUndoRedoCommand)
  105.    Private redoStack As Stack(Of BaseUndoRedoCommand) = New Stack(Of BaseUndoRedoCommand)
  106.    Private _undoRedoCommand As UndoRedoCommandType = UndoRedoCommandType.ctNone
  107.    Private _canUndo As Boolean = False
  108.    Private _canRedo As Boolean = False
  109.  
  110.    Public Event CanUndoChanged(ByVal Sender As Object, ByVal CanUndo As Boolean)
  111.    Public Event CanRedoChanged(ByVal Sender As Object, ByVal CanRedo As Boolean)
  112.    Public Event UndoRedoStacksChanged(ByVal Sender As Object)
  113.  
  114.    Private Sub UpdateCanUndoRedo()
  115.        Dim isCanUndoChanged As Boolean = Not (undoStack.Count > 0) = _canUndo, _
  116.            isCanRedoChanged As Boolean = Not (redoStack.Count > 0) = _canRedo
  117.        _canUndo = undoStack.Count > 0
  118.        _canRedo = redoStack.Count > 0
  119.        If isCanUndoChanged Then
  120.            RaiseEvent CanUndoChanged(Me, _canUndo)
  121.        End If
  122.        If isCanRedoChanged Then
  123.            RaiseEvent CanRedoChanged(Me, _canRedo)
  124.        End If
  125.        RaiseEvent UndoRedoStacksChanged(Me)
  126.    End Sub
  127.  
  128.    Public ReadOnly Property isUndoing() As Boolean
  129.        Get
  130.            Return _undoRedoCommand = UndoRedoCommandType.ctUndo
  131.        End Get
  132.    End Property
  133.    Public ReadOnly Property isRedoing() As Boolean
  134.        Get
  135.            Return _undoRedoCommand = UndoRedoCommandType.ctRedo
  136.        End Get
  137.    End Property
  138.    Public ReadOnly Property isPerformingUndoRedo() As Boolean
  139.        Get
  140.            Return _undoRedoCommand <> UndoRedoCommandType.ctNone
  141.        End Get
  142.    End Property
  143.  
  144.    Public ReadOnly Property CanUndo() As Boolean
  145.        Get
  146.            Return _canUndo
  147.        End Get
  148.    End Property
  149.  
  150.    Public ReadOnly Property CanRedo() As Boolean
  151.        Get
  152.            Return _canRedo
  153.        End Get
  154.    End Property
  155.  
  156.    Public Sub AddUndoCommand(ByVal UndoRedoCommand As BaseUndoRedoCommand)
  157.        If Not isUndoing Then
  158.            undoStack.Push(UndoRedoCommand)
  159.            If Not isRedoing Then
  160.                redoStack.Clear()
  161.                UpdateCanUndoRedo()
  162.            End If
  163.        End If
  164.    End Sub
  165.  
  166.    Public Sub AddRedoCommand(ByVal UndoRedoCommand As BaseUndoRedoCommand)
  167.        If Not isRedoing Then
  168.            redoStack.Push(UndoRedoCommand)
  169.            If Not isUndoing Then
  170.                UpdateCanUndoRedo()
  171.            End If
  172.        End If
  173.    End Sub
  174.  
  175.    Public Sub AddCommand(ByVal UndoRedoCommandType As UndoRedoCommandType, ByVal UndoRedoCommand As BaseUndoRedoCommand)
  176.        Select Case UndoRedoCommandType
  177.            Case UndoRedoCommandType.ctUndo
  178.                AddUndoCommand(UndoRedoCommand)
  179.            Case UndoRedoCommandType.ctRedo
  180.                AddRedoCommand(UndoRedoCommand)
  181.            Case Else
  182.                Throw New Exception("An undo or redo command could not be accepted.")
  183.        End Select
  184.    End Sub
  185.  
  186.    Public Sub Undo()
  187.        If CanUndo Then
  188.            'Try                
  189.            _undoRedoCommand = UndoRedoCommandType.ctUndo
  190.            undoStack.Pop.Undo()
  191.            'Catch e As Exception
  192.            'Finally
  193.            UpdateCanUndoRedo()
  194.            _undoRedoCommand = UndoRedoCommandType.ctNone
  195.            'End Try
  196.        End If
  197.    End Sub
  198.  
  199.    Public Sub Redo()
  200.        If CanRedo Then
  201.            _undoRedoCommand = UndoRedoCommandType.ctRedo
  202.            redoStack.Pop.Redo()
  203.            UpdateCanUndoRedo()
  204.            _undoRedoCommand = UndoRedoCommandType.ctNone
  205.        End If
  206.    End Sub
  207.  
  208.    Protected Overrides Sub Finalize()
  209.        MyBase.Finalize()
  210.    End Sub
  211.  
  212.  
  213. #Region "debug info"
  214.  
  215.    Public Shared Function ArrayToString(ByVal ObjectArray() As Object) As String
  216.        Dim sb As New System.Text.StringBuilder
  217.        For Each item As Object In ObjectArray
  218.            sb.AppendLine(item.ToString)
  219.        Next
  220.        Return sb.ToString
  221.    End Function
  222.  
  223.  
  224.    Public Function GetUndoStack() As String
  225.        Return ArrayToString(undoStack.ToArray)
  226.    End Function
  227.  
  228.    Public Function GetRedoStack() As String
  229.        Return ArrayToString(redoStack.ToArray)
  230.    End Function
  231.  
  232.    Public Function GetRegisteredUndoRedoMonitorTypes() As String
  233.        Return ArrayToString(RegisteredUndoRedoMonitorTypes.ToArray)
  234.    End Function
  235.  
  236. #End Region
  237.  
  238. End Class
  239.  

Código
  1. '******************************************************************************************************************
  2. ' Undo/Redo framework (c) Copyright 2009 Etienne Nijboer
  3. '******************************************************************************************************************
  4.  
  5. Public MustInherit Class BaseUndoRedoMonitor
  6.  
  7.    Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
  8.        _UndoRedoManager = AUndoRedoManager
  9.    End Sub
  10.  
  11.    Private _UndoRedoManager As UndoRedoManager
  12.    Public Property UndoRedoManager() As UndoRedoManager
  13.        Get
  14.            Return _UndoRedoManager
  15.        End Get
  16.        Set(ByVal value As UndoRedoManager)
  17.            _UndoRedoManager = value
  18.        End Set
  19.    End Property
  20.  
  21.    Public ReadOnly Property isUndoing() As Boolean
  22.        Get
  23.            Return UndoRedoManager.isUndoing
  24.        End Get
  25.    End Property
  26.    Public ReadOnly Property isRedoing() As Boolean
  27.        Get
  28.            Return UndoRedoManager.isRedoing
  29.        End Get
  30.    End Property
  31.  
  32.    Public ReadOnly Property isPerformingUndoRedo() As Boolean
  33.        Get
  34.            Return UndoRedoManager.isPerformingUndoRedo
  35.        End Get
  36.    End Property
  37.  
  38.    Public Sub AddCommand(ByVal UndoRedoCommandType As UndoRedoCommandType, ByVal UndoRedoCommand As BaseUndoRedoCommand)
  39.        UndoRedoManager.AddCommand(UndoRedoCommandType, UndoRedoCommand)
  40.    End Sub
  41.  
  42.    Public MustOverride Function Monitor(ByVal AControl As Control) As Boolean
  43.  
  44. End Class
  45.  
  46. '****************************************************************************************************************
  47. ' SimpleControl
  48. ' Controls: TextBox, ComboBox, DateTimePicker, NumericUpDown, MaskedTextBox
  49. '****************************************************************************************************************
  50. Public Class SimpleControlMonitor : Inherits BaseUndoRedoMonitor
  51.  
  52.    Private Data As String
  53.  
  54.    Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
  55.        MyBase.New(AUndoRedoManager)
  56.    End Sub
  57.  
  58.    Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
  59.        If TypeOf AControl Is TextBox Or _
  60.           TypeOf AControl Is ComboBox Or _
  61.           TypeOf AControl Is DateTimePicker Or _
  62.           TypeOf AControl Is NumericUpDown Or _
  63.           TypeOf AControl Is ListView Or _
  64.           TypeOf AControl Is MaskedTextBox Then
  65.            AddHandler AControl.Enter, AddressOf Control_Enter
  66.            AddHandler AControl.Leave, AddressOf Control_Leave
  67.            Return True
  68.        End If
  69.        Return False
  70.    End Function
  71.  
  72.    Private Sub Control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
  73.        Data = CType(sender, Control).Text
  74.    End Sub
  75.  
  76.    Private Sub Control_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs)
  77.        Dim CurrentData As String = CType(sender, Control).Text
  78.        If Not String.Equals(CurrentData, Data) Then
  79.            AddCommand(UndoRedoCommandType.ctUndo, New SimpleControlUndoRedoCommand(Me, sender, Data))
  80.        End If
  81.    End Sub
  82. End Class
  83.  
  84. '****************************************************************************************************************
  85. ' ListBox
  86. '****************************************************************************************************************
  87. Public Class ListBoxMonitor : Inherits BaseUndoRedoMonitor
  88.  
  89.    Private Data As Object
  90.  
  91.    Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
  92.        MyBase.New(AUndoRedoManager)
  93.    End Sub
  94.  
  95.    Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
  96.        If TypeOf AControl Is ListBox Then
  97.            AddHandler AControl.Enter, AddressOf Control_Enter
  98.            AddHandler CType(AControl, ListBox).SelectedIndexChanged, AddressOf Control_Changed
  99.            Return True
  100.        End If
  101.        Return False
  102.    End Function
  103.  
  104.    Public Function GetSelected(ByVal AListBox As Object) As String
  105.        Dim Indices As List(Of String) = New List(Of String)
  106.        For Each itemIndex As Integer In CType(AListBox, ListBox).SelectedIndices
  107.            Indices.Add(CStr(itemIndex + 1))
  108.        Next
  109.        Return String.Join(",", Indices.ToArray)
  110.    End Function
  111.  
  112.    Public Sub RestoreSelected(ByVal AListBox As Object, ByVal ASelection As String)
  113.        If Not String.IsNullOrEmpty(ASelection) Then
  114.            Dim Indices As List(Of Integer) = New List(Of Integer)(Array.ConvertAll(ASelection.Split(","), New Converter(Of String, Integer)(AddressOf Integer.Parse)))
  115.            Dim Control As ListBox = CType(AListBox, ListBox)
  116.            Select Case Control.SelectionMode
  117.                Case SelectionMode.None
  118.                Case SelectionMode.One
  119.                    Control.SetSelected(Indices(0) - 1, True)
  120.                Case SelectionMode.MultiSimple, SelectionMode.MultiExtended
  121.                    For index As Integer = 0 To Control.Items.Count - 1
  122.                        Control.SetSelected(index, Indices.IndexOf(index + 1) >= 0)
  123.                    Next
  124.            End Select
  125.        Else
  126.            CType(AListBox, ListBox).ClearSelected()
  127.        End If
  128.    End Sub
  129.  
  130.    Private Sub Control_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs)
  131.        ' Events that are also fired when the undo/redo value is changed by code, like change events,
  132.        ' it is important to make sure that no undo/redo command is added when performing a undo/redo action.
  133.        If Not isPerformingUndoRedo Then
  134.            Dim CurrentData As String = GetSelected(sender)
  135.            If Not String.Equals(Data, CurrentData) Then
  136.                AddCommand(UndoRedoCommandType.ctUndo, New ListBoxUndoRedoCommand(Me, sender, Data))
  137.                Data = CurrentData
  138.            End If
  139.        End If
  140.    End Sub
  141.  
  142.    Private Sub Control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
  143.        Data = GetSelected(sender)
  144.    End Sub
  145.  
  146. End Class
  147.  
  148.  
  149. '****************************************************************************************************************
  150. ' CheckBox
  151. '****************************************************************************************************************
  152. Public Class CheckBoxMonitor : Inherits BaseUndoRedoMonitor
  153.    Private Data As CheckState
  154.  
  155.    Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
  156.        MyBase.New(AUndoRedoManager)
  157.    End Sub
  158.  
  159.    Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
  160.        If TypeOf AControl Is CheckBox Then
  161.            AddHandler AControl.Enter, AddressOf Control_Enter
  162.            AddHandler AControl.Leave, AddressOf Control_Leave
  163.            Return True
  164.        End If
  165.        Return False
  166.    End Function
  167.  
  168.    Private Sub Control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
  169.        Data = CType(sender, CheckBox).CheckState
  170.    End Sub
  171.  
  172.    Private Sub Control_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs)
  173.        Dim CurrentData As CheckState = CType(sender, CheckBox).CheckState
  174.        If Data <> CurrentData Then
  175.            AddCommand(UndoRedoCommandType.ctUndo, New CheckBoxUndoRedoCommand(Me, sender, Data))
  176.        End If
  177.    End Sub
  178. End Class
  179.  
  180. '****************************************************************************************************************
  181. ' RadioButton
  182. '****************************************************************************************************************
  183. Public Class RadioButtonMonitor : Inherits BaseUndoRedoMonitor
  184.    Private Data As RadioButton
  185.  
  186.    Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
  187.        MyBase.New(AUndoRedoManager)
  188.    End Sub
  189.  
  190.    Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
  191.        If TypeOf AControl Is RadioButton Then
  192.            AddHandler CType(AControl, RadioButton).CheckedChanged, AddressOf Control_CheckedChanged
  193.            Return True
  194.        End If
  195.        Return False
  196.    End Function
  197.  
  198.    Private Sub Control_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  199.        ' Events that are also fired when the undo/redo value is changed by code, like change events,
  200.        ' it is important to make sure that no undo/redo command is added when performing a undo/redo action.  
  201.        If Not isPerformingUndoRedo Then
  202.            If CType(sender, RadioButton).Checked Then
  203.                AddCommand(UndoRedoCommandType.ctUndo, New RadioButtonUndoRedoCommand(Me, sender, Data))
  204.            Else
  205.                Data = sender
  206.            End If
  207.        End If
  208.    End Sub
  209. End Class
  210.  
  211. '****************************************************************************************************************
  212. ' MonthCalendar
  213. '****************************************************************************************************************
  214. Public Class MonthCalendarMonitor : Inherits BaseUndoRedoMonitor
  215.    Private Data As SelectionRange
  216.  
  217.    Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
  218.        MyBase.New(AUndoRedoManager)
  219.    End Sub
  220.  
  221.    Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
  222.        If TypeOf AControl Is MonthCalendar Then
  223.            AddHandler AControl.Enter, AddressOf Control_Enter
  224.            AddHandler CType(AControl, MonthCalendar).DateSelected, AddressOf Control_DateSelected
  225.            Return True
  226.        End If
  227.        Return False
  228.    End Function
  229.  
  230.    Private Sub Control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
  231.        Data = CType(sender, MonthCalendar).SelectionRange
  232.    End Sub
  233.  
  234.    Private Sub Control_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs)
  235.        ' Events that are also fired when the undo/redo value is changed by code, like selected events,
  236.        ' it is important to make sure that no undo/redo command is added when performing a undo/redo action.
  237.        If Not isPerformingUndoRedo Then
  238.            Dim CurrentData As SelectionRange = CType(sender, MonthCalendar).SelectionRange
  239.            If Not SelectionRange.Equals(Data, CurrentData) Then
  240.                AddCommand(UndoRedoCommandType.ctUndo, New MonthCalendarUndoRedoCommand(Me, sender, Data))
  241.                Data = CurrentData
  242.            End If
  243.        End If
  244.    End Sub
  245.  
  246. End Class

Código
  1. '******************************************************************************************************************
  2. ' Undo/Redo framework (c) Copyright 2009 Etienne Nijboer
  3. '******************************************************************************************************************
  4.  
  5. Public MustInherit Class BaseUndoRedoCommand
  6.  
  7.    Private _UndoRedoMonitor As BaseUndoRedoMonitor
  8.    Private _UndoRedoControl As Control
  9.    Private _UndoRedoData As Object
  10.  
  11.    Public ReadOnly Property UndoRedoMonitor() As BaseUndoRedoMonitor
  12.        Get
  13.            Return _UndoRedoMonitor
  14.        End Get
  15.    End Property
  16.  
  17.    Public ReadOnly Property UndoRedoControl() As Control
  18.        Get
  19.            Return _UndoRedoControl
  20.        End Get
  21.    End Property
  22.  
  23.    Protected Property UndoRedoData() As Object
  24.        Get
  25.            Return _UndoRedoData
  26.        End Get
  27.        Set(ByVal value As Object)
  28.            _UndoRedoData = value
  29.        End Set
  30.    End Property
  31.  
  32.    Protected Sub New()
  33.        Throw New Exception("Cannot create instance with the default constructor.")
  34.    End Sub
  35.  
  36.    Public Sub New(ByVal AUndoRedoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
  37.        Me.New(AUndoRedoMonitor, AMonitorControl, Nothing)
  38.    End Sub
  39.  
  40.    Public Sub New(ByVal AUndoRedoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As Object)
  41.        _UndoRedoMonitor = AUndoRedoMonitor
  42.        _UndoRedoControl = AMonitorControl
  43.        _UndoRedoData = AUndoRedoData
  44.    End Sub
  45.  
  46.    Protected Sub AddCommand(ByVal UndoRedoCommandType As UndoRedoCommandType, ByVal UndoRedoCommand As BaseUndoRedoCommand)
  47.        UndoRedoMonitor.AddCommand(UndoRedoCommandType, UndoRedoCommand)
  48.    End Sub
  49.  
  50.    Public Overridable Sub Undo()
  51.        AddCommand(UndoRedoCommandType.ctRedo, Activator.CreateInstance(Me.GetType, UndoRedoMonitor, UndoRedoControl))
  52.    End Sub
  53.  
  54.    Public Overridable Sub Redo()
  55.        AddCommand(UndoRedoCommandType.ctUndo, Activator.CreateInstance(Me.GetType, UndoRedoMonitor, UndoRedoControl))
  56.    End Sub
  57.  
  58.    Public Overridable Sub Undo(ByVal RedoData As Object)
  59.        AddCommand(UndoRedoCommandType.ctRedo, Activator.CreateInstance(Me.GetType, UndoRedoMonitor, UndoRedoControl, RedoData))
  60.    End Sub
  61.  
  62.    Public Overridable Sub Redo(ByVal UndoData As Object)
  63.        AddCommand(UndoRedoCommandType.ctUndo, Activator.CreateInstance(Me.GetType, UndoRedoMonitor, UndoRedoControl, UndoData))
  64.    End Sub
  65.  
  66.    Public MustOverride Function CommandAsText() As String
  67.  
  68.    Public Overrides Function ToString() As String
  69.        Return CommandAsText()
  70.    End Function
  71.  
  72. End Class
  73.  
  74. '****************************************************************************************************************
  75. ' SimpleControl
  76. ' Controls: TextBox, ComboBox, DateTimePicker, NumericUpDown, MaskedTextBox
  77. '****************************************************************************************************************
  78. Public Class SimpleControlUndoRedoCommand : Inherits BaseUndoRedoCommand
  79.  
  80.    Protected ReadOnly Property UndoRedoText() As String
  81.        Get
  82.            Return CStr(UndoRedoData)
  83.        End Get
  84.    End Property
  85.  
  86.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
  87.        MyBase.New(AUndoMonitor, AMonitorControl)
  88.        UndoRedoData = UndoRedoControl.Text
  89.    End Sub
  90.  
  91.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As String)
  92.        MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
  93.    End Sub
  94.  
  95.    Public Overrides Sub Undo()
  96.        MyBase.Undo()
  97.        UndoRedoControl.Text = UndoRedoText
  98.    End Sub
  99.  
  100.    Public Overrides Sub Redo()
  101.        MyBase.Redo()
  102.        UndoRedoControl.Text = UndoRedoText
  103.    End Sub
  104.  
  105.    Public Overrides Function CommandAsText() As String
  106.        Return String.Format("Change to '{0}'", UndoRedoText)
  107.    End Function
  108.  
  109. End Class
  110.  
  111. '****************************************************************************************************************
  112. ' ListBox
  113. '****************************************************************************************************************
  114. Public Class ListBoxUndoRedoCommand : Inherits BaseUndoRedoCommand
  115.  
  116.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
  117.        MyBase.New(AUndoMonitor, AMonitorControl)
  118.        UndoRedoData = GetSelection()
  119.    End Sub
  120.  
  121.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As Object)
  122.        MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
  123.    End Sub
  124.  
  125.    Public ReadOnly Property Control() As ListBox
  126.        Get
  127.            Return CType(UndoRedoControl, ListBox)
  128.        End Get
  129.    End Property
  130.  
  131.    Private Sub RestoreSelection()
  132.        CType(UndoRedoMonitor, ListBoxMonitor).RestoreSelected(UndoRedoControl, CStr(UndoRedoData))
  133.    End Sub
  134.  
  135.    Private Function GetSelection() As Object
  136.        Return CType(UndoRedoMonitor, ListBoxMonitor).GetSelected(UndoRedoControl)
  137.    End Function
  138.  
  139.    Public Overrides Sub Undo()
  140.        MyBase.Undo()
  141.        RestoreSelection()
  142.    End Sub
  143.  
  144.    Public Overrides Sub Redo()
  145.        MyBase.Redo()
  146.        RestoreSelection()
  147.    End Sub
  148.  
  149.    Public Overrides Function CommandAsText() As String
  150.        Return String.Format("Select {0}", CStr(UndoRedoData))
  151.    End Function
  152. End Class
  153.  
  154.  
  155. '****************************************************************************************************************
  156. ' CheckBox
  157. '****************************************************************************************************************
  158. Public Class CheckBoxUndoRedoCommand : Inherits BaseUndoRedoCommand
  159.  
  160.    Protected ReadOnly Property UndoRedoCheckState() As CheckState
  161.        Get
  162.            Return CType(UndoRedoData, CheckState)
  163.        End Get
  164.    End Property
  165.  
  166.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
  167.        MyBase.New(AUndoMonitor, AMonitorControl)
  168.        UndoRedoData = Control.CheckState
  169.    End Sub
  170.  
  171.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As String)
  172.        MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
  173.    End Sub
  174.  
  175.    Public ReadOnly Property Control() As CheckBox
  176.        Get
  177.            Return CType(UndoRedoControl, CheckBox)
  178.        End Get
  179.    End Property
  180.  
  181.    Public Overrides Sub Undo()
  182.        MyBase.Undo()
  183.        Control.CheckState = UndoRedoCheckState
  184.    End Sub
  185.  
  186.    Public Overrides Sub Redo()
  187.        MyBase.Redo()
  188.        Control.CheckState = UndoRedoCheckState
  189.    End Sub
  190.  
  191.    Public Overrides Function CommandAsText() As String
  192.        Return String.Format("Change to '{0}'", UndoRedoCheckState.ToString)
  193.    End Function
  194.  
  195. End Class
  196.  
  197. '****************************************************************************************************************
  198. ' RadioButton
  199. '****************************************************************************************************************
  200. Public Class RadioButtonUndoRedoCommand : Inherits BaseUndoRedoCommand
  201.  
  202.    Protected ReadOnly Property UndoRedoRadioButton() As RadioButton
  203.        Get
  204.            Return CType(UndoRedoData, RadioButton)
  205.        End Get
  206.    End Property
  207.  
  208.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
  209.        MyBase.New(AUndoMonitor, AMonitorControl)
  210.        UndoRedoData = Control.Checked
  211.    End Sub
  212.  
  213.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As Control)
  214.        MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
  215.    End Sub
  216.  
  217.    Public ReadOnly Property Control() As RadioButton
  218.        Get
  219.            Return CType(UndoRedoControl, RadioButton)
  220.        End Get
  221.    End Property
  222.  
  223.    Public Overrides Sub Undo()
  224.        MyBase.Undo(UndoRedoRadioButton)
  225.        Control.Checked = False
  226.        If UndoRedoRadioButton IsNot Nothing Then
  227.            UndoRedoRadioButton.Checked = True
  228.        End If
  229.    End Sub
  230.  
  231.    Public Overrides Sub Redo()
  232.        MyBase.Redo(UndoRedoRadioButton)
  233.        If UndoRedoRadioButton IsNot Nothing Then
  234.            UndoRedoRadioButton.Checked = False
  235.        End If
  236.        Control.Checked = True
  237.    End Sub
  238.  
  239.    Public Overrides Function CommandAsText() As String
  240.        If UndoRedoRadioButton IsNot Nothing Then
  241.            Return String.Format("Invert '{0}'/'{1}'", Control.Text, UndoRedoRadioButton.Text)
  242.        Else
  243.            Return String.Format("Change '{0}'", Control.Text)
  244.        End If
  245.    End Function
  246.  
  247. End Class
  248.  
  249.  
  250. '****************************************************************************************************************
  251. ' MonthCalendar
  252. '****************************************************************************************************************
  253. Public Class MonthCalendarUndoRedoCommand : Inherits BaseUndoRedoCommand
  254.  
  255.    Protected ReadOnly Property UndoRedoSelectionRange() As SelectionRange
  256.        Get
  257.            Return CType(UndoRedoData, SelectionRange)
  258.        End Get
  259.    End Property
  260.  
  261.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
  262.        MyBase.New(AUndoMonitor, AMonitorControl)
  263.        UndoRedoData = Control.SelectionRange
  264.    End Sub
  265.  
  266.    Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As SelectionRange)
  267.        MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
  268.    End Sub
  269.  
  270.    Public ReadOnly Property Control() As MonthCalendar
  271.        Get
  272.            Return CType(UndoRedoControl, MonthCalendar)
  273.        End Get
  274.    End Property
  275.  
  276.    Public Overrides Sub Undo()
  277.        MyBase.Undo()
  278.        Control.SelectionRange = UndoRedoSelectionRange
  279.    End Sub
  280.  
  281.    Public Overrides Sub Redo()
  282.        MyBase.Redo()
  283.        Control.SelectionRange = UndoRedoSelectionRange
  284.    End Sub
  285.  
  286.    Public Overrides Function CommandAsText() As String
  287.        If Date.Equals(UndoRedoSelectionRange.Start, UndoRedoSelectionRange.End) Then
  288.            Return String.Format("Select date {0}", FormatDateTime(UndoRedoSelectionRange.Start, DateFormat.ShortDate))
  289.        Else
  290.        End If
  291.        Return String.Format("Change to '{0}'", String.Format("{0} until {1}", FormatDateTime(UndoRedoSelectionRange.Start, DateFormat.ShortDate), _
  292.                                                                               FormatDateTime(UndoRedoSelectionRange.End, DateFormat.ShortDate)))
  293.    End Function
  294.  
  295. End Class

2. Usarlo de esta manera:

Código
  1. Public Class Form1
  2.  
  3.    Private WithEvents frmUndoRedoManager As UndoRedoManager
  4.  
  5.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  6.        frmUndoRedoManager = New UndoRedoManager(Me)
  7.    End Sub
  8.  
  9.    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  10.        frmUndoRedoManager.Undo()
  11.    End Sub
  12.  
  13.    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  14.        frmUndoRedoManager.Redo()
  15.    End Sub
  16.  
  17. End Class

Saludos.
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #254 en: 13 Julio 2013, 11:41 am »

Una class para manejar Audios en la librería NAudio.

(Es algo corta, lo sé, no he experimentado más cosas que las que necesito de esta librería)

Código
  1. #Region " NAudio "
  2.  
  3. Public Class NAudio_Helper
  4.  
  5.    ' [ NAudio ]
  6.    '
  7.    ' // By Elektro H@cker
  8.    '
  9.    ' Instructions:
  10.    ' 1. Add a reference for the "NAudio.dll" file into the project.
  11.    '
  12.    ' Examples:
  13.    '
  14.    ' Dim Stream As NAudio.Wave.WaveFileReader = New NAudio.Wave.WaveFileReader(File)
  15.    '
  16.    ' Set_Volume(Stream, 0.5)
  17.    ' Play_Sound(Stream, 1)
  18.    ' Play_Sound(My.Resources.AudioFile)
  19.    ' Play_Sound("C:\File.wav")
  20.  
  21.  
  22.    ' Play Sound (File)
  23.    Private Sub Play_Sound(ByVal File As String, _
  24.                           Optional ByVal Volume As Single = Nothing)
  25.  
  26.        Dim Wave As New NAudio.Wave.WaveOut
  27.  
  28.        Select Case File.Split(".").Last.ToLower
  29.            Case "aiff"
  30.                Wave.Init(New NAudio.Wave.AiffFileReader(File))
  31.            Case "mp3"
  32.                Wave.Init(New NAudio.Wave.Mp3FileReader(File))
  33.            Case "wav"
  34.                Wave.Init(New NAudio.Wave.WaveFileReader(File))
  35.            Case Else
  36.                Wave.Init(New NAudio.Wave.BlockAlignReductionStream(NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(New NAudio.Wave.AudioFileReader(File))))
  37.        End Select
  38.  
  39.        If Not Volume = Nothing Then Wave.Volume = Volume
  40.        Wave.Play()
  41.  
  42.    End Sub
  43.  
  44.    ' Play Sound (MemoryStream)
  45.    Private Sub Play_Sound(ByVal Stream As IO.MemoryStream, _
  46.                           Optional ByVal Volume As Single = Nothing)
  47.  
  48.        Dim Wave As New NAudio.Wave.WaveOut
  49.        Wave.Init(New NAudio.Wave.BlockAlignReductionStream(NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(New NAudio.Wave.WaveFileReader(Stream))))
  50.        If Not Volume = Nothing Then Wave.Volume = Volume
  51.        Wave.Play()
  52.  
  53.    End Sub
  54.  
  55.    ' Play Sound (Unmanaged MemoryStream)
  56.    Private Sub Play_Sound(ByVal Stream As IO.UnmanagedMemoryStream, _
  57.                           Optional ByVal Volume As Single = Nothing)
  58.  
  59.        Dim Wave As New NAudio.Wave.WaveOut
  60.        Wave.Init(New NAudio.Wave.BlockAlignReductionStream(NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(New NAudio.Wave.WaveFileReader(Stream))))
  61.        If Not Volume = Nothing Then Wave.Volume = Volume
  62.        Wave.Play()
  63.  
  64.    End Sub
  65.  
  66.    ' Play Sound (NAudio Stream)
  67.    Private Sub Play_Sound(ByVal NAudio_Stream As Object, _
  68.                           Optional ByVal Volume As Single = Nothing)
  69.  
  70.        Dim Wave As New NAudio.Wave.WaveOut
  71.        Wave.Init(NAudio_Stream)
  72.        If Not Volume = Nothing Then Wave.Volume = Volume
  73.        Wave.Play()
  74.  
  75.    End Sub
  76.  
  77.    ' Set Volume (NAudio Stream)
  78.    Private Function Set_Volume(ByVal NAudio_Stream As Object, ByVal Volume As Single) _
  79.    As NAudio.Wave.WaveOut
  80.  
  81.        Dim Wave As New NAudio.Wave.WaveOut
  82.        Wave.Init(NAudio_Stream)
  83.        Wave.Volume = Volume
  84.        Return Wave
  85.  
  86.    End Function
  87.  
  88. End Class
  89.  
  90. #End Region
« Última modificación: 13 Julio 2013, 17:40 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #255 en: 14 Julio 2013, 17:05 pm »

He ideado esya función para convertir un archivo REG a un script BAT.

La verdad es que no me ha costado mucho, ya había desarrollado antes la manera de convertir usando Ruby y sólo he tenido que trasladar el código que hice y agregarle las mejoras de VBNET xD.


Código
  1.    #Region " Reg2Bat "
  2.  
  3.       ' [ Reg2Bat Function ]
  4.       '
  5.       ' // By Elektro H@cker
  6.       '
  7.       ' Examples :
  8.       ' MsgBox(Reg2Bat("C:\Registry.reg"))
  9.  
  10.    Private Function Reg2Bat(ByVal Reg_File As String) As String
  11.  
  12.        ' Source Input
  13.        ' Join he lines, delete the Regedit linebreaks characters: "\  ", and then split the lines.
  14.        Dim RegFile() As String = Split( _
  15.                                  String.Join("@@@Reg2Bat@@@", IO.File.ReadAllLines(Reg_File)) _
  16.                                  .Replace("\@@@Reg2Bat@@@  ", "") _
  17.                                  .Replace("@@@Reg2Bat@@@", Environment.NewLine), _
  18.                                  Environment.NewLine)
  19.  
  20.        Dim RegLine As String = String.Empty ' Where the Regedit Line will be stored.
  21.        Dim RegKey As String = String.Empty ' Where the Regedit Key will be stored.
  22.        Dim RegVal As String = String.Empty ' Where the Regedit Value will be stored.
  23.        Dim RegData As String = String.Empty ' Where the Regedit Data will be stored.
  24.  
  25.        Dim Batch_Commands As String = String.Empty ' Where the decoded Regedit strings will be stored.
  26.  
  27.        ' Check if first line of Reg File has a valid Regedit signature
  28.        For X As Int64 = 0 To RegFile.LongLength - 1
  29.  
  30.            RegLine = RegFile(X).Trim
  31.  
  32.            While RegLine = String.Empty
  33.                X += 1
  34.                RegLine = RegFile(X).Trim
  35.            End While
  36.  
  37.            If Not RegLine.ToLower = "windows registry editor version 5.00" Then
  38.                Throw New Exception("This is not a valid Regedit v5.00 script.")
  39.                Return Nothing
  40.            Else
  41.                Batch_Commands &= ":: Converted with REG2BAT By Elektro H@cker" & Environment.NewLine & Environment.NewLine
  42.                Batch_Commands &= String.Format("REM {0}", RegLine) & Environment.NewLine & Environment.NewLine
  43.                Exit For
  44.            End If
  45.  
  46.        Next
  47.  
  48.        ' Start reading the Regedit File
  49.        For X As Int64 = 0 To RegFile.LongLength - 1
  50.  
  51.            RegLine = RegFile(X).Trim
  52.  
  53.            Select Case True
  54.  
  55.                Case RegLine.StartsWith(";") ' Comment line
  56.  
  57.                    Batch_Commands &= Environment.NewLine
  58.                    Batch_Commands &= String.Format("REM {0}", RegLine.Substring(1, RegLine.Length - 1).Trim)
  59.                    Batch_Commands &= Environment.NewLine
  60.  
  61.                Case RegLine.StartsWith("[-") ' Key to delete
  62.  
  63.                    RegKey = RegLine.Substring(2, RegLine.Length - 3).Trim
  64.                    Batch_Commands &= String.Format("REG DELETE ""{0}"" /F", RegKey)
  65.                    Batch_Commands &= Environment.NewLine
  66.  
  67.                Case RegLine.StartsWith("[") ' Key to add
  68.  
  69.                    RegKey = RegLine.Substring(1, RegLine.Length - 2).Trim
  70.                    Batch_Commands &= String.Format("REG ADD ""{0}"" /F", RegKey)
  71.                    Batch_Commands &= Environment.NewLine
  72.  
  73.                Case RegLine.StartsWith("@=") ' Default Value to add
  74.  
  75.                    RegData = Split(RegLine, "@=", , CompareMethod.Text).Last
  76.                    Batch_Commands &= String.Format("REG ADD ""{0}"" /V  """" /D {1} /F", RegKey, RegData)
  77.                    Batch_Commands &= Environment.NewLine
  78.  
  79.                Case RegLine.StartsWith("""") _
  80.                AndAlso RegLine.Split("=").Last = "-"  ' Value to delete
  81.  
  82.                    RegVal = RegLine.Substring(1, RegLine.Length - 4)
  83.                    Batch_Commands &= String.Format("REG DELETE ""{0}"" /V ""{1}"" /F", RegKey, RegVal)
  84.                    Batch_Commands &= Environment.NewLine
  85.  
  86.                Case RegLine.StartsWith("""") ' Value to add
  87.  
  88.                    RegLine = RegLine.Replace("\\", "\") ' Replace Double "\\" to single "\".
  89.  
  90.                    ' Check data type:
  91.                    Select Case RegLine.Split("=")(1).Split(":")(0).ToLower
  92.  
  93.                        Case "hex" ' Binary
  94.  
  95.                            RegVal = Split(RegLine, "=hex:", , CompareMethod.Text)(0)
  96.                            RegData = Split(RegLine, (RegVal & "=hex:"), , CompareMethod.Text).Last.Replace(",", "")
  97.                            Batch_Commands &= String.Format("REG ADD ""{0}"" /V {1} /T ""REG_BINARY"" /D ""{2}"" /F", RegKey, RegVal, RegData)
  98.                            Batch_Commands &= Environment.NewLine
  99.  
  100.                        Case "dword" ' DWORD
  101.  
  102.                            RegVal = Split(RegLine, "=dword:", , CompareMethod.Text)(0)
  103.                            RegData = "0x" & Split(RegLine, (RegVal & "=dword:"), , CompareMethod.Text).Last
  104.                            Batch_Commands &= String.Format("REG ADD ""{0}"" /V {1} /T ""REG_DWORD"" /D ""{2}"" /F", RegKey, RegVal, RegData)
  105.                            Batch_Commands &= Environment.NewLine
  106.  
  107.                        Case "hex(b)" ' QWORD
  108.  
  109.                            Dim TempData As String = "0x"
  110.                            RegVal = Split(RegLine, "=hex(b):", , CompareMethod.Text)(0)
  111.                            RegData = StrReverse(Split(RegLine, (RegVal & "=hex(b):"), , CompareMethod.Text).Last)
  112.                            For Each [byte] In RegData.Split(",") : TempData &= StrReverse([byte]) : Next
  113.                            Batch_Commands &= String.Format("REG ADD ""{0}"" /V {1} /T ""REG_QWORD"" /D ""{2}"" /F", RegKey, RegVal, TempData)
  114.                            Batch_Commands &= Environment.NewLine
  115.  
  116.                        Case "hex(2)"  ' EXPAND SZ
  117.  
  118.                            Dim TempData As String = String.Empty
  119.                            RegVal = Split(RegLine, "=Hex(2):", , CompareMethod.Text)(0)
  120.                            RegData = Split(RegLine, (RegVal & "=hex(2):"), , CompareMethod.Text).Last.Replace(",00", "").Replace("00,", "")
  121.                            For Each [byte] In RegData.Split(",") : TempData &= Chr(Val("&H" & [byte])) : Next
  122.                            TempData = TempData.Replace("%", "%%").Replace("""", "\""")
  123.                            Batch_Commands &= String.Format("REG ADD ""{0}"" /V {1} /T ""REG_EXPAND_SZ"" /D ""{2}"" /F", RegKey, RegVal, TempData)
  124.                            Batch_Commands &= Environment.NewLine
  125.  
  126.                        Case "hex(7)" ' MULTI SZ
  127.  
  128.                            Dim TempData As String = String.Empty
  129.                            RegVal = Split(RegLine, "=Hex(7):", , CompareMethod.Text)(0)
  130.                            RegData = Split(RegLine, (RegVal & "=hex(7):"), , CompareMethod.Text).Last.Replace(",00,00,00", ",\0").Replace(",00", "").Replace("00,", "")
  131.  
  132.                            For Each [byte] In RegData.Split(",")
  133.  
  134.                                If [byte] = "\0" Then
  135.                                    TempData &= "\0" ' Line separator for multiline.
  136.                                Else
  137.                                    TempData &= Chr(Val("&H" & [byte]))
  138.                                End If
  139.  
  140.                            Next
  141.  
  142.                            TempData = TempData.Replace("%", "%%").Replace("""", "\""")
  143.                            Batch_Commands &= String.Format("REG ADD ""{0}"" /V {1} /T ""REG_MULTI_SZ"" /D ""{2}"" /F", RegKey, RegVal, TempData)
  144.                            Batch_Commands &= Environment.NewLine
  145.  
  146.                        Case Else ' REG SZ
  147.  
  148.                            RegVal = Split(RegLine, """=""", , CompareMethod.Text)(0)
  149.                            RegData = Split(RegLine, (RegVal & """="""), , CompareMethod.Text).Last
  150.                            Batch_Commands &= String.Format("REG ADD ""{0}"" /V {1}"" /T ""REG_SZ"" /D ""{2} /F", RegKey, RegVal, RegData)
  151.                            Batch_Commands &= Environment.NewLine
  152.  
  153.                    End Select
  154.  
  155.            End Select
  156.  
  157.        Next
  158.  
  159.        Return Batch_Commands
  160.  
  161.    End Function
  162.  
  163.    #End Region
  164.  
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #256 en: 18 Julio 2013, 06:26 am »

· Expandir todas las variables de un string

PD: Útil para permitir al usuario manejar variables de entorno en la aplicación por ejemplo para setear una ruta, o cargar una ruta que contenga variables de entorno desde un archivo INI.

Código
  1. #Region " Expand Variables In String "
  2.  
  3.    ' [ Expand Variables In String Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Expand_Variables_In_String("%homedrive%\Users\%username%\%fake-var%\")) ' Result: C:\Users\Administrador\%fake-var%\
  9.  
  10.    Public Function Expand_Variables_In_String(ByVal str As String) As String
  11.  
  12.        Dim match As System.Text.RegularExpressions.Match = _
  13.        System.Text.RegularExpressions.Regex.Match(str, "(%.*%)")
  14.  
  15.        Do While match.Success
  16.            str = str.Replace(match.ToString, Environment.ExpandEnvironmentVariables(match.ToString))
  17.            match = match.NextMatch()
  18.        Loop
  19.  
  20.        Return str
  21.  
  22.    End Function
  23.  
  24. #End Region
« Última modificación: 18 Julio 2013, 14:01 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #257 en: 20 Julio 2013, 10:56 am »

Una class de ayuda para manejar lo básico de la librería FreeImage

Convertir entre formatos, convertir a escala de grises, rotar, redimensionar, generar un thumbnail...

http://freeimage.sourceforge.net/download.html

Código
  1. #Region " FreeImage Helper "
  2.  
  3.  
  4. ' [ FreeImage Helper ]
  5. '
  6. ' // By Elektro H@cker
  7. '
  8. '
  9. ' INSTRUCTIONS:
  10. ' 1. ADD A REFERENCE FOR "FreeImageNET.dll" IN THE PROJECT.
  11. ' 2. ADD THE "FREEIMAGE.DLL" IN THE PROJECT.
  12. '
  13. '
  14. ' Examples :
  15. '
  16. ' MsgBox(FreeImageHelper.Is_Avaliable() ' Result: True
  17. ' MsgBox(FreeImageHelper.Get_Version()  ' Result: 3.15.1
  18. ' MsgBox(FreeImageHelper.Get_ImageFormat("C:\Test.png")) ' Result: PNG
  19. '
  20. ' FreeImageHelper.Convert("C:\Test.png", "C:\Test.ico", FreeImageAPI.FREE_IMAGE_FORMAT.FIF_ICO)
  21. ' FreeImageHelper.Convert(New Bitmap("C:\Test.png"), "C:\Test.jpg", FreeImageAPI.FREE_IMAGE_FORMAT.FIF_JPEG, FreeImageAPI.FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_444 Or FreeImageAPI.FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB)
  22. '
  23. ' PictureBox1.BackgroundImage = FreeImageHelper.GrayScale(New Bitmap("C:\Test.bmp"))
  24. ' PictureBox1.BackgroundImage = FreeImageHelper.GrayScale("C:\Test.bmp")
  25. '
  26. ' PictureBox1.BackgroundImage = FreeImageHelper.Resize(New Bitmap("C:\Test.bmp"), 32, 32)
  27. ' PictureBox1.BackgroundImage = FreeImageHelper.Resize("C:\Test.bmp", 64, 128)
  28. '
  29. ' PictureBox1.BackgroundImage = FreeImageHelper.Rotate(New Bitmap("C:\Test.bmp"), 90)
  30. ' PictureBox1.BackgroundImage = FreeImageHelper.Rotate("C:\Test.bmp", -90)
  31. '
  32. ' PictureBox1.BackgroundImage = FreeImageHelper.Thumbnail(New Bitmap("C:\Test.png"), 64, True)
  33. ' PictureBox1.BackgroundImage = FreeImageHelper.Thumbnail("C:\Test.png", 64, True)
  34.  
  35.  
  36.  
  37. Imports FreeImageAPI
  38.  
  39. Public Class FreeImageHelper
  40.  
  41.    ' <summary>
  42.    ' Checks if <i>FreeImage.dll</i> is avaliable on the system.
  43.    ' </summary>
  44.    Public Shared Function Is_Avaliable() As Boolean
  45.        Return FreeImage.IsAvailable
  46.    End Function
  47.  
  48.    ' <summary>
  49.    ' Gets the version of FreeImage.dll.
  50.    ' </summary>
  51.    Shared Function Get_Version() As String
  52.        Return FreeImage.GetVersion
  53.    End Function
  54.  
  55.    ' <summary>
  56.    ' Gets the image format of a image file.
  57.    ' </summary>
  58.    Shared Function Get_ImageFormat(ByVal File As String) As String
  59.        Return FreeImage.GetFileType(File, 0).ToString.Substring(4)
  60.    End Function
  61.  
  62.    ' <summary>
  63.    ' Convert a Bitmap object between image formats and save it to disk.
  64.    ' </summary>
  65.    Shared Sub Convert(ByVal bmp As System.Drawing.Bitmap, _
  66.                       ByVal Output As String, _
  67.                       ByVal NewFormat As FREE_IMAGE_FORMAT, _
  68.                       Optional ByVal SaveFlags As FREE_IMAGE_SAVE_FLAGS = FREE_IMAGE_SAVE_FLAGS.DEFAULT)
  69.  
  70.        Try
  71.            FreeImage.SaveBitmap(bmp, Output, NewFormat, SaveFlags)
  72.        Catch ex As Exception
  73.            ' Throw New Exception(ex.Message)
  74.            MsgBox(ex.Message)
  75.        End Try
  76.  
  77.    End Sub
  78.  
  79.    ' <summary>
  80.    ' Convert a image file between image formats and save it to disk.
  81.    ' </summary>
  82.    Shared Sub Convert(ByVal File As String, _
  83.                       ByVal Output As String, _
  84.                       ByVal NewFormat As FREE_IMAGE_FORMAT, _
  85.                       Optional ByVal SaveFlags As FREE_IMAGE_SAVE_FLAGS = FREE_IMAGE_SAVE_FLAGS.DEFAULT)
  86.  
  87.        Try
  88.            FreeImage.Save(NewFormat, FreeImage.LoadEx(File), Output, SaveFlags)
  89.        Catch ex As Exception
  90.            ' Throw New Exception(ex.Message)
  91.            MsgBox(ex.Message)
  92.        End Try
  93.  
  94.    End Sub
  95.  
  96.    ' <summary>
  97.    ' GrayScales a Bitmap object.
  98.    ' </summary>
  99.    Shared Function GrayScale(ByVal bmp As System.Drawing.Bitmap) As System.Drawing.Bitmap
  100.  
  101.        Try
  102.  
  103.            Dim ImageStream As New System.IO.MemoryStream
  104.            bmp.Save(ImageStream, bmp.RawFormat)
  105.  
  106.            Dim Image As FIBITMAP = FreeImage.LoadFromStream(ImageStream)
  107.            ImageStream.Dispose()
  108.  
  109.            Return FreeImage.GetBitmap(FreeImage.ConvertToGreyscale(Image))
  110.  
  111.        Catch ex As Exception
  112.            ' Throw New Exception(ex.Message)
  113.            MsgBox(ex.Message)
  114.            Return Nothing
  115.        End Try
  116.  
  117.    End Function
  118.  
  119.    ' <summary>
  120.    ' GrayScales a image file.
  121.    ' </summary>
  122.    Shared Function GrayScale(ByVal File As String) As System.Drawing.Bitmap
  123.  
  124.        Try
  125.            Return FreeImage.GetBitmap(FreeImage.ConvertToGreyscale(FreeImage.LoadEx(File)))
  126.        Catch ex As Exception
  127.            ' Throw New Exception(ex.Message)
  128.            MsgBox(ex.Message)
  129.            Return Nothing
  130.        End Try
  131.  
  132.    End Function
  133.  
  134.    ' <summary>
  135.    ' Resizes a Bitmap object.
  136.    ' </summary>
  137.    Shared Function Resize(ByVal bmp As System.Drawing.Bitmap, _
  138.                           ByVal X As Int32, _
  139.                           ByVal Y As Int32, _
  140.                           Optional ByVal Quality As FREE_IMAGE_FILTER = FREE_IMAGE_FILTER.FILTER_BILINEAR) As System.Drawing.Bitmap
  141.  
  142.        Try
  143.  
  144.            Dim ImageStream As New System.IO.MemoryStream
  145.            bmp.Save(ImageStream, bmp.RawFormat)
  146.  
  147.            Dim Image As FIBITMAP = FreeImage.LoadFromStream(ImageStream)
  148.            ImageStream.Dispose()
  149.  
  150.            Return FreeImage.GetBitmap(FreeImage.Rescale(Image, X, Y, Quality))
  151.  
  152.        Catch ex As Exception
  153.            ' Throw New Exception(ex.Message)
  154.            MsgBox(ex.Message)
  155.            Return Nothing
  156.        End Try
  157.  
  158.    End Function
  159.  
  160.    ' <summary>
  161.    ' Resizes a image file.
  162.    ' </summary>
  163.    Shared Function Resize(ByVal File As String, _
  164.                           ByVal X As Int32, _
  165.                           ByVal Y As Int32, _
  166.                           Optional ByVal Quality As FREE_IMAGE_FILTER = FREE_IMAGE_FILTER.FILTER_BILINEAR) As System.Drawing.Bitmap
  167.  
  168.        Try
  169.  
  170.            Return FreeImage.GetBitmap(FreeImage.Rescale(FreeImage.LoadEx(File), X, Y, Quality))
  171.  
  172.        Catch ex As Exception
  173.            ' Throw New Exception(ex.Message)
  174.            MsgBox(ex.Message)
  175.            Return Nothing
  176.        End Try
  177.  
  178.    End Function
  179.  
  180.    ' <summary>
  181.    ' Rotates a Bitmap object.
  182.    ' </summary>
  183.    Shared Function Rotate(ByVal bmp As System.Drawing.Bitmap, _
  184.                           ByVal Angle As Double) As System.Drawing.Bitmap
  185.  
  186.        Try
  187.  
  188.            Dim ImageStream As New System.IO.MemoryStream
  189.            bmp.Save(ImageStream, bmp.RawFormat)
  190.  
  191.            Dim Image As FIBITMAP = FreeImage.LoadFromStream(ImageStream)
  192.            ImageStream.Dispose()
  193.  
  194.            Return FreeImage.GetBitmap(FreeImage.Rotate(Image, Angle))
  195.  
  196.        Catch ex As Exception
  197.            ' Throw New Exception(ex.Message)
  198.            MsgBox(ex.Message)
  199.            Return Nothing
  200.        End Try
  201.  
  202.    End Function
  203.  
  204.    ' <summary>
  205.    ' Rotates a image file.
  206.    ' </summary>
  207.    Shared Function Rotate(ByVal File As String, _
  208.                           ByVal Angle As Double) As System.Drawing.Bitmap
  209.  
  210.        Try
  211.  
  212.            Return FreeImage.GetBitmap(FreeImage.Rotate(FreeImage.LoadEx(File), Angle))
  213.  
  214.        Catch ex As Exception
  215.            ' Throw New Exception(ex.Message)
  216.            MsgBox(ex.Message)
  217.            Return Nothing
  218.        End Try
  219.  
  220.    End Function
  221.  
  222.    ' <summary>
  223.    ' Returns a Thumbnail of a Bitmap object.
  224.    ' </summary>
  225.    Shared Function Thumbnail(ByVal bmp As System.Drawing.Bitmap, _
  226.                                   ByVal size As Int32, _
  227.                                   ByVal convert As Boolean) As System.Drawing.Bitmap
  228.  
  229.        Try
  230.  
  231.            Dim ImageStream As New System.IO.MemoryStream
  232.            bmp.Save(ImageStream, bmp.RawFormat)
  233.  
  234.            Dim Image As FIBITMAP = FreeImage.LoadFromStream(ImageStream)
  235.            ImageStream.Dispose()
  236.  
  237.            Return FreeImage.GetBitmap(FreeImage.MakeThumbnail(Image, size, convert))
  238.  
  239.        Catch ex As Exception
  240.            ' Throw New Exception(ex.Message)
  241.            MsgBox(ex.Message)
  242.            Return Nothing
  243.        End Try
  244.  
  245.    End Function
  246.  
  247.    ' <summary>
  248.    ' Returns a Thumbnail of a image file.
  249.    ' </summary>
  250.    Shared Function Thumbnail(ByVal File As String, _
  251.                                   ByVal size As Int32, _
  252.                                   ByVal convert As Boolean) As System.Drawing.Bitmap
  253.  
  254.        Try
  255.            Return FreeImage.GetBitmap(FreeImage.MakeThumbnail(FreeImage.LoadEx(File), size, convert))
  256.        Catch ex As Exception
  257.            ' Throw New Exception(ex.Message)
  258.            MsgBox(ex.Message)
  259.            Return Nothing
  260.        End Try
  261.  
  262.    End Function
  263.  
  264. End Class
  265.  
  266. #End Region





Informa a Windows de cambios en el sistema para refrescar el sistema.

Código
  1. #Region " System Notifier "
  2.  
  3. ' [ System Notifier ]
  4. '
  5. ' Examples :
  6. '
  7. ' SystemNotifier.Notify(SystemNotifier.EventID.FileAssociation_Changed, SystemNotifier.NotifyFlags.DWORD, IntPtr.Zero, IntPtr.Zero)
  8.  
  9. Public Class SystemNotifier
  10.  
  11.    <System.Runtime.InteropServices.DllImport("shell32.dll")> _
  12.    Shared Sub SHChangeNotify( _
  13.        ByVal wEventID As EventID, _
  14.        ByVal uFlags As NotifyFlags, _
  15.        ByVal dwItem1 As IntPtr, _
  16.        ByVal dwItem2 As IntPtr)
  17.    End Sub
  18.  
  19.    Shared Sub Notify(ByVal wEventID As EventID, ByVal uFlags As NotifyFlags, ByVal dwItem1 As IntPtr, ByVal dwItem2 As IntPtr)
  20.        SHChangeNotify(wEventID, uFlags, dwItem1, dwItem2)
  21.    End Sub
  22.  
  23.    <Flags()> _
  24.    Public Enum NotifyFlags
  25.  
  26.        ' <summary>
  27.        ' The <i>dwItem1</i> and <i>dwItem2</i> parameters are DWORD values.
  28.        ' </summary>
  29.        DWORD = &H3
  30.  
  31.        ' <summary>
  32.        ' <i>dwItem1</i> and <i>dwItem2</i> are the addresses of ItemIDList structures,
  33.        ' that represent the item(s) affected by the change.
  34.        ' Each ItemIDList must be relative to the desktop folder.
  35.        ' </summary>
  36.        ItemIDList = &H0
  37.  
  38.        ' <summary>
  39.        ' <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings,
  40.        ' of maximum length MAX_PATH that contain the full path names of the items affected by the change.
  41.        ' </summary>
  42.        PathA = &H1
  43.  
  44.        ' <summary>
  45.        ' <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings,
  46.        ' of maximum length MAX_PATH that contain the full path names of the items affected by the change.
  47.        ' </summary>
  48.        PathW = &H5
  49.  
  50.        ' <summary>
  51.        ' <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings,
  52.        ' that represent the friendly names of the printer(s) affected by the change.
  53.        ' </summary>
  54.        PrinterA = &H2
  55.  
  56.        ' <summary>
  57.        ' <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings,
  58.        ' that represent the friendly names of the printer(s) affected by the change.
  59.        ' </summary>
  60.        PrinterW = &H6
  61.  
  62.        ' <summary>
  63.        ' The function should not return until the notification has been delivered to all affected components.
  64.        ' As this flag modifies other data-type flags it cannot by used by itself.
  65.        ' </summary>
  66.        Flush = &H1000
  67.  
  68.        ' <summary>
  69.        ' The function should begin delivering notifications to all affected components,
  70.        ' but should return as soon as the notification process has begun.
  71.        ' As this flag modifies other data-type flags it cannot by used by itself.
  72.        ' </summary>
  73.        FlushNoWait = &H2000
  74.  
  75.    End Enum
  76.  
  77.    <Flags()> _
  78.    Public Enum EventID
  79.  
  80.        ' <summary>
  81.        ' All events have occurred.
  82.        ' </summary>
  83.        All_Events = &H7FFFFFFF
  84.  
  85.        ' <summary>
  86.        ' A folder has been created.
  87.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  88.        ' <i>dwItem1</i> contains the folder that was created.
  89.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  90.        ' </summary>
  91.        Directory_Created = &H8
  92.  
  93.        ' <summary>
  94.        ' A folder has been removed.
  95.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  96.        ' <i>dwItem1</i> contains the folder that was removed.
  97.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  98.        ' </summary>
  99.        Directory_Deleted = &H10
  100.  
  101.        ' <summary>
  102.        ' The name of a folder has changed.
  103.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  104.        ' <i>dwItem1</i> contains the previous pointer to an item identifier list (PIDL) or name of the folder.
  105.        ' <i>dwItem2</i> contains the new PIDL or name of the folder.
  106.        ' </summary>
  107.        Directory_Renamed = &H20000
  108.  
  109.        ' <summary>
  110.        ' A nonfolder item has been created.
  111.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  112.        ' <i>dwItem1</i> contains the item that was created.
  113.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  114.        ' </summary>
  115.        Item_Created = &H2
  116.  
  117.        ' <summary>
  118.        ' A nonfolder item has been deleted.
  119.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  120.        ' <i>dwItem1</i> contains the item that was deleted.
  121.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  122.        ' </summary>
  123.        Item_Deleted = &H4
  124.  
  125.        ' <summary>
  126.        ' The name of a nonfolder item has changed.
  127.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  128.        ' <i>dwItem1</i> contains the previous PIDL or name of the item.
  129.        ' <i>dwItem2</i> contains the new PIDL or name of the item.
  130.        ' </summary>
  131.        Item_Renamed = &H1
  132.  
  133.        ' <summary>
  134.        ' A drive has been added.
  135.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  136.        ' <i>dwItem1</i> contains the root of the drive that was added.
  137.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  138.        ' </summary>
  139.        Drive_Added = &H100
  140.  
  141.        ' <summary>
  142.        ' A drive has been added and the Shell should create a new window for the drive.
  143.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  144.        ' <i>dwItem1</i> contains the root of the drive that was added.
  145.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  146.        ' </summary>
  147.        Drive_Added_Shell = &H10000
  148.  
  149.        ' <summary>
  150.        ' A drive has been removed. <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  151.        ' <i>dwItem1</i> contains the root of the drive that was removed.
  152.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  153.        ' </summary>
  154.        Drive_Removed = &H80
  155.  
  156.        ' <summary>
  157.        ' Storage media has been inserted into a drive.
  158.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  159.        ' <i>dwItem1</i> contains the root of the drive that contains the new media.
  160.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  161.        ' </summary>
  162.        Media_Inserted = &H20
  163.  
  164.        ' <summary>
  165.        ' Storage media has been removed from a drive.
  166.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  167.        ' <i>dwItem1</i> contains the root of the drive from which the media was removed.
  168.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  169.        ' </summary>
  170.        Media_Removed = &H40
  171.  
  172.        ' <summary>
  173.        ' A folder on the local computer is being shared via the network.
  174.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  175.        ' <i>dwItem1</i> contains the folder that is being shared.
  176.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  177.        ' </summary>
  178.        Net_Shared = &H200
  179.  
  180.        ' <summary>
  181.        ' A folder on the local computer is no longer being shared via the network.
  182.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  183.        ' <i>dwItem1</i> contains the folder that is no longer being shared.
  184.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  185.        ' </summary>
  186.        Net_Unshared = &H400
  187.  
  188.        ' <summary>
  189.        ' The computer has disconnected from a server.
  190.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  191.        ' <i>dwItem1</i> contains the server from which the computer was disconnected.
  192.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  193.        ' </summary>
  194.        Server_Disconnected = &H4000
  195.  
  196.        ' <summary>
  197.        ' The attributes of an item or folder have changed.
  198.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  199.        ' <i>dwItem1</i> contains the item or folder that has changed.
  200.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  201.        ' </summary>
  202.        Attributes_Changed = &H800
  203.  
  204.        ' <summary>
  205.        ' A file type association has changed. <see cref="NotifyFlags.ItemIDList"/>
  206.        ' must be specified in the <i>uFlags</i> parameter.
  207.        ' <i>dwItem1</i> and <i>dwItem2</i> are not used and must be <see langword="null"/>.
  208.        ' </summary>
  209.        FileAssociation_Changed = &H8000000
  210.  
  211.        ' <summary>
  212.        ' The amount of free space on a drive has changed.
  213.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  214.        ' <i>dwItem1</i> contains the root of the drive on which the free space changed.
  215.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  216.        ' </summary>
  217.        Freespace_Changed = &H40000
  218.  
  219.        ' <summary>
  220.        ' The contents of an existing folder have changed but the folder still exists and has not been renamed.
  221.        ' <see cref="NotifyFlags.ItemIDList"/> or <see cref="NotifyFlags.PathA"/> must be specified in <i>uFlags</i>.
  222.        ' <i>dwItem1</i> contains the folder that has changed.
  223.        ' <i>dwItem2</i> is not used and should be <see langword="null"/>.
  224.        ' If a folder has been created, deleted or renamed use Directory_Created, Directory_Removed or Directory_Renamed respectively instead.
  225.        ' </summary>
  226.        Update_Directory = &H1000
  227.  
  228.        ' <summary>
  229.        ' An image in the system image list has changed.
  230.        ' <see cref="NotifyFlags.DWORD"/> must be specified in <i>uFlags</i>.
  231.        ' </summary>
  232.        Update_Image = &H8000
  233.  
  234.    End Enum
  235.  
  236. End Class
  237.  
  238. #End Region
« Última modificación: 20 Julio 2013, 11:08 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #258 en: 21 Julio 2013, 02:15 am »

No apruebo el uso de aplicaciones commandline a menos que sea para situaciones complicadas y tediosas como esta...

...Una class para usar SETACL para modificar el propietario de una clave de registro y para modificar los permisos de la clave:

PD: a ver si alguien nos sorprende con un código nativo...  :silbar:

Código
  1. #Region " SETACL Helper "
  2.  
  3.  
  4. ' [ SETACL Helper ]
  5. '
  6. ' // By Elektro H@cker
  7. '
  8. '
  9. ' INSTRUCTIONS:
  10. ' 1. Add the "SETACL.exe" in the project.
  11. '
  12. ' Examples :
  13. '
  14. ' SETACL.Set_Owner("HKCU\Test", True)
  15. ' SETACL.Set_Permission("HKCU\Test\", SETACL.SETACL_Permission.full, False)
  16.  
  17.  
  18. Public Class SETACL
  19.  
  20.    ' <summary>
  21.    ' Gets or sets the SETACL executable path.
  22.    ' </summary>
  23.    Public Shared SETACL_Location As String = ".\SetACL.exe"
  24.  
  25.    ' <summary>
  26.    ' Gets or sets the SETACL logfile filename.
  27.    ' </summary>
  28.    Public Shared SETACL_Logfile As String = ".\SetACL.log"
  29.  
  30.  
  31.    Public Enum SETACL_Permission
  32.  
  33.        ' <summary>
  34.        ' Create link
  35.        ' </summary>
  36.        create_link
  37.  
  38.        ' <summary>
  39.        ' Create subkeys
  40.        ' </summary>
  41.        create_subkey
  42.  
  43.        ' <summary>
  44.        ' Delete
  45.        ' </summary>
  46.        delete
  47.  
  48.        ' <summary>
  49.        ' Enumerate subkeys
  50.        ' </summary>
  51.        enum_subkeys
  52.  
  53.        ' <summary>
  54.        ' Notify
  55.        ' </summary>
  56.        notify
  57.  
  58.        ' <summary>
  59.        ' Query value
  60.        ' </summary>
  61.        query_val
  62.  
  63.        ' <summary>
  64.        ' Read control
  65.        ' </summary>
  66.        read_access
  67.  
  68.        ' <summary>
  69.        ' Set value
  70.        ' </summary>
  71.        set_val
  72.  
  73.        ' <summary>
  74.        ' Write permissions
  75.        ' </summary>
  76.        write_dacl
  77.  
  78.        ' <summary>
  79.        ' Take ownership
  80.        ' </summary>
  81.        write_owner
  82.  
  83.  
  84.        ' <summary>
  85.        ' Read (KEY_ENUMERATE_SUB_KEYS + KEY_EXECUTE + KEY_NOTIFY + KEY_QUERY_VALUE + KEY_READ + READ_CONTROL)
  86.        ' </summary>
  87.        read
  88.  
  89.        ' <summary>
  90.        ' Full access
  91.        ' (KEY_CREATE_LINK + KEY_CREATE_SUB_KEY +KEY_ENUMERATE_SUB_KEYS + ...
  92.        ' ...KEY_EXECUTE + KEY_NOTIFY + KEY_QUERY_VALUE + KEY_READ + KEY_SET_VALUE + ...
  93.        ' ...KEY_WRITE + READ_CONTROL + WRITE_OWNER + WRITE_DAC + DELETE)
  94.        ' </summary>
  95.        full
  96.  
  97.    End Enum
  98.  
  99.    ' <summary>
  100.    ' Checks if SETACL process is avaliable.
  101.    ' </summary>
  102.    Public Shared Function Is_Avaliable() As Boolean
  103.        Return IO.File.Exists(SETACL_Location)
  104.    End Function
  105.  
  106.    ' <summary>
  107.    ' Takes ownership of a registry key.
  108.    ' </summary>
  109.    Public Shared Sub Set_Owner(ByVal RegKey As String, ByVal Recursive As Boolean, Optional ByVal UserName As String = "%USERNAME%")
  110.  
  111.        If RegKey.EndsWith("\") Then RegKey = RegKey.Substring(0, RegKey.Length - 1)
  112.  
  113.        Dim Recursion As String = "No" : If Recursive Then Recursion = "Yes"
  114.  
  115.        Dim SETACL As New Process(), SETACL_Info As New ProcessStartInfo()
  116.  
  117.        SETACL_Info.FileName = SETACL_Location
  118.        SETACL_Info.Arguments = String.Format("-on ""{0}"" -ot reg -ownr ""n:{1}"" -rec ""{2}"" -actn setowner -silent -ignoreerr -log ""{3}""", RegKey, UserName, Recursion, SETACL_Logfile)
  119.        SETACL_Info.CreateNoWindow = True
  120.        SETACL_Info.UseShellExecute = False
  121.        SETACL.StartInfo = SETACL_Info
  122.        SETACL.Start()
  123.        SETACL.WaitForExit()
  124.  
  125.        If SETACL.ExitCode <> 0 Then
  126.            ' Throw New Exception("Exit code: " & SETACL.ExitCode)
  127.            MsgBox(IO.File.ReadAllText(SETACL_Logfile))
  128.        End If
  129.  
  130.    End Sub
  131.  
  132.    ' <summary>
  133.    ' Sets the user permission of a registry key.
  134.    ' </summary>
  135.    Public Shared Sub Set_Permission(ByVal RegKey As String, ByVal Permission As SETACL_Permission, ByVal Recursive As Boolean, Optional ByVal UserName As String = "%USERNAME%")
  136.  
  137.        If RegKey.EndsWith("\") Then RegKey = RegKey.Substring(0, RegKey.Length - 1)
  138.  
  139.        Dim Recursion As String = "No" : If Recursive Then Recursion = "Yes"
  140.  
  141.        Dim SETACL As New Process(), SETACL_Info As New ProcessStartInfo()
  142.  
  143.        SETACL_Info.FileName = SETACL_Location
  144.        SETACL_Info.Arguments = String.Format("-on ""{0}"" -ot reg -ace ""n:{1};p:{2}"" -rec ""{3}"" -actn ace -silent -ignoreerr -log ""{4}""", RegKey, UserName, Permission, Recursion, SETACL_Logfile)
  145.        SETACL_Info.CreateNoWindow = True
  146.        SETACL_Info.UseShellExecute = False
  147.        SETACL.StartInfo = SETACL_Info
  148.        SETACL.Start()
  149.        SETACL.WaitForExit()
  150.  
  151.        If SETACL.ExitCode <> 0 Then
  152.            ' Throw New Exception("Exit code: " & SETACL.ExitCode)
  153.            MsgBox(IO.File.ReadAllText(SETACL_Logfile))
  154.        End If
  155.  
  156.    End Sub
  157.  
  158. End Class
  159.  
  160. #End Region
« Última modificación: 21 Julio 2013, 02:36 am por EleKtro H@cker » En línea

Novlucker
Ninja y
Colaborador
***
Desconectado Desconectado

Mensajes: 10.683

Yo que tu lo pienso dos veces


Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #259 en: 21 Julio 2013, 04:01 am »

http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.setaccesscontrol.aspx
En línea

Contribuye con la limpieza del foro, reporta los "casos perdidos" a un MOD XD
"Hay dos cosas infinitas: el Universo y la estupidez  humana. Y de la primera no estoy muy seguro."
Albert Einstein
Páginas: 1 ... 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [26] 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 ... 58 Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines