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

 

 


Tema destacado: Estamos en la red social de Mastodon


  Mostrar Mensajes
Páginas: 1 ... 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 [740] 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 ... 1236
7391  Sistemas Operativos / Windows / Re: ayuda con windows... en: 23 Febrero 2014, 13:38 pm
Opino lo mismo que @Dato000,
trastear con el bootloader sólamente para probar un SO (o en este caso decidir si te gusta un Windows) se podría considerar algo prehistórico en los tiempos que corren (y peligroso para las personas que no se manejan bien con los dual-boots), teniendo virtualizadores de sistemas operativos como VirtualBox, lo pruebas y luego si decides que te gusta pues te lo instalas en tu PC para comprobar los demás aspectos como la compatibilidad de Hardware, aunque si lo único que te preocupa es la compatibilidad con tu Bios, según Microsoft se puede instalar en una Bios MBR, EFI o UEFI:

http://windows.microsoft.com/en-us/windows-8/system-requirements
http://technet.microsoft.com/en-us/windows/jj721676.aspx

Saludos.
7392  Programación / Scripting / Re: [BATCH][APORTE] WSS (Windows Seven Shrinker). Limpiador postinstall y WINSXS en: 23 Febrero 2014, 08:42 am
@CrashSomeMore

Thankyou for comment.

It's possible that maybe (or maybe not) the reason why you've encountered bugs/crashes could be that I only did the script testing it on a Win7 x64 ISO build in Spanish lang and maybe some critical English directories are removed by the Script (I don't remember it now).

Sorry mate but since I've migrated to Win 8.1 I've never performed updates on the Shrinker-script for Win 7.

PS: If you're interested into the Shrinker for Win8.1 just reply to this message to provide it for you, but instead working on a installed Windows now the script works on a mounted directory of the ISO, to shrink it and burn it, it shrinks more than 1 GB on the original ISO (that means a lot of GB's on the installation) and all works as expected, even NetFX 3.5 and Win updates. :)

Regards.
7393  Programación / .NET (C#, VB.NET, ASP) / Re: Control para seleccionar Carpetas [Solucionado] en: 23 Febrero 2014, 01:18 am
(Porfavor la próxima vez no hagas doble post, utiliza el botón MODIFICAR)



Tienes toda la razón del mundo, es un coñazo usar el FolderBrowserDialog, yo lo veo como un diálogo obsoleto y dificil de manejar, con muy poco rendimiento, ya que con el diálogo de carpetas de Windows puedes acceder a una ubicación en 5 segundos escribiendo la ubicación o usando las ubicaciones favoritas, mientras que con el FolderBrowserDialog pierdes mucho más tiempo expandiendo carpetas ...una por una.
Es una completa basura.

La solución de terceros que has mostrado ....bueno, es una solución y es customizable, pero no tiene ventajas sobre la navegación de directorios, debería customizarse en más aspectos la Class ...cosa que resultaría laboriosa. Así que sin ánimo de ofender al autor del código, me parece algo muy cutre heredar un 'CommonDialog' para hacer sólamente eso.

Te propongo algo más eficiente, usando la librería Windows API Code Pack que provee Microsoft.

Te muestro un ejemplo de uso:

Código
  1.    ' WindowsAPICodePack 'CommonOpenFileDialog' Example.
  2.    ' ( By Elektro )
  3.    '
  4.    ' Instructions:
  5.    ' 1. Reference "Microsoft.WindowsAPICodePack.dll" and "Microsoft.WindowsAPICodePack.Shell.dll".
  6.  
  7.    Imports Microsoft.WindowsAPICodePack.Dialogs
  8.    Imports Microsoft.WindowsAPICodePack.Shell
  9.  
  10.    ''' <summary>
  11.    ''' The WindowsAPICodePack 'CommonOpenFileDialog' instance.
  12.    ''' </summary>
  13.    Private WithEvents FolderPicker As New CommonOpenFileDialog With
  14.        {
  15.            .Title = "Folder Picker Test",
  16.            .DefaultDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
  17.            .InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
  18.            .DefaultFileName = "C:\",
  19.            .IsFolderPicker = True,
  20.            .Multiselect = False,
  21.            .ShowPlacesList = True,
  22.            .ShowHiddenItems = True,
  23.            .EnsurePathExists = True,
  24.            .RestoreDirectory = False,
  25.            .NavigateToShortcut = True,
  26.            .AllowNonFileSystemItems = True,
  27.            .AddToMostRecentlyUsedList = True
  28.        }
  29.  
  30.    ''' <summary>
  31.    ''' Handles the Click event of the Button1 control.
  32.    ''' </summary>
  33.    ''' <param name="sender">The source of the event.</param>
  34.    ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  35.    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  36.  
  37.        ' If folder is picked then...
  38.        If FolderPicker.ShowDialog() = CommonFileDialogResult.Ok Then
  39.  
  40.            Dim SelectedFolder As ShellObject = FolderPicker.FileAsShellObject
  41.            MsgBox(SelectedFolder.GetDisplayName(DisplayNameType.FileSystemPath))
  42.  
  43.        End If
  44.  
  45.        ' FolderPicker.Dispose()
  46.  
  47.    End Sub
  48.  
  49.    ''' <summary>
  50.    ''' Handles the FolderChanging event of the FolderPicker control.
  51.    ''' </summary>
  52.    ''' <param name="sender">The source of the event.</param>
  53.    ''' <param name="e">The <see cref="Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogFolderChangeEventArgs"/> instance containing the event data.</param>
  54.    Private Sub FolderPicker_FolderChanging(sender As Object, e As CommonFileDialogFolderChangeEventArgs) _
  55.    Handles FolderPicker.FolderChanging
  56.  
  57.        ' Restrict the navigation on specific folders.
  58.        Select Case True
  59.  
  60.            Case e.Folder = Environment.GetFolderPath(Environment.SpecialFolder.Windows)
  61.                '  Restricts the navigation to 'Windows' directory.
  62.                e.Cancel = True
  63.  
  64.            Case e.Folder.Equals("C:\Juegos", StringComparison.CurrentCultureIgnoreCase)
  65.                ' Restricts the navigation to 'C:\Juegos' directory.
  66.                e.Cancel = True
  67.  
  68.            Case e.Folder.Split("\").Last.Equals("Administrador", StringComparison.CurrentCultureIgnoreCase)
  69.                ' Restricts the navigation to any directory name ending in "Administrador" keyword.
  70.                e.Cancel = True
  71.  
  72.            Case Else
  73.                ' Allow navigation on that directory.
  74.                e.Cancel = False
  75.  
  76.        End Select
  77.  
  78.    End Sub

PD: Y si no quieres depender de librerías siempre puedes sacar la parte importante del código fuente que va incluido.
PD: Además, ese kit de librerías en el futuro te proporcionarían ventajas y comodidades para usar otros tipos de controles y classes muy interesantes.

O también puedes usar la librería Ooki Dialogs, que son diálogos basados en Windows VISTA y es la librería que yo usaba como reemplazamiento del 'FolderBrowserDialog', antes de conocer la existencia de 'WindowsAPICodePack'.

Un mini ejemplo de uso:

Código
  1.  Dim FolderPicker As New Ookii.Dialogs.VistaFolderBrowserDialog
  2.  FolderPicker.ShowNewFolderButton = True
  3.  
  4.  If FolderPicker.ShowDialog.ToString() = "OK" Then
  5.      msgbox(FolderPicker.SelectedPath)
  6.  End If
  7.  
  8.  ' FolderPicker.Dispose()

Saludos.
7394  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 21 Febrero 2014, 12:18 pm
Un helper class para el método SendInput de la WinAPI

Synthesizes keystrokes, mouse motions, and button clicks.

PD: El método 'sendkeys' no es 100% perfecto con caracteres especiales como la 'Ñ', pero tampoco lo voy a elaborar más por el momento,ya que es un coñazo por los distintos layouts del teclado.

Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 02-21-2014
  4. ' ***********************************************************************
  5. ' <copyright file="SendInputs.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Usage Examples "
  11.  
  12. 'Private Sub Test() Handles Button1.Click
  13.  
  14. ' AppActivate(Process.GetProcessesByName("notepad").First.Id)
  15.  
  16. ' Dim c As Char = Convert.ToChar(Keys.Oemtilde) ' Ñ
  17. ' Dim Result As Integer = SendInputs.SendKey(Convert.ToChar(c.ToString.ToLower))
  18. ' MessageBox.Show(String.Format("Successfull events: {0}", CStr(Result)))
  19.  
  20. ' SendInputs.SendKey(Keys.Enter)
  21. ' SendInputs.SendKey(Convert.ToChar(Keys.Back))
  22. ' SendInputs.SendKeys("Hello World", True)
  23. ' SendInputs.SendKey(Convert.ToChar(Keys.D0))
  24. ' SendInputs.SendKeys(Keys.Insert, BlockInput:=True)
  25.  
  26. ' SendInputs.MouseClick(SendInputs.MouseButton.RightPress, False)
  27. ' SendInputs.MouseMove(5, -5)
  28. ' SendInputs.MousePosition(New Point(100, 500))
  29.  
  30. 'End Sub
  31.  
  32. #End Region
  33.  
  34. #Region " Imports "
  35.  
  36. Imports System.Runtime.InteropServices
  37. Imports System.ComponentModel
  38.  
  39. #End Region
  40.  
  41. ''' <summary>
  42. ''' Synthesizes keystrokes, mouse motions, and button clicks.
  43. ''' </summary>
  44. Public Class SendInputs
  45.  
  46. #Region " P/Invoke "
  47.  
  48.    Friend Class NativeMethods
  49.  
  50. #Region " Methods "
  51.  
  52.        ''' <summary>
  53.        ''' Blocks keyboard and mouse input events from reaching applications.
  54.        ''' For more info see here:
  55.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646290%28v=vs.85%29.aspx
  56.        ''' </summary>
  57.        ''' <param name="fBlockIt">
  58.        ''' The function's purpose.
  59.        ''' If this parameter is 'TRUE', keyboard and mouse input events are blocked.
  60.        ''' If this parameter is 'FALSE', keyboard and mouse events are unblocked.
  61.        ''' </param>
  62.        ''' <returns>
  63.        ''' If the function succeeds, the return value is nonzero.
  64.        ''' If input is already blocked, the return value is zero.
  65.        ''' </returns>
  66.        ''' <remarks>
  67.        ''' Note that only the thread that blocked input can successfully unblock input.
  68.        ''' </remarks>
  69.        <DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall,
  70.        SetLastError:=True)>
  71.        Friend Shared Function BlockInput(
  72.               ByVal fBlockIt As Boolean
  73.        ) As Integer
  74.        End Function
  75.  
  76.        ''' <summary>
  77.        ''' Synthesizes keystrokes, mouse motions, and button clicks.
  78.        ''' For more info see here:
  79.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx
  80.        ''' </summary>
  81.        ''' <param name="nInputs">
  82.        ''' Indicates the number of structures in the pInputs array.
  83.        ''' </param>
  84.        ''' <param name="pInputs">
  85.        ''' Indicates an Array of 'INPUT' structures.
  86.        ''' Each structure represents an event to be inserted into the keyboard or mouse input stream.
  87.        ''' </param>
  88.        ''' <param name="cbSize">
  89.        ''' The size, in bytes, of an 'INPUT' structure.
  90.        ''' If 'cbSize' is not the size of an 'INPUT' structure, the function fails.
  91.        ''' </param>
  92.        ''' <returns>
  93.        ''' The function returns the number of events that it successfully
  94.        ''' inserted into the keyboard or mouse input stream.
  95.        ''' If the function returns zero, the input was already blocked by another thread.
  96.        ''' </returns>
  97.        <DllImport("user32.dll", SetLastError:=True)>
  98.        Friend Shared Function SendInput(
  99.               ByVal nInputs As Integer,
  100.               <MarshalAs(UnmanagedType.LPArray), [In]> ByVal pInputs As INPUT(),
  101.               ByVal cbSize As Integer
  102.        ) As Integer
  103.        End Function
  104.  
  105. #End Region
  106.  
  107. #Region " Enumerations "
  108.  
  109.        ''' <summary>
  110.        ''' VirtualKey codes.
  111.        ''' </summary>
  112.        Friend Enum VirtualKeys As Short
  113.  
  114.            ''' <summary>
  115.            ''' The Shift key.
  116.            ''' VK_SHIFT
  117.            ''' </summary>
  118.            SHIFT = &H10S
  119.  
  120.            ''' <summary>
  121.            ''' The DEL key.
  122.            ''' VK_DELETE
  123.            ''' </summary>
  124.            DELETE = 46S
  125.  
  126.            ''' <summary>
  127.            ''' The ENTER key.
  128.            ''' VK_RETURN
  129.            ''' </summary>
  130.            [RETURN] = 13S
  131.  
  132.        End Enum
  133.  
  134.        ''' <summary>
  135.        ''' The type of the input event.
  136.        ''' For more info see here:
  137.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646270%28v=vs.85%29.aspx
  138.        ''' </summary>
  139.        <Description("Enumeration used for 'type' parameter of 'INPUT' structure")>
  140.        Friend Enum InputType As Integer
  141.  
  142.            ''' <summary>
  143.            ''' The event is a mouse event.
  144.            ''' Use the mi structure of the union.
  145.            ''' </summary>
  146.            Mouse = 0
  147.  
  148.            ''' <summary>
  149.            ''' The event is a keyboard event.
  150.            ''' Use the ki structure of the union.
  151.            ''' </summary>
  152.            Keyboard = 1
  153.  
  154.            ''' <summary>
  155.            ''' The event is a hardware event.
  156.            ''' Use the hi structure of the union.
  157.            ''' </summary>
  158.            Hardware = 2
  159.  
  160.        End Enum
  161.  
  162.        ''' <summary>
  163.        ''' Specifies various aspects of a keystroke.
  164.        ''' This member can be certain combinations of the following values.
  165.        ''' For more info see here:
  166.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271%28v=vs.85%29.aspx
  167.        ''' </summary>
  168.        <Description("Enumeration used for 'dwFlags' parameter of 'KeyboardInput' structure")>
  169.        <Flags>
  170.        Friend Enum KeyboardInput_Flags As Integer
  171.  
  172.            ''' <summary>
  173.            ''' If specified, the scan code was preceded by a prefix byte that has the value '0xE0' (224).
  174.            ''' </summary>
  175.            ExtendedKey = &H1
  176.  
  177.            ''' <summary>
  178.            ''' If specified, the key is being pressed.
  179.            ''' </summary>
  180.            KeyDown = &H0
  181.  
  182.            ''' <summary>
  183.            ''' If specified, the key is being released.
  184.            ''' If not specified, the key is being pressed.
  185.            ''' </summary>
  186.            KeyUp = &H2
  187.  
  188.            ''' <summary>
  189.            ''' If specified, 'wScan' identifies the key and 'wVk' is ignored.
  190.            ''' </summary>
  191.            ScanCode = &H8
  192.  
  193.            ''' <summary>
  194.            ''' If specified, the system synthesizes a 'VK_PACKET' keystroke.
  195.            ''' The 'wVk' parameter must be '0'.
  196.            ''' This flag can only be combined with the 'KEYEVENTF_KEYUP' flag.
  197.            ''' </summary>
  198.            Unicode = &H4
  199.  
  200.        End Enum
  201.  
  202.        ''' <summary>
  203.        ''' A set of bit flags that specify various aspects of mouse motion and button clicks.
  204.        ''' The bits in this member can be any reasonable combination of the following values.
  205.        ''' For more info see here:
  206.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646273%28v=vs.85%29.aspx
  207.        ''' </summary>
  208.        <Description("Enumeration used for 'dwFlags' parameter of 'MouseInput' structure")>
  209.        <Flags>
  210.        Friend Enum MouseInput_Flags As Integer
  211.  
  212.            ''' <summary>
  213.            ''' The 'dx' and 'dy' members contain normalized absolute coordinates.
  214.            ''' If the flag is not set, 'dx' and 'dy' contain relative data
  215.            ''' (the change in position since the last reported position).
  216.            ''' This flag can be set, or not set,
  217.            ''' regardless of what kind of mouse or other pointing device, if any, is connected to the system.
  218.            ''' </summary>
  219.            Absolute = &H8000I
  220.  
  221.            ''' <summary>
  222.            ''' Movement occurred.
  223.            ''' </summary>
  224.            Move = &H1I
  225.  
  226.            ''' <summary>
  227.            ''' The 'WM_MOUSEMOVE' messages will not be coalesced.
  228.            ''' The default behavior is to coalesce 'WM_MOUSEMOVE' messages.
  229.            ''' </summary>
  230.            Move_NoCoalesce = &H2000I
  231.  
  232.            ''' <summary>
  233.            ''' The left button was pressed.
  234.            ''' </summary>
  235.            LeftDown = &H2I
  236.  
  237.            ''' <summary>
  238.            ''' The left button was released.
  239.            ''' </summary>
  240.            LeftUp = &H4I
  241.  
  242.            ''' <summary>
  243.            ''' The right button was pressed.
  244.            ''' </summary>
  245.            RightDown = &H8I
  246.  
  247.            ''' <summary>
  248.            ''' The right button was released.
  249.            ''' </summary>
  250.            RightUp = &H10I
  251.  
  252.            ''' <summary>
  253.            ''' The middle button was pressed.
  254.            ''' </summary>
  255.            MiddleDown = &H20I
  256.  
  257.            ''' <summary>
  258.            ''' The middle button was released.
  259.            ''' </summary>
  260.            MiddleUp = &H40I
  261.  
  262.            ''' <summary>
  263.            ''' Maps coordinates to the entire desktop.
  264.            ''' Must be used in combination with 'Absolute'.
  265.            ''' </summary>
  266.            VirtualDesk = &H4000I
  267.  
  268.            ''' <summary>
  269.            ''' The wheel was moved, if the mouse has a wheel.
  270.            ''' The amount of movement is specified in 'mouseData'.
  271.            ''' </summary>
  272.            Wheel = &H800I
  273.  
  274.            ''' <summary>
  275.            ''' The wheel was moved horizontally, if the mouse has a wheel.
  276.            ''' The amount of movement is specified in 'mouseData'.
  277.            ''' </summary>
  278.            HWheel = &H1000I
  279.  
  280.            ''' <summary>
  281.            ''' An X button was pressed.
  282.            ''' </summary>
  283.            XDown = &H80I
  284.  
  285.            ''' <summary>
  286.            ''' An X button was released.
  287.            ''' </summary>
  288.            XUp = &H100I
  289.  
  290.        End Enum
  291.  
  292. #End Region
  293.  
  294. #Region " Structures "
  295.  
  296.        ''' <summary>
  297.        ''' Used by 'SendInput' function
  298.        ''' to store information for synthesizing input events such as keystrokes, mouse movement, and mouse clicks.
  299.        ''' For more info see here:
  300.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646270%28v=vs.85%29.aspx
  301.        ''' </summary>
  302.        <Description("Structure used for 'INPUT' parameter of 'SendInput' API method")>
  303.        <StructLayout(LayoutKind.Explicit)>
  304.        Friend Structure Input
  305.  
  306.            ' ******
  307.            '  NOTE
  308.            ' ******
  309.            ' Field offset for 32 bit machine: 4
  310.            ' Field offset for 64 bit machine: 8
  311.  
  312.            ''' <summary>
  313.            ''' The type of the input event.
  314.            ''' </summary>
  315.            <FieldOffset(0)>
  316.            Public type As InputType
  317.  
  318.            ''' <summary>
  319.            ''' The information about a simulated mouse event.
  320.            ''' </summary>
  321.            <FieldOffset(8)>
  322.            Public mi As MouseInput
  323.  
  324.            ''' <summary>
  325.            ''' The information about a simulated keyboard event.
  326.            ''' </summary>
  327.            <FieldOffset(8)>
  328.            Public ki As KeyboardInput
  329.  
  330.            ''' <summary>
  331.            ''' The information about a simulated hardware event.
  332.            ''' </summary>
  333.            <FieldOffset(8)>
  334.            Public hi As HardwareInput
  335.  
  336.        End Structure
  337.  
  338.        ''' <summary>
  339.        ''' Contains information about a simulated mouse event.
  340.        ''' For more info see here:
  341.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646273%28v=vs.85%29.aspx
  342.        ''' </summary>
  343.        <Description("Structure used for 'mi' parameter of 'INPUT' structure")>
  344.        Friend Structure MouseInput
  345.  
  346.            ''' <summary>
  347.            ''' The absolute position of the mouse,
  348.            ''' or the amount of motion since the last mouse event was generated,
  349.            ''' depending on the value of the dwFlags member.
  350.            ''' Absolute data is specified as the 'x' coordinate of the mouse;
  351.            ''' relative data is specified as the number of pixels moved.
  352.            ''' </summary>
  353.            Public dx As Integer
  354.  
  355.            ''' <summary>
  356.            ''' The absolute position of the mouse,
  357.            ''' or the amount of motion since the last mouse event was generated,
  358.            ''' depending on the value of the dwFlags member.
  359.            ''' Absolute data is specified as the 'y' coordinate of the mouse;
  360.            ''' relative data is specified as the number of pixels moved.
  361.            ''' </summary>
  362.            Public dy As Integer
  363.  
  364.            ''' <summary>
  365.            ''' If 'dwFlags' contains 'MOUSEEVENTF_WHEEL',
  366.            ''' then 'mouseData' specifies the amount of wheel movement.
  367.            ''' A positive value indicates that the wheel was rotated forward, away from the user;
  368.            ''' a negative value indicates that the wheel was rotated backward, toward the user.
  369.            ''' One wheel click is defined as 'WHEEL_DELTA', which is '120'.
  370.            '''
  371.            ''' If 'dwFlags' does not contain 'MOUSEEVENTF_WHEEL', 'MOUSEEVENTF_XDOWN', or 'MOUSEEVENTF_XUP',
  372.            ''' then mouseData should be '0'.
  373.            ''' </summary>
  374.            Public mouseData As Integer
  375.  
  376.            ''' <summary>
  377.            ''' A set of bit flags that specify various aspects of mouse motion and button clicks.
  378.            ''' The bits in this member can be any reasonable combination of the following values.
  379.            ''' The bit flags that specify mouse button status are set to indicate changes in status,
  380.            ''' not ongoing conditions.
  381.            ''' For example, if the left mouse button is pressed and held down,
  382.            ''' 'MOUSEEVENTF_LEFTDOWN' is set when the left button is first pressed,
  383.            ''' but not for subsequent motions.
  384.            ''' Similarly, 'MOUSEEVENTF_LEFTUP' is set only when the button is first released.
  385.            '''
  386.            ''' You cannot specify both the 'MOUSEEVENTF_WHEE'L flag
  387.            ''' and either 'MOUSEEVENTF_XDOWN' or 'MOUSEEVENTF_XUP' flags simultaneously in the 'dwFlags' parameter,
  388.            ''' because they both require use of the 'mouseData' field.
  389.            ''' </summary>
  390.            Public dwFlags As MouseInput_Flags
  391.  
  392.            ''' <summary>
  393.            ''' The time stamp for the event, in milliseconds.
  394.            ''' If this parameter is '0', the system will provide its own time stamp.
  395.            ''' </summary>
  396.            Public time As Integer
  397.  
  398.            ''' <summary>
  399.            ''' An additional value associated with the mouse event.
  400.            ''' An application calls 'GetMessageExtraInfo' to obtain this extra information.
  401.            ''' </summary>
  402.            Public dwExtraInfo As IntPtr
  403.  
  404.        End Structure
  405.  
  406.        ''' <summary>
  407.        ''' Contains information about a simulated keyboard event.
  408.        ''' For more info see here:
  409.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271%28v=vs.85%29.aspx
  410.        ''' </summary>
  411.        <Description("Structure used for 'ki' parameter of 'INPUT' structure")>
  412.        Friend Structure KeyboardInput
  413.  
  414.            ''' <summary>
  415.            ''' A virtual-key code.
  416.            ''' The code must be a value in the range '1' to '254'.
  417.            ''' If the 'dwFlags' member specifies 'KEYEVENTF_UNICODE', wVk must be '0'.
  418.            ''' </summary>
  419.            Public wVk As Short
  420.  
  421.            ''' <summary>
  422.            ''' A hardware scan code for the key.
  423.            ''' If 'dwFlags' specifies 'KEYEVENTF_UNICODE',
  424.            ''' 'wScan' specifies a Unicode character which is to be sent to the foreground application.
  425.            ''' </summary>
  426.            Public wScan As Short
  427.  
  428.            ''' <summary>
  429.            ''' Specifies various aspects of a keystroke.
  430.            ''' </summary>
  431.            Public dwFlags As KeyboardInput_Flags
  432.  
  433.            ''' <summary>
  434.            ''' The time stamp for the event, in milliseconds.
  435.            ''' If this parameter is '0', the system will provide its own time stamp.
  436.            ''' </summary>
  437.            Public time As Integer
  438.  
  439.            ''' <summary>
  440.            ''' An additional value associated with the keystroke.
  441.            ''' Use the 'GetMessageExtraInfo' function to obtain this information.
  442.            ''' </summary>
  443.            Public dwExtraInfo As IntPtr
  444.  
  445.        End Structure
  446.  
  447.        ''' <summary>
  448.        ''' Contains information about a simulated message generated by an input device other than a keyboard or mouse.
  449.        ''' For more info see here:
  450.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646269%28v=vs.85%29.aspx
  451.        ''' </summary>
  452.        <Description("Structure used for 'hi' parameter of 'INPUT' structure")>
  453.        Friend Structure HardwareInput
  454.  
  455.            ''' <summary>
  456.            ''' The message generated by the input hardware.
  457.            ''' </summary>
  458.            Public uMsg As Integer
  459.  
  460.            ''' <summary>
  461.            ''' The low-order word of the lParam parameter for uMsg.
  462.            ''' </summary>
  463.            Public wParamL As Short
  464.  
  465.            ''' <summary>
  466.            ''' The high-order word of the lParam parameter for uMsg.
  467.            ''' </summary>
  468.            Public wParamH As Short
  469.  
  470.        End Structure
  471.  
  472. #End Region
  473.  
  474.    End Class
  475.  
  476. #End Region
  477.  
  478. #Region " Enumerations "
  479.  
  480.    ''' <summary>
  481.    ''' Indicates a mouse button.
  482.    ''' </summary>
  483.    <Description("Enumeration used for 'MouseAction' parameter of 'MouseClick' function.")>
  484.    Public Enum MouseButton As Integer
  485.  
  486.        ''' <summary>
  487.        ''' Hold the left button.
  488.        ''' </summary>
  489.        LeftDown = &H2I
  490.  
  491.        ''' <summary>
  492.        ''' Release the left button.
  493.        ''' </summary>
  494.        LeftUp = &H4I
  495.  
  496.        ''' <summary>
  497.        ''' Hold the right button.
  498.        ''' </summary>
  499.        RightDown = &H8I
  500.  
  501.        ''' <summary>
  502.        ''' Release the right button.
  503.        ''' </summary>
  504.        RightUp = &H10I
  505.  
  506.        ''' <summary>
  507.        ''' Hold the middle button.
  508.        ''' </summary>
  509.        MiddleDown = &H20I
  510.  
  511.        ''' <summary>
  512.        ''' Release the middle button.
  513.        ''' </summary>
  514.        MiddleUp = &H40I
  515.  
  516.        ''' <summary>
  517.        ''' Press the left button.
  518.        ''' ( Hold + Release )
  519.        ''' </summary>
  520.        LeftPress = LeftDown + LeftUp
  521.  
  522.        ''' <summary>
  523.        ''' Press the Right button.
  524.        ''' ( Hold + Release )
  525.        ''' </summary>
  526.        RightPress = RightDown + RightUp
  527.  
  528.        ''' <summary>
  529.        ''' Press the Middle button.
  530.        ''' ( Hold + Release )
  531.        ''' </summary>
  532.        MiddlePress = MiddleDown + MiddleUp
  533.  
  534.    End Enum
  535.  
  536. #End Region
  537.  
  538. #Region " Public Methods "
  539.  
  540.    ''' <summary>
  541.    ''' Sends a keystroke.
  542.    ''' </summary>
  543.    ''' <param name="key">
  544.    ''' Indicates the keystroke to simulate.
  545.    ''' </param>
  546.    ''' <param name="BlockInput">
  547.    ''' If set to <c>true</c>, the keyboard and mouse are blocked until the keystroke is sent.
  548.    ''' </param>
  549.    ''' <returns>
  550.    ''' The function returns the number of events that it successfully inserted into the keyboard input stream.
  551.    ''' If the function returns zero, the input was already blocked by another thread.
  552.    ''' </returns>
  553.    Public Shared Function SendKey(ByVal key As Char,
  554.                                   Optional BlockInput As Boolean = False) As Integer
  555.  
  556.        ' Block Keyboard and mouse.
  557.        If BlockInput Then NativeMethods.BlockInput(True)
  558.  
  559.        ' The inputs structures to send.
  560.        Dim Inputs As New List(Of NativeMethods.INPUT)
  561.  
  562.        ' The current input to add into the Inputs list.
  563.        Dim CurrentInput As New NativeMethods.INPUT
  564.  
  565.        ' Determines whether a character is an alphabetic letter.
  566.        Dim IsAlphabetic As Boolean = Not (key.ToString.ToUpper = key.ToString.ToLower)
  567.  
  568.        ' Determines whether a character is an uppercase alphabetic letter.
  569.        Dim IsUpperCase As Boolean =
  570.            (key.ToString = key.ToString.ToUpper) AndAlso Not (key.ToString.ToUpper = key.ToString.ToLower)
  571.  
  572.        ' Determines whether the CapsLock key is pressed down.
  573.        Dim CapsLockON As Boolean = My.Computer.Keyboard.CapsLock
  574.  
  575.        ' Set the passed key to upper-case.
  576.        If IsAlphabetic AndAlso Not IsUpperCase Then
  577.            key = Convert.ToChar(key.ToString.ToUpper)
  578.        End If
  579.  
  580.        ' If character is alphabetic and is UpperCase and CapsLock is pressed down,
  581.        ' OrElse character is alphabetic and is not UpperCase and CapsLock is not pressed down,
  582.        ' OrElse character is not alphabetic.
  583.        If (IsAlphabetic AndAlso IsUpperCase AndAlso CapsLockON) _
  584.        OrElse (IsAlphabetic AndAlso Not IsUpperCase AndAlso Not CapsLockON) _
  585.        OrElse (Not IsAlphabetic) Then
  586.  
  587.            ' Hold the character key.
  588.            With CurrentInput
  589.                .type = NativeMethods.InputType.Keyboard
  590.                .ki.wVk = Convert.ToInt16(CChar(key))
  591.                .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyDown
  592.            End With : Inputs.Add(CurrentInput)
  593.  
  594.            ' Release the character key.
  595.            With CurrentInput
  596.                .type = NativeMethods.InputType.Keyboard
  597.                .ki.wVk = Convert.ToInt16(CChar(key))
  598.                .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyUp
  599.            End With : Inputs.Add(CurrentInput)
  600.  
  601.            ' If character is alphabetic and is UpperCase and CapsLock is not pressed down,
  602.            ' OrElse character is alphabetic and is not UpperCase and CapsLock is pressed down.
  603.        ElseIf (IsAlphabetic AndAlso IsUpperCase AndAlso Not CapsLockON) _
  604.        OrElse (IsAlphabetic AndAlso Not IsUpperCase AndAlso CapsLockON) Then
  605.  
  606.            ' Hold the Shift key.
  607.            With CurrentInput
  608.                .type = NativeMethods.InputType.Keyboard
  609.                .ki.wVk = NativeMethods.VirtualKeys.SHIFT
  610.                .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyDown
  611.            End With : Inputs.Add(CurrentInput)
  612.  
  613.            ' Hold the character key.
  614.            With CurrentInput
  615.                .type = NativeMethods.InputType.Keyboard
  616.                .ki.wVk = Convert.ToInt16(CChar(key))
  617.                .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyDown
  618.            End With : Inputs.Add(CurrentInput)
  619.  
  620.            ' Release the character key.
  621.            With CurrentInput
  622.                .type = NativeMethods.InputType.Keyboard
  623.                .ki.wVk = Convert.ToInt16(CChar(key))
  624.                .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyUp
  625.            End With : Inputs.Add(CurrentInput)
  626.  
  627.            ' Release the Shift key.
  628.            With CurrentInput
  629.                .type = NativeMethods.InputType.Keyboard
  630.                .ki.wVk = NativeMethods.VirtualKeys.SHIFT
  631.                .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyUp
  632.            End With : Inputs.Add(CurrentInput)
  633.  
  634.        End If ' UpperCase And My.Computer.Keyboard.CapsLock is...
  635.  
  636.        ' Send the input key.
  637.        Return NativeMethods.SendInput(Inputs.Count, Inputs.ToArray,
  638.                                       Marshal.SizeOf(GetType(NativeMethods.Input)))
  639.  
  640.        ' Unblock Keyboard and mouse.
  641.        If BlockInput Then NativeMethods.BlockInput(False)
  642.  
  643.    End Function
  644.  
  645.    ''' <summary>
  646.    ''' Sends a keystroke.
  647.    ''' </summary>
  648.    ''' <param name="key">
  649.    ''' Indicates the keystroke to simulate.
  650.    ''' </param>
  651.    ''' <param name="BlockInput">
  652.    ''' If set to <c>true</c>, the keyboard and mouse are blocked until the keystroke is sent.
  653.    ''' </param>
  654.    ''' <returns>
  655.    ''' The function returns the number of events that it successfully inserted into the keyboard input stream.
  656.    ''' If the function returns zero, the input was already blocked by another thread.
  657.    ''' </returns>
  658.    Public Shared Function SendKey(ByVal key As Keys,
  659.                                   Optional BlockInput As Boolean = False) As Integer
  660.  
  661.        Return SendKey(Convert.ToChar(key), BlockInput)
  662.  
  663.    End Function
  664.  
  665.    ''' <summary>
  666.    ''' Sends a string.
  667.    ''' </summary>
  668.    ''' <param name="String">
  669.    ''' Indicates the string to send.
  670.    ''' </param>
  671.    ''' <param name="BlockInput">
  672.    ''' If set to <c>true</c>, the keyboard and mouse are blocked until the keystroke is sent.
  673.    ''' </param>
  674.    ''' <returns>
  675.    ''' The function returns the number of events that it successfully inserted into the keyboard input stream.
  676.    ''' If the function returns zero, the input was already blocked by another thread.
  677.    ''' </returns>
  678.    Public Shared Function SendKeys(ByVal [String] As String,
  679.                                    Optional BlockInput As Boolean = False) As Integer
  680.  
  681.        Dim SuccessCount As Integer = 0
  682.  
  683.        ' Block Keyboard and mouse.
  684.        If BlockInput Then NativeMethods.BlockInput(True)
  685.  
  686.        For Each c As Char In [String]
  687.            SuccessCount += SendKey(c, BlockInput:=False)
  688.        Next c
  689.  
  690.        ' Unblock Keyboard and mouse.
  691.        If BlockInput Then NativeMethods.BlockInput(False)
  692.  
  693.        Return SuccessCount
  694.  
  695.    End Function
  696.  
  697.    ''' <summary>
  698.    ''' Slices the mouse position.
  699.    ''' </summary>
  700.    ''' <param name="Offset">
  701.    ''' Indicates the offset, in coordinates.
  702.    ''' </param>
  703.    ''' <param name="BlockInput">
  704.    ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
  705.    ''' </param>
  706.    ''' <returns>
  707.    ''' The function returns the number of events that it successfully inserted into the mouse input stream.
  708.    ''' If the function returns zero, the input was already blocked by another thread.
  709.    ''' </returns>
  710.    Public Shared Function MouseMove(ByVal Offset As Point,
  711.                                     Optional BlockInput As Boolean = False) As Integer
  712.  
  713.        ' Block Keyboard and mouse.
  714.        If BlockInput Then NativeMethods.BlockInput(True)
  715.  
  716.        ' The inputs structures to send.
  717.        Dim Inputs As New List(Of NativeMethods.Input)
  718.  
  719.        ' The current input to add into the Inputs list.
  720.        Dim CurrentInput As New NativeMethods.Input
  721.  
  722.        ' Add a mouse movement.
  723.        With CurrentInput
  724.            .type = NativeMethods.InputType.Mouse
  725.            .mi.dx = Offset.X
  726.            .mi.dy = Offset.Y
  727.            .mi.dwFlags = NativeMethods.MouseInput_Flags.Move
  728.        End With : Inputs.Add(CurrentInput)
  729.  
  730.        ' Send the mouse movement.
  731.        Return NativeMethods.SendInput(Inputs.Count, Inputs.ToArray,
  732.                                       Marshal.SizeOf(GetType(NativeMethods.Input)))
  733.  
  734.        ' Unblock Keyboard and mouse.
  735.        If BlockInput Then NativeMethods.BlockInput(False)
  736.  
  737.    End Function
  738.  
  739.    ''' <summary>
  740.    ''' Slices the mouse position.
  741.    ''' </summary>
  742.    ''' <param name="X">
  743.    ''' Indicates the 'X' offset.
  744.    ''' </param>
  745.    ''' <param name="Y">
  746.    ''' Indicates the 'Y' offset.
  747.    ''' </param>
  748.    ''' <param name="BlockInput">
  749.    ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
  750.    ''' </param>
  751.    ''' <returns>
  752.    ''' The function returns the number of events that it successfully inserted into the mouse input stream.
  753.    ''' If the function returns zero, the input was already blocked by another thread.
  754.    ''' </returns>
  755.    Public Shared Function MouseMove(ByVal X As Integer, ByVal Y As Integer,
  756.                                     Optional BlockInput As Boolean = False) As Integer
  757.  
  758.        Return MouseMove(New Point(X, Y), BlockInput)
  759.  
  760.    End Function
  761.  
  762.    ''' <summary>
  763.    ''' Moves the mouse hotspot to an absolute position, in coordinates.
  764.    ''' </summary>
  765.    ''' <param name="Position">
  766.    ''' Indicates the absolute position.
  767.    ''' </param>
  768.    ''' <param name="BlockInput">
  769.    ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
  770.    ''' </param>
  771.    ''' <returns>
  772.    ''' The function returns the number of events that it successfully inserted into the mouse input stream.
  773.    ''' If the function returns zero, the input was already blocked by another thread.
  774.    ''' </returns>
  775.    Public Shared Function MousePosition(ByVal Position As Point,
  776.                                         Optional BlockInput As Boolean = False) As Integer
  777.  
  778.        ' Block Keyboard and mouse.
  779.        If BlockInput Then NativeMethods.BlockInput(True)
  780.  
  781.        ' The inputs structures to send.
  782.        Dim Inputs As New List(Of NativeMethods.Input)
  783.  
  784.        ' The current input to add into the Inputs list.
  785.        Dim CurrentInput As New NativeMethods.Input
  786.  
  787.        ' Transform the coordinates.
  788.        Position.X = CInt(Position.X * 65535 / (Screen.PrimaryScreen.Bounds.Width - 1))
  789.        Position.Y = CInt(Position.Y * 65535 / (Screen.PrimaryScreen.Bounds.Height - 1))
  790.  
  791.        ' Add an absolute mouse movement.
  792.        With CurrentInput
  793.            .type = NativeMethods.InputType.Mouse
  794.            .mi.dx = Position.X
  795.            .mi.dy = Position.Y
  796.            .mi.dwFlags = NativeMethods.MouseInput_Flags.Absolute Or NativeMethods.MouseInput_Flags.Move
  797.            .mi.time = 0
  798.        End With : Inputs.Add(CurrentInput)
  799.  
  800.        ' Send the absolute mouse movement.
  801.        Return NativeMethods.SendInput(Inputs.Count, Inputs.ToArray,
  802.                                       Marshal.SizeOf(GetType(NativeMethods.Input)))
  803.  
  804.        ' Unblock Keyboard and mouse.
  805.        If BlockInput Then NativeMethods.BlockInput(False)
  806.  
  807.    End Function
  808.  
  809.    ''' <summary>
  810.    ''' Moves the mouse hotspot to an absolute position, in coordinates.
  811.    ''' </summary>
  812.    ''' <param name="X">
  813.    ''' Indicates the absolute 'X' coordinate.
  814.    ''' </param>
  815.    ''' <param name="Y">
  816.    ''' Indicates the absolute 'Y' coordinate.
  817.    ''' </param>
  818.    ''' <param name="BlockInput">
  819.    ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
  820.    ''' </param>
  821.    ''' <returns>
  822.    ''' The function returns the number of events that it successfully inserted into the mouse input stream.
  823.    ''' If the function returns zero, the input was already blocked by another thread.
  824.    ''' </returns>
  825.    Public Shared Function MousePosition(ByVal X As Integer, ByVal Y As Integer,
  826.                                         Optional BlockInput As Boolean = False) As Integer
  827.  
  828.        Return MousePosition(New Point(X, Y), BlockInput)
  829.  
  830.    End Function
  831.  
  832.    ''' <summary>
  833.    ''' Simulates a mouse click.
  834.    ''' </summary>
  835.    ''' <param name="MouseAction">
  836.    ''' Indicates the mouse action to perform.
  837.    ''' </param>
  838.    ''' <param name="BlockInput">
  839.    ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
  840.    ''' </param>
  841.    ''' <returns>
  842.    ''' The function returns the number of events that it successfully inserted into the mouse input stream.
  843.    ''' If the function returns zero, the input was already blocked by another thread.
  844.    ''' </returns>
  845.    Public Shared Function MouseClick(ByVal MouseAction As MouseButton,
  846.                                      Optional BlockInput As Boolean = False) As Integer
  847.  
  848.        ' Block Keyboard and mouse.
  849.        If BlockInput Then NativeMethods.BlockInput(True)
  850.  
  851.        ' The inputs structures to send.
  852.        Dim Inputs As New List(Of NativeMethods.Input)
  853.  
  854.        ' The current input to add into the Inputs list.
  855.        Dim CurrentInput As New NativeMethods.Input
  856.  
  857.        ' The mouse actions to perform.
  858.        Dim MouseActions As New List(Of MouseButton)
  859.  
  860.        Select Case MouseAction
  861.  
  862.            Case MouseButton.LeftPress ' Left button, hold and release.
  863.                MouseActions.Add(MouseButton.LeftDown)
  864.                MouseActions.Add(MouseButton.LeftUp)
  865.  
  866.            Case MouseButton.RightPress ' Right button, hold and release.
  867.                MouseActions.Add(MouseButton.RightDown)
  868.                MouseActions.Add(MouseButton.RightUp)
  869.  
  870.            Case MouseButton.MiddlePress ' Middle button, hold and release.
  871.                MouseActions.Add(MouseButton.MiddleDown)
  872.                MouseActions.Add(MouseButton.MiddleUp)
  873.  
  874.            Case Else ' Other
  875.                MouseActions.Add(MouseAction)
  876.  
  877.        End Select ' MouseAction
  878.  
  879.        For Each Action As MouseButton In MouseActions
  880.  
  881.            ' Add the mouse click.
  882.            With CurrentInput
  883.                .type = NativeMethods.InputType.Mouse
  884.                '.mi.dx = Offset.X
  885.                '.mi.dy = Offset.Y
  886.                .mi.dwFlags = Action
  887.            End With : Inputs.Add(CurrentInput)
  888.  
  889.        Next Action
  890.  
  891.        ' Send the mouse click.
  892.        Return NativeMethods.SendInput(Inputs.Count, Inputs.ToArray,
  893.                                       Marshal.SizeOf(GetType(NativeMethods.Input)))
  894.  
  895.        ' Unblock Keyboard and mouse.
  896.        If BlockInput Then NativeMethods.BlockInput(False)
  897.  
  898.    End Function
  899.  
  900. #End Region
  901.  
  902. End Class
7395  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 21 Febrero 2014, 03:59 am
Ejemplo de como encontrar e invocar un método usando Reflection, si solo tenemos un String que contiene el nombre del método, y como pasarle un parámetro nulo al invocar.

Código
  1. Imports System.Reflection
  2. Imports System.Globalization
  3.  
  4. Public Class Form1
  5.  
  6.    Private Shadows Sub Load() Handles MyBase.Load
  7.  
  8.        Dim MethodName As String = "Test"
  9.  
  10.        Dim Method As MethodInfo =
  11.            Me.GetType().GetMethod(MethodName, BindingFlags.IgnoreCase Or BindingFlags.Instance Or
  12.                                               BindingFlags.Public Or BindingFlags.NonPublic)
  13.  
  14.        If Method IsNot Nothing Then
  15.            Method.Invoke(Me, BindingFlags.IgnoreCase Or BindingFlags.Instance Or
  16.                              BindingFlags.Public Or BindingFlags.NonPublic,
  17.                          Nothing,
  18.                          New Object() {"Hello World!", Type.Missing}, CultureInfo.InvariantCulture)
  19.  
  20.        Else
  21.            MsgBox("Method not found.")
  22.  
  23.        End If
  24.  
  25.    End Sub
  26.  
  27.    Private Sub Test(ByVal StringValue As String, Optional ByVal IntValue As Integer = 1)
  28.        MessageBox.Show(StringValue & IntValue)
  29.    End Sub
  30.  
  31. End Class



Un DateDifference personalizado:

Código
  1.    ' Date Difference
  2.    ' ( By Elektro )
  3.    '
  4.    ' Usage Examples :
  5.    '
  6.    ' MsgBox(DateDifference(DateTime.Parse("01/03/2013 00:00:00"),
  7.    '                       DateTime.Parse("09/04/2014 01:01:01"),
  8.    '                       "{0} Year(s), {1} Month(s), {2} Week(s), {3} Day(s), {4} Hour(s), {5} Minute(s) and {6} Second(s)"))
  9.  
  10.    ''' <summary>
  11.    ''' Shows the difference between two dates with custom string format.
  12.    ''' </summary>
  13.    ''' <param name="Date1">Indicates the first date to compare.</param>
  14.    ''' <param name="Date2">Indicates the second date to compare.</param>
  15.    ''' <param name="StringFormat">
  16.    ''' Indicates the string format to display the difference, where:
  17.    ''' {0} = Years, {1} = Months, {2} = Weeks, {3} = Days, {4} = Hours, {5} = Minutes and {6} = Seconds</param>
  18.    ''' <returns>System.String.</returns>
  19.    Private Function DateDifference(ByVal Date1 As DateTime,
  20.                                    ByVal Date2 As DateTime,
  21.                                    ByVal StringFormat As String) As String
  22.  
  23.        Dim Time As TimeSpan
  24.        Dim YearDiff As Integer, MonthDiff As Integer, WeekDiff As Integer
  25.  
  26.        Do Until Date1 > Date2
  27.  
  28.            Date1 = Date1.AddMonths(1)
  29.            MonthDiff += 1
  30.  
  31.            If MonthDiff = 12 Then
  32.                YearDiff += 1
  33.                MonthDiff = 0
  34.            End If
  35.  
  36.        Loop
  37.  
  38.        MonthDiff -= 1
  39.        Date1 = Date1.AddMonths(-1)
  40.        Time = (Date2 - Date1)
  41.        WeekDiff = (Time.Days \ 7)
  42.        Time = (Time - TimeSpan.FromDays(WeekDiff * 7))
  43.  
  44.        Return String.Format(StringFormat, YearDiff, MonthDiff, WeekDiff, Time.Days, Time.Hours, Time.Minutes, Time.Seconds)
  45.  
  46.    End Function
7396  Seguridad Informática / Hacking / Re: Importante (Packet Editor, Proxy) en C# en: 20 Febrero 2014, 23:49 pm
A ver si dejas de duplicar posts, y empiezas por leer las normas del foro.

Saludos
7397  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 20 Febrero 2014, 06:06 am
Una helper class para las librerías 'SautinSoft.HtmlToRtf' y 'SautinSoft.RtfToHtml', como sus nombres indican, para convertir distintos documentos entre HTML, RTF, DOC y TXT.

La verdad es que se consiguen muy buenos resultados y tiene muchas opciones de customización, esta librería es mucho mejor que la que posteé hace unas semanas del cual también hice un ayudante.

Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 02-20-2014
  4. ' ***********************************************************************
  5. ' <copyright file="DocumentConverter.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Example Usages "
  11.  
  12. ' ' HTML 2 RTF
  13. ' RichTextBox1.Rtf = HTMLConverter.Html2Rtf(IO.File.ReadAllText("C:\File.htm", System.Text.Encoding.Default),
  14. '                                           SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
  15. '                                           DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
  16. '                                           "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
  17. '                                           DocumentConverter.PageOrientation.Auto, "Header", "Footer",
  18. '                                           SautinSoft.HtmlToRtf.eImageCompatible.WordPad)
  19.  
  20.  
  21. ' ' HTML 2 TXT
  22. ' RichTextBox1.Text = HTMLConverter.Html2Txt(IO.File.ReadAllText("C:\File.htm", System.Text.Encoding.Default),
  23. '                                            SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
  24. '                                            DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
  25. '                                            "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
  26. '                                            DocumentConverter.PageOrientation.Auto, "Header", "Footer",
  27. '                                            SautinSoft.HtmlToRtf.eImageCompatible.WordPad)
  28.  
  29.  
  30. ' ' HTML 2 DOC
  31. ' Dim MSDocText As String = HTMLConverter.Html2Doc(IO.File.ReadAllText("C:\File.htm", System.Text.Encoding.Default),
  32. '                                                  SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
  33. '                                                  DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
  34. '                                                  "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
  35. '                                                  DocumentConverter.PageOrientation.Auto, "Header", "Footer",
  36. '                                                  SautinSoft.HtmlToRtf.eImageCompatible.MSWord)
  37. ' IO.File.WriteAllText("C:\DocFile.doc", MSDocText, System.Text.Encoding.Default)
  38.  
  39.  
  40. ' ' TXT 2 RTF
  41. ' RichTextBox1.Rtf = DocumentConverter.Txt2Rtf("Hello World!",
  42. '                                              SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
  43. '                                              DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
  44. '                                              "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
  45. '                                              DocumentConverter.PageOrientation.Auto, "Header", "Footer",
  46. '                                              SautinSoft.HtmlToRtf.eImageCompatible.WordPad)
  47.  
  48.  
  49. ' ' TXT 2 DOC
  50. ' Dim MSDocText As String = DocumentConverter.Txt2Doc("Hello World!",
  51. '                                                     SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
  52. '                                                     DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
  53. '                                                     "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
  54. '                                                     DocumentConverter.PageOrientation.Auto, "Header", "Footer",
  55. '                                                     SautinSoft.HtmlToRtf.eImageCompatible.WordPad)
  56. ' IO.File.WriteAllText("C:\DocFile.doc", MSDocText, System.Text.Encoding.Default)
  57.  
  58.  
  59. ' ' RTF 2 HTML
  60. ' Dim HTMLString As String =
  61. '     DocumentConverter.Rtf2Html(IO.File.ReadAllText("C:\File.rtf"),
  62. '                                SautinSoft.RtfToHtml.eOutputFormat.XHTML_10,
  63. '                                SautinSoft.RtfToHtml.eEncoding.UTF_8,
  64. '                                True, "C:\")
  65. '
  66. ' IO.File.WriteAllText("C:\File.html", HTMLString)
  67. ' Process.Start("C:\File.html")
  68.  
  69. #End Region
  70.  
  71. #Region " Imports "
  72.  
  73. Imports SautinSoft
  74. Imports System.Reflection
  75.  
  76. #End Region
  77.  
  78. ''' <summary>
  79. ''' Performs HTML document convertions to other document formats.
  80. ''' </summary>
  81. Public Class DocumentConverter
  82.  
  83. #Region " Enumerations "
  84.  
  85.    ''' <summary>
  86.    ''' Indicates the resulting PageSize.
  87.    ''' </summary>
  88.    Public Enum PageSize
  89.        Auto
  90.        A3
  91.        A4
  92.        A5
  93.        A6
  94.        B5Iso
  95.        B5Jis
  96.        B6
  97.        Executive
  98.        Folio
  99.        Legal
  100.        Letter
  101.        Oficio2
  102.        Statement
  103.    End Enum
  104.  
  105.    ''' <summary>
  106.    ''' Indicates the resulting PageOrientation.
  107.    ''' </summary>
  108.    Public Enum PageOrientation
  109.        Auto
  110.        Landscape
  111.        Portrait
  112.    End Enum
  113.  
  114. #End Region
  115.  
  116. #Region " Private Methods "
  117.  
  118.    ''' <summary>
  119.    ''' Converts a document using 'SautinSoft.HtmlToRtf' library.
  120.    ''' </summary>
  121.    ''' <param name="Text">
  122.    ''' Indicates the text to convert.
  123.    ''' </param>
  124.    ''' <param name="OutputFormat">
  125.    ''' Indicates the output document format.
  126.    ''' </param>
  127.    ''' <param name="TextEncoding">
  128.    ''' Indicates the text encoding.
  129.    ''' </param>
  130.    ''' <param name="PreservePageBreaks">
  131.    ''' If set to <c>true</c> page breaks are preserved on the conversion.
  132.    ''' </param>
  133.    ''' <param name="PageSize">
  134.    ''' Indicates the page size.
  135.    ''' </param>
  136.    ''' <param name="Pagenumbers">
  137.    ''' Indicates the page numbers.
  138.    ''' </param>
  139.    ''' <param name="PagenumbersFormat">
  140.    ''' Indicates the page numbers format.
  141.    ''' </param>
  142.    ''' <param name="PageAlignment">
  143.    ''' Indicates the page alignment.
  144.    ''' </param>
  145.    ''' <param name="PageOrientation">
  146.    ''' Indicates the page orientation.
  147.    ''' </param>
  148.    ''' <param name="PageHeader">
  149.    ''' Indicates the page header text.
  150.    ''' </param>
  151.    ''' <param name="PageFooter">
  152.    ''' Indicates the page footer text.
  153.    ''' </param>
  154.    ''' <param name="ImageCompatibility">
  155.    ''' Indicates the image compatibility if the document contains images.
  156.    ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
  157.    ''' Microsoft Word can show images in jpeg, png, etc.
  158.    ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
  159.    ''' </param>
  160.    ''' <returns>System.String.</returns>
  161.    Private Shared Function HtmlToRtfConvert(ByVal [Text] As String,
  162.                                             ByVal InputFormat As HtmlToRtf.eInputFormat,
  163.                                             ByVal OutputFormat As HtmlToRtf.eOutputFormat,
  164.                                             Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
  165.                                             Optional ByVal PreservePageBreaks As Boolean = False,
  166.                                             Optional ByVal PageSize As PageSize = PageSize.Auto,
  167.                                             Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
  168.                                             Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
  169.                                             Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
  170.                                             Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
  171.                                             Optional ByVal PageHeader As String = Nothing,
  172.                                             Optional ByVal PageFooter As String = Nothing,
  173.                                             Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad) As String
  174.  
  175.        ' Set the PageSize.
  176.        Dim PerformPageSize As New HtmlToRtf.CPageStyle.CPageSize()
  177.        Dim PageSizeMethod As MethodInfo = PerformPageSize.GetType().GetMethod(PageSize.ToString())
  178.  
  179.        ' Set the PageOrientation.
  180.        Dim PerformPageOrientation As New HtmlToRtf.CPageStyle.CPageOrientation
  181.        Dim PageOrientationMethod As MethodInfo = PerformPageOrientation.GetType().GetMethod(PageOrientation.ToString())
  182.  
  183.        ' Call the PageSize method.
  184.        If Not PageSizeMethod Is Nothing Then
  185.            PageSizeMethod.Invoke(PerformPageSize, Nothing)
  186.        Else
  187.            Throw New Exception(String.Format("PageSize method {0} not found.", PageSize.ToString))
  188.        End If
  189.  
  190.        ' Call the PageOrientation method.
  191.        If Not PageOrientationMethod Is Nothing Then
  192.            PageOrientationMethod.Invoke(PerformPageOrientation, Nothing)
  193.        Else
  194.            Throw New Exception(String.Format("PageOrientation method {0} not found.", PageOrientation.ToString))
  195.        End If
  196.  
  197.        ' Instance a new document converter.
  198.        Dim Converter As New HtmlToRtf
  199.  
  200.        ' Customize the conversion options.
  201.        With Converter
  202.  
  203.            .Serial = "123456789012"
  204.  
  205.            .InputFormat = InputFormat
  206.            .OutputFormat = OutputFormat
  207.            .Encoding = TextEncoding
  208.            .PreservePageBreaks = PreservePageBreaks
  209.            .ImageCompatible = ImageCompatibility
  210.            .PageAlignment = PageAlignment
  211.            .PageNumbers = Pagenumbers
  212.            .PageNumbersFormat = PagenumbersFormat
  213.            .PageStyle.PageSize = PerformPageSize
  214.            .PageStyle.PageOrientation = PerformPageOrientation
  215.            If Not String.IsNullOrEmpty(PageHeader) Then .PageStyle.PageHeader.Text(PageHeader)
  216.            If Not String.IsNullOrEmpty(PageFooter) Then .PageStyle.PageFooter.Text(PageFooter)
  217.  
  218.        End With
  219.  
  220.        ' Convert it.
  221.        Return Converter.ConvertString([Text])
  222.  
  223.    End Function
  224.  
  225.    ''' <summary>
  226.    ''' Converts a document using 'SautinSoft.RtfToHtml' library.
  227.    ''' </summary>
  228.    ''' <param name="Text">
  229.    ''' Indicates the text to convert.
  230.    ''' </param>
  231.    ''' <param name="OutputFormat">
  232.    ''' Indicates the output HTML format.
  233.    ''' </param>
  234.    ''' <param name="TextEncoding">
  235.    ''' Indicates the text encoding.
  236.    ''' </param>
  237.    ''' <param name="SaveImagesToDisk">
  238.    ''' If set to <c>true</c>, converted images are saved to a directory on hard drive.
  239.    ''' </param>
  240.    ''' <param name="ImageFolder">
  241.    ''' If 'SaveImagesToDisk' parameter is set to 'True', indicates the image directory to save the images.
  242.    ''' The directory must exist.
  243.    ''' </param>
  244.    ''' <returns>System.String.</returns>
  245.    Private Shared Function RtfToHtmlConvert(ByVal [Text] As String,
  246.                                             Optional ByVal OutputFormat As RtfToHtml.eOutputFormat = RtfToHtml.eOutputFormat.XHTML_10,
  247.                                             Optional ByVal TextEncoding As RtfToHtml.eEncoding = RtfToHtml.eEncoding.UTF_8,
  248.                                             Optional ByVal SaveImagesToDisk As Boolean = False,
  249.                                             Optional ByVal ImageFolder As String = "C:\") As String
  250.  
  251.  
  252.        ' Instance a new document converter.
  253.        Dim Converter As New RtfToHtml
  254.  
  255.        ' Customize the conversion options.
  256.        With Converter
  257.  
  258.            .Serial = "123456789012"
  259.  
  260.            .OutputFormat = OutputFormat
  261.            .Encoding = TextEncoding
  262.            .ImageStyle.IncludeImageInHtml = Not SaveImagesToDisk
  263.            .ImageStyle.ImageFolder = ImageFolder ' This folder must exist to save the converted images.
  264.            .ImageStyle.ImageSubFolder = "Pictures" ' This subfolder will be created by the component to save the images.
  265.            .ImageStyle.ImageFileName = "picture" ' Pattern name for converted images. (Ex: 'Picture1.png')
  266.  
  267.        End With
  268.  
  269.        ' Convert it.
  270.        Return Converter.ConvertString([Text])
  271.  
  272.    End Function
  273.  
  274. #End Region
  275.  
  276. #Region " Public Methods "
  277.  
  278.    ''' <summary>
  279.    ''' Converts HTML text to DOC (Microsoft Word).
  280.    ''' </summary>
  281.    ''' <param name="HtmlText">
  282.    ''' Indicates the HTML text to convert.
  283.    ''' </param>
  284.    ''' <param name="TextEncoding">
  285.    ''' Indicates the text encoding.
  286.    ''' </param>
  287.    ''' <param name="PreservePageBreaks">
  288.    ''' If set to <c>true</c> page breaks are preserved on the conversion.
  289.    ''' </param>
  290.    ''' <param name="PageSize">
  291.    ''' Indicates the page size.
  292.    ''' </param>
  293.    ''' <param name="Pagenumbers">
  294.    ''' Indicates the page numbers.
  295.    ''' </param>
  296.    ''' <param name="PagenumbersFormat">
  297.    ''' Indicates the page numbers format.
  298.    ''' </param>
  299.    ''' <param name="PageAlignment">
  300.    ''' Indicates the page alignment.
  301.    ''' </param>
  302.    ''' <param name="PageOrientation">
  303.    ''' Indicates the page orientation.
  304.    ''' </param>
  305.    ''' <param name="PageHeader">
  306.    ''' Indicates the page header text.
  307.    ''' </param>
  308.    ''' <param name="PageFooter">
  309.    ''' Indicates the page footer text.
  310.    ''' </param>
  311.    ''' <param name="ImageCompatibility">
  312.    ''' Indicates the image compatibility if the document contains images.
  313.    ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
  314.    ''' Microsoft Word can show images in jpeg, png, etc.
  315.    ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
  316.    ''' </param>
  317.    ''' <returns>System.String.</returns>
  318.    Public Shared Function Html2Doc(ByVal HtmlText As String,
  319.                                    Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
  320.                                    Optional ByVal PreservePageBreaks As Boolean = False,
  321.                                    Optional ByVal PageSize As PageSize = PageSize.Auto,
  322.                                    Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
  323.                                    Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
  324.                                    Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
  325.                                    Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
  326.                                    Optional ByVal PageHeader As String = Nothing,
  327.                                    Optional ByVal PageFooter As String = Nothing,
  328.                                    Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
  329.                                    ) As String
  330.  
  331.        Return HtmlToRtfConvert(HtmlText, HtmlToRtf.eInputFormat.Html, HtmlToRtf.eOutputFormat.Doc, TextEncoding,
  332.                       PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
  333.                       PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)
  334.  
  335.    End Function
  336.  
  337.    ''' <summary>
  338.    ''' Converts HTML text to RTF (Rich Text).
  339.    ''' </summary>
  340.    ''' <param name="HtmlText">
  341.    ''' Indicates the HTML text to convert.
  342.    ''' </param>
  343.    ''' <param name="TextEncoding">
  344.    ''' Indicates the text encoding.
  345.    ''' </param>
  346.    ''' <param name="PreservePageBreaks">
  347.    ''' If set to <c>true</c> page breaks are preserved on the conversion.
  348.    ''' </param>
  349.    ''' <param name="PageSize">
  350.    ''' Indicates the page size.
  351.    ''' </param>
  352.    ''' <param name="Pagenumbers">
  353.    ''' Indicates the page numbers.
  354.    ''' </param>
  355.    ''' <param name="PagenumbersFormat">
  356.    ''' Indicates the page numbers format.
  357.    ''' </param>
  358.    ''' <param name="PageAlignment">
  359.    ''' Indicates the page alignment.
  360.    ''' </param>
  361.    ''' <param name="PageOrientation">
  362.    ''' Indicates the page orientation.
  363.    ''' </param>
  364.    ''' <param name="PageHeader">
  365.    ''' Indicates the page header text.
  366.    ''' </param>
  367.    ''' <param name="PageFooter">
  368.    ''' Indicates the page footer text.
  369.    ''' </param>
  370.    ''' <param name="ImageCompatibility">
  371.    ''' Indicates the image compatibility if the document contains images.
  372.    ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
  373.    ''' Microsoft Word can show images in jpeg, png, etc.
  374.    ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
  375.    ''' </param>
  376.    ''' <returns>System.String.</returns>
  377.    Public Shared Function Html2Rtf(ByVal HtmlText As String,
  378.                                    Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
  379.                                    Optional ByVal PreservePageBreaks As Boolean = False,
  380.                                    Optional ByVal PageSize As PageSize = PageSize.Auto,
  381.                                    Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
  382.                                    Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
  383.                                    Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
  384.                                    Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
  385.                                    Optional ByVal PageHeader As String = Nothing,
  386.                                    Optional ByVal PageFooter As String = Nothing,
  387.                                    Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
  388.                                    ) As String
  389.  
  390.        Return HtmlToRtfConvert(HtmlText, HtmlToRtf.eInputFormat.Html, HtmlToRtf.eOutputFormat.Rtf, TextEncoding,
  391.                       PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
  392.                       PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)
  393.  
  394.    End Function
  395.  
  396.    ''' <summary>
  397.    ''' Converts HTML text to TXT (Plain Text).
  398.    ''' </summary>
  399.    ''' <param name="HtmlText">
  400.    ''' Indicates the HTML text to convert.
  401.    ''' </param>
  402.    ''' <param name="TextEncoding">
  403.    ''' Indicates the text encoding.
  404.    ''' </param>
  405.    ''' <param name="PreservePageBreaks">
  406.    ''' If set to <c>true</c> page breaks are preserved on the conversion.
  407.    ''' </param>
  408.    ''' <param name="PageSize">
  409.    ''' Indicates the page size.
  410.    ''' </param>
  411.    ''' <param name="Pagenumbers">
  412.    ''' Indicates the page numbers.
  413.    ''' </param>
  414.    ''' <param name="PagenumbersFormat">
  415.    ''' Indicates the page numbers format.
  416.    ''' </param>
  417.    ''' <param name="PageAlignment">
  418.    ''' Indicates the page alignment.
  419.    ''' </param>
  420.    ''' <param name="PageOrientation">
  421.    ''' Indicates the page orientation.
  422.    ''' </param>
  423.    ''' <param name="PageHeader">
  424.    ''' Indicates the page header text.
  425.    ''' </param>
  426.    ''' <param name="PageFooter">
  427.    ''' Indicates the page footer text.
  428.    ''' </param>
  429.    ''' <param name="ImageCompatibility">
  430.    ''' Indicates the image compatibility if the document contains images.
  431.    ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
  432.    ''' Microsoft Word can show images in jpeg, png, etc.
  433.    ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
  434.    ''' </param>
  435.    ''' <returns>System.String.</returns>
  436.    Public Shared Function Html2Txt(ByVal HtmlText As String,
  437.                                    Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
  438.                                    Optional ByVal PreservePageBreaks As Boolean = False,
  439.                                    Optional ByVal PageSize As PageSize = PageSize.Auto,
  440.                                    Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
  441.                                    Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
  442.                                    Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
  443.                                    Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
  444.                                    Optional ByVal PageHeader As String = Nothing,
  445.                                    Optional ByVal PageFooter As String = Nothing,
  446.                                    Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
  447.                                    ) As String
  448.  
  449.        Return HtmlToRtfConvert(HtmlText, HtmlToRtf.eInputFormat.Html, HtmlToRtf.eOutputFormat.TextAnsi, TextEncoding,
  450.                       PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
  451.                       PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)
  452.  
  453.    End Function
  454.  
  455.    ''' <summary>
  456.    ''' Converts TXT to DOC (Microsoft Word).
  457.    ''' </summary>
  458.    ''' <param name="Text">
  459.    ''' Indicates the plain text to convert.
  460.    ''' </param>
  461.    ''' <param name="TextEncoding">
  462.    ''' Indicates the text encoding.
  463.    ''' </param>
  464.    ''' <param name="PreservePageBreaks">
  465.    ''' If set to <c>true</c> page breaks are preserved on the conversion.
  466.    ''' </param>
  467.    ''' <param name="PageSize">
  468.    ''' Indicates the page size.
  469.    ''' </param>
  470.    ''' <param name="Pagenumbers">
  471.    ''' Indicates the page numbers.
  472.    ''' </param>
  473.    ''' <param name="PagenumbersFormat">
  474.    ''' Indicates the page numbers format.
  475.    ''' </param>
  476.    ''' <param name="PageAlignment">
  477.    ''' Indicates the page alignment.
  478.    ''' </param>
  479.    ''' <param name="PageOrientation">
  480.    ''' Indicates the page orientation.
  481.    ''' </param>
  482.    ''' <param name="PageHeader">
  483.    ''' Indicates the page header text.
  484.    ''' </param>
  485.    ''' <param name="PageFooter">
  486.    ''' Indicates the page footer text.
  487.    ''' </param>
  488.    ''' <param name="ImageCompatibility">
  489.    ''' Indicates the image compatibility if the document contains images.
  490.    ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
  491.    ''' Microsoft Word can show images in jpeg, png, etc.
  492.    ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
  493.    ''' </param>
  494.    ''' <returns>System.String.</returns>
  495.    Public Shared Function Txt2Doc(ByVal [Text] As String,
  496.                                   Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
  497.                                   Optional ByVal PreservePageBreaks As Boolean = False,
  498.                                   Optional ByVal PageSize As PageSize = PageSize.Auto,
  499.                                   Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
  500.                                   Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
  501.                                   Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
  502.                                   Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
  503.                                   Optional ByVal PageHeader As String = Nothing,
  504.                                   Optional ByVal PageFooter As String = Nothing,
  505.                                   Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
  506.                                   ) As String
  507.  
  508.        Return HtmlToRtfConvert([Text], HtmlToRtf.eInputFormat.Text, HtmlToRtf.eOutputFormat.Doc, TextEncoding,
  509.                       PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
  510.                       PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)
  511.  
  512.    End Function
  513.  
  514.    ''' <summary>
  515.    ''' Converts TXT to RTF (Rich Text).
  516.    ''' </summary>
  517.    ''' <param name="Text">
  518.    ''' Indicates the plain text to convert.
  519.    ''' </param>
  520.    ''' <param name="TextEncoding">
  521.    ''' Indicates the text encoding.
  522.    ''' </param>
  523.    ''' <param name="PreservePageBreaks">
  524.    ''' If set to <c>true</c> page breaks are preserved on the conversion.
  525.    ''' </param>
  526.    ''' <param name="PageSize">
  527.    ''' Indicates the page size.
  528.    ''' </param>
  529.    ''' <param name="Pagenumbers">
  530.    ''' Indicates the page numbers.
  531.    ''' </param>
  532.    ''' <param name="PagenumbersFormat">
  533.    ''' Indicates the page numbers format.
  534.    ''' </param>
  535.    ''' <param name="PageAlignment">
  536.    ''' Indicates the page alignment.
  537.    ''' </param>
  538.    ''' <param name="PageOrientation">
  539.    ''' Indicates the page orientation.
  540.    ''' </param>
  541.    ''' <param name="PageHeader">
  542.    ''' Indicates the page header text.
  543.    ''' </param>
  544.    ''' <param name="PageFooter">
  545.    ''' Indicates the page footer text.
  546.    ''' </param>
  547.    ''' <param name="ImageCompatibility">
  548.    ''' Indicates the image compatibility if the document contains images.
  549.    ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
  550.    ''' Microsoft Word can show images in jpeg, png, etc.
  551.    ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
  552.    ''' </param>
  553.    ''' <returns>System.String.</returns>
  554.    Public Shared Function Txt2Rtf(ByVal [Text] As String,
  555.                                   Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
  556.                                   Optional ByVal PreservePageBreaks As Boolean = False,
  557.                                   Optional ByVal PageSize As PageSize = PageSize.Auto,
  558.                                   Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
  559.                                   Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
  560.                                   Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
  561.                                   Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
  562.                                   Optional ByVal PageHeader As String = Nothing,
  563.                                   Optional ByVal PageFooter As String = Nothing,
  564.                                   Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
  565.                                   ) As String
  566.  
  567.        Return HtmlToRtfConvert([Text], HtmlToRtf.eInputFormat.Text, HtmlToRtf.eOutputFormat.Rtf, TextEncoding,
  568.                       PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
  569.                       PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)
  570.  
  571.    End Function
  572.  
  573.    ''' <summary>
  574.    ''' Converts RtF to HtML.
  575.    ''' </summary>
  576.    ''' <param name="RtfText">
  577.    ''' Indicates the rich text to convert.
  578.    ''' </param>
  579.    ''' <param name="OutputFormat">
  580.    ''' Indicates the output HTML format.
  581.    ''' </param>
  582.    ''' <param name="TextEncoding">
  583.    ''' Indicates the text encoding.
  584.    ''' </param>
  585.    ''' <param name="SaveImagesToDisk">
  586.    ''' If set to <c>true</c>, converted images are saved to a directory on hard drive.
  587.    ''' </param>
  588.    ''' <param name="ImageFolder">
  589.    ''' If 'SaveImagesToDisk' parameter is set to 'True', indicates the image directory to save the images.
  590.    ''' The directory must exist.
  591.    ''' </param>
  592.    ''' <returns>System.String.</returns>
  593.    Public Shared Function Rtf2Html(ByVal RtfText As String,
  594.                                    Optional ByVal OutputFormat As RtfToHtml.eOutputFormat = RtfToHtml.eOutputFormat.XHTML_10,
  595.                                    Optional ByVal TextEncoding As RtfToHtml.eEncoding = RtfToHtml.eEncoding.UTF_8,
  596.                                    Optional ByVal SaveImagesToDisk As Boolean = False,
  597.                                    Optional ByVal ImageFolder As String = "C:\") As String
  598.  
  599.        Return RtfToHtmlConvert(RtFText, OutputFormat, TextEncoding, SaveImagesToDisk, ImageFolder)
  600.  
  601.    End Function
  602.  
  603. #End Region
  604.  
  605. End Class
7398  Informática / Software / Re: Duda sobre la existencia de un programa en: 19 Febrero 2014, 22:34 pm
No creo que exista un software dedicado a una tarea tan "singular", pero de todas formas no es dificil conseguirlo escribiendo un Script/Programa, partiendo cada linea de texto usando como delimitador el caracter de 'espacio'.

Slaudos!
7399  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 19 Febrero 2014, 21:54 pm
         [RichTextBox] Colorize Words

         Busca coincidencias de texto y las colorea.


Código
  1.    ' Colorize Words
  2.    ' ( By Elektro )
  3.    '
  4.    ' Usage Examples:
  5.    '
  6.    ' ColorizeWord(RichTextBox1, "Hello", True,
  7.    '              Color.Red, Color.Black,
  8.    '              New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Italic))
  9.    '
  10.    ' ColorizeWords(RichTextBox1, {"Hello", "[0-9]"}, IgnoreCase:=False,
  11.    '               ForeColor:=Color.Red, BackColor:=Nothing, Font:=Nothing)
  12.  
  13.    ''' <summary>
  14.    ''' Find a word on a RichTextBox and colorizes each match.
  15.    ''' </summary>
  16.    ''' <param name="RichTextBox">Indicates the RichTextBox.</param>
  17.    ''' <param name="Word">Indicates the word to colorize.</param>
  18.    ''' <param name="IgnoreCase">Indicates the ignore case.</param>
  19.    ''' <param name="ForeColor">Indicates the text color.</param>
  20.    ''' <param name="BackColor">Indicates the background color.</param>
  21.    ''' <param name="Font">Indicates the text font.</param>
  22.    ''' <returns><c>true</c> if matched at least one word, <c>false</c> otherwise.</returns>
  23.    Private Function ColorizeWord(ByVal [RichTextBox] As RichTextBox,
  24.                                  ByVal Word As String,
  25.                                  Optional ByVal IgnoreCase As Boolean = False,
  26.                                  Optional ByVal ForeColor As Color = Nothing,
  27.                                  Optional ByVal BackColor As Color = Nothing,
  28.                                  Optional ByVal [Font] As Font = Nothing) As Boolean
  29.  
  30.        ' Find all the word matches.
  31.        Dim Matches As System.Text.RegularExpressions.MatchCollection =
  32.            System.Text.RegularExpressions.Regex.Matches([RichTextBox].Text, Word,
  33.                                                         If(IgnoreCase,
  34.                                                            System.Text.RegularExpressions.RegexOptions.IgnoreCase,
  35.                                                            System.Text.RegularExpressions.RegexOptions.None))
  36.  
  37.        ' If no matches then return.
  38.        If Not Matches.Count <> 0 Then
  39.            Return False
  40.        End If
  41.  
  42.        ' Set the passed Parameter values.
  43.        If ForeColor.Equals(Nothing) Then ForeColor = [RichTextBox].ForeColor
  44.        If BackColor.Equals(Nothing) Then BackColor = [RichTextBox].BackColor
  45.        If [Font] Is Nothing Then [Font] = [RichTextBox].Font
  46.  
  47.        ' Store the current caret position to restore it at the end.
  48.        Dim CaretPosition As Integer = [RichTextBox].SelectionStart
  49.  
  50.        ' Suspend the control layout to work quicklly.
  51.        [RichTextBox].SuspendLayout()
  52.  
  53.        ' Colorize each match.
  54.        For Each Match As System.Text.RegularExpressions.Match In Matches
  55.  
  56.            [RichTextBox].Select(Match.Index, Match.Length)
  57.            [RichTextBox].SelectionColor = ForeColor
  58.            [RichTextBox].SelectionBackColor = BackColor
  59.            [RichTextBox].SelectionFont = [Font]
  60.  
  61.        Next Match
  62.  
  63.        ' Restore the caret position.
  64.        [RichTextBox].Select(CaretPosition, 0)
  65.  
  66.        ' Restore the control layout.
  67.        [RichTextBox].ResumeLayout()
  68.  
  69.        ' Return successfully
  70.        Return True
  71.  
  72.    End Function
  73.  
  74.    ''' <summary>
  75.    ''' Find multiple words on a RichTextBox and colorizes each match.
  76.    ''' </summary>
  77.    ''' <param name="RichTextBox">Indicates the RichTextBox.</param>
  78.    ''' <param name="Words">Indicates the words to colorize.</param>
  79.    ''' <param name="IgnoreCase">Indicates the ignore case.</param>
  80.    ''' <param name="ForeColor">Indicates the text color.</param>
  81.    ''' <param name="BackColor">Indicates the background color.</param>
  82.    ''' <param name="Font">Indicates the text font.</param>
  83.    ''' <returns><c>true</c> if matched at least one word, <c>false</c> otherwise.</returns>
  84.    Private Function ColorizeWords(ByVal [RichTextBox] As RichTextBox,
  85.                                   ByVal Words As String(),
  86.                                   Optional ByVal IgnoreCase As Boolean = False,
  87.                                   Optional ByVal ForeColor As Color = Nothing,
  88.                                   Optional ByVal BackColor As Color = Nothing,
  89.                                   Optional ByVal [Font] As Font = Nothing) As Boolean
  90.  
  91.        Dim Success As Boolean = False
  92.  
  93.        For Each Word As String In Words
  94.            Success += ColorizeWord([RichTextBox], Word, IgnoreCase, ForeColor, BackColor, [Font])
  95.        Next Word
  96.  
  97.        Return Success
  98.  
  99.    End Function



[ListView] Remove Duplicates

Elimina Items duplicados de un Listview, comparando un índice de subitem específico.

Código
  1.    ' Remove ListView Duplicates
  2.    ' ( By Elektro )
  3.    '
  4.    ' Usage Examples:
  5.    ' Dim Items As ListView.ListViewItemCollection = New ListView.ListViewItemCollection(ListView1)
  6.    ' RemoveListViewDuplicates(Items, 0)    
  7.    '
  8.    ''' <summary>
  9.    ''' Removes duplicated items from a Listview.
  10.    ''' </summary>
  11.    ''' <param name="Items">
  12.    ''' Indicates the items collection.
  13.    ''' </param>
  14.    ''' <param name="SubitemCompare">
  15.    ''' Indicates the subitem column to compare duplicates.
  16.    ''' </param>
  17.    Private Sub RemoveListViewDuplicates(ByVal Items As ListView.ListViewItemCollection,
  18.                                         ByVal SubitemCompare As Integer)
  19.  
  20.        ' Suspend the layout on the Control that owns the Items collection.
  21.        Items.Item(0).ListView.SuspendLayout()
  22.  
  23.        ' Get the duplicated Items.
  24.        Dim Duplicates As ListViewItem() =
  25.            Items.Cast(Of ListViewItem)().
  26.            GroupBy(Function(Item As ListViewItem) Item.SubItems(SubitemCompare).Text).
  27.            Where(Function(g As IGrouping(Of String, ListViewItem)) g.Count <> 1).
  28.            SelectMany(Function(g As IGrouping(Of String, ListViewItem)) g).
  29.            Skip(1).
  30.            ToArray()
  31.  
  32.        ' Delete the duplicated Items.
  33.        For Each Item As ListViewItem In Duplicates
  34.            Items.Remove(Item)
  35.        Next Item
  36.  
  37.        ' Resume the layout on the Control that owns the Items collection.
  38.        Items.Item(0).ListView.ResumeLayout()
  39.  
  40.        Duplicates = Nothing
  41.  
  42.    End Sub
  43.  



Formatea un dispositivo

Código
  1.    ' Format Drive
  2.    ' ( By Elektro )
  3.    '
  4.    ' Usage Examples:
  5.    ' FormatDrive("Z")
  6.    ' MsgBox(FormatDrive("Z", DriveFileSystem.NTFS, True, 4096, "Formatted", False))
  7.  
  8.    ''' <summary>
  9.    ''' Indicates the possible HardDisk filesystem's for Windows OS.
  10.    ''' </summary>
  11.    Public Enum DriveFileSystem As Integer
  12.  
  13.        ' NOTE:
  14.        ' *****
  15.        ' The numeric values just indicates the max harddisk volume-label character-length for each filesystem.
  16.  
  17.        ''' <summary>
  18.        ''' NTFS FileSystem.
  19.        ''' </summary>
  20.        NTFS = 32
  21.  
  22.        ''' <summary>
  23.        ''' FAT16 FileSystem.
  24.        ''' </summary>
  25.        FAT16 = 11
  26.  
  27.        ''' <summary>
  28.        ''' FAT32 FileSystem.
  29.        ''' </summary>
  30.        FAT32 = FAT16
  31.  
  32.    End Enum
  33.  
  34.    ''' <summary>
  35.    ''' Formats a drive.
  36.    ''' For more info see here:
  37.    ''' http://msdn.microsoft.com/en-us/library/aa390432%28v=vs.85%29.aspx
  38.    ''' </summary>
  39.    ''' <param name="DriveLetter">
  40.    ''' Indicates the drive letter to format.
  41.    ''' </param>
  42.    ''' <param name="FileSystem">
  43.    ''' Indicates the filesystem format to use for this volume.
  44.    ''' The default is "NTFS".
  45.    ''' </param>
  46.    ''' <param name="QuickFormat">
  47.    ''' If set to <c>true</c>, formats the volume with a quick format by removing files from the disk
  48.    ''' without scanning the disk for bad sectors.
  49.    ''' Use this option only if the disk has been previously formatted,
  50.    ''' and you know that the disk is not damaged.
  51.    ''' The default is <c>true</c>.
  52.    ''' </param>
  53.    ''' <param name="ClusterSize">
  54.    ''' Disk allocation unit size—cluster size.
  55.    ''' All of the filesystems organizes the hard disk based on cluster size,
  56.    ''' which represents the smallest amount of disk space that can be allocated to hold a file.
  57.    ''' The smaller the cluster size you use, the more efficiently your disk stores information.
  58.    ''' If no cluster size is specified during format, Windows picks defaults based on the size of the volume.
  59.    ''' These defaults have been selected to reduce the amount of space lost and to reduce fragmentation.
  60.    ''' For general use, the default settings are strongly recommended.
  61.    ''' </param>
  62.    ''' <param name="VolumeLabel">
  63.    ''' Indicates the Label to use for the new volume.
  64.    ''' The volume label can contain up to 11 characters for FAT16 and FAT32 volumes,
  65.    ''' and up to 32 characters for NTFS filesystem volumes.
  66.    ''' </param>
  67.    ''' <param name="EnableCompression">Not implemented.</param>
  68.    ''' <returns>
  69.    ''' 0  = Success.
  70.    ''' 1  = Unsupported file system.
  71.    ''' 2  = Incompatible media in drive.
  72.    ''' 3  = Access denied.
  73.    ''' 4  = Call canceled.
  74.    ''' 5  = Call cancellation request too late.
  75.    ''' 6  = Volume write protected.
  76.    ''' 7  = Volume lock failed.
  77.    ''' 8  = Unable to quick format.
  78.    ''' 9  = Input/Output (I/O) error.
  79.    ''' 10 = Invalid volume label.
  80.    ''' 11 = No media in drive.
  81.    ''' 12 = Volume is too small.
  82.    ''' 13 = Volume is too large.
  83.    ''' 14 = Volume is not mounted.
  84.    ''' 15 = Cluster size is too small.
  85.    ''' 16 = Cluster size is too large.
  86.    ''' 17 = Cluster size is beyond 32 bits.
  87.    ''' 18 = Unknown error.
  88.    ''' </returns>
  89.    Public Function FormatDrive(ByVal DriveLetter As Char,
  90.                                Optional ByVal FileSystem As DriveFileSystem = DriveFileSystem.NTFS,
  91.                                Optional ByVal QuickFormat As Boolean = True,
  92.                                Optional ByVal ClusterSize As Integer = Nothing,
  93.                                Optional ByVal VolumeLabel As String = Nothing,
  94.                                Optional ByVal EnableCompression As Boolean = False) As Integer
  95.  
  96.        ' Volume-label error check.
  97.        If Not String.IsNullOrEmpty(VolumeLabel) Then
  98.  
  99.            If VolumeLabel.Length > FileSystem Then
  100.                Throw New Exception(String.Format("Volume label for '{0}' filesystem can't be larger than '{1}' characters.",
  101.                                                  FileSystem.ToString, CStr(FileSystem)))
  102.            End If
  103.  
  104.        End If
  105.  
  106.        Dim Query As String = String.Format("select * from Win32_Volume WHERE DriveLetter = '{0}:'",
  107.                                            Convert.ToString(DriveLetter))
  108.  
  109.        Using WMI As New ManagementObjectSearcher(Query)
  110.  
  111.            Return CInt(WMI.[Get].Cast(Of ManagementObject).First.
  112.                        InvokeMethod("Format",
  113.                                     New Object() {FileSystem, QuickFormat, ClusterSize, VolumeLabel, EnableCompression}))
  114.  
  115.        End Using
  116.  
  117.        Return 18 ' Unknown error.
  118.  
  119.    End Function
7400  Programación / Java / Re: hacer compareTo con vector de char (para ordenar nombres) en: 19 Febrero 2014, 05:37 am
Porfavor, usa las etiquetas de código... respeta las normas del foro.

PD: Sobre el código, no se Java.

Saludos!
Páginas: 1 ... 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 [740] 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 ... 1236
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines