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

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


  Mostrar Mensajes
Páginas: 1 ... 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 [759] 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 ... 1236
7581  Programación / .NET (C#, VB.NET, ASP) / Re: Condicionar arrays en: 14 Enero 2014, 13:07 pm
me da el tipico error de que ya esta declarada el array " Results7s "

Hombre, error típico no es, lo que pasa es que tienes la mala costumbre de declarar variables innecesarias por todas partes del código, y al final tienes un lio.

En lugar de declarar varios arrays:

Código
  1. Dim result1 as Integer()  = {1, 2, 3}
  2. Dim result2 as Integer()  = {4, 5, 6}
  3. Dim result2 as Integer() = {7, 8, 9}

Intenta declarar sólamente 1 array, y reemplazarlo/actualízarlo cuando sea necesario:

Código
  1. Public Result as Integer() = {1, 2, 3}

...En otra parte del código:
Código
  1. Me.Result = Me.Result.Concat({4, 5, 6}).Concat({7, 8, 9}).ToArray ' Por ejemplo.

De todas formas si prefieres seguir como hasta ahora, pues declara una nueva variable con otro nombre distinto y así no tendrás ese "típico error", de verdad no te lo tomes a mal pero no le veo ningún sentido a la duda que has posteado.

Saludos!
7582  Programación / .NET (C#, VB.NET, ASP) / Re: [SOURCE] Color.NET v2.0 en: 14 Enero 2014, 12:51 pm
Versión 2.1 ~> http://www.mediafire.com/download/7qu4rpnhrruby6g/Color.NET.rar
( Solo código fuente )

Código:
[+] Version 2.1 - Changes:
    
    [+] Fixed:
        · Hexadecimal string conversion sometimes are not shown correctly.
        · The 'Recent Colors' menu item sometimes throws an exception.

    [+] Changed:
        · Replaced a lot of code and added and internal Class 'ColorTools.vb' to get the pixel color and also manage the color-string conversions.

    [+] Deleted:
        · The 'ToolTipForm.vb' Form, now is managed by the 'ShowtoolTip' method.
        · Deleted unnecessary code (NativeMethods.vb)
7583  Programación / .NET (C#, VB.NET, ASP) / Re: Condicionar arrays en: 13 Enero 2014, 22:03 pm
Se puede condicionar que los resultados de este array pasen de x numeros ?

¿Te refieres a descartar números que séan mayores de 99?

@Luis456, te sugiero que aprendas a usar LINQ ...será tu mejor aliado :) (por su sencillez, no por rendimiento) :

Código
  1. Dim Max As Integer = 99
  2.  
  3. Dim arr1 As Integer() = {100, 2, 3}
  4. Dim arr2 As Integer() = {4, 500, 6}
  5. Dim arr3 As Integer() = {7, 8, 999}
  6.  
  7. Dim Result As Integer() =
  8. (
  9.  From Value As Integer In (arr1.Concat(arr2).Concat(arr3))
  10.  Where Value <= Max
  11. ).ToArray
  12.  
  13. MsgBox(String.Join(", ", Result)) ' Result = {2, 3, 4, 6, 7, 8}
  14.  

PD: En otro post te dije una url donde descargar 101 ejemplos de LINQ, si te lo estudiases un poco tendrías ejemplos como los que yo te pongo para un buen rato xD.

Saludos
7584  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 13 Enero 2014, 18:35 pm
A mi no me deja descargar, ¿me podrias facilitar un enlace por MP?

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

Saludos!
7585  Programación / .NET (C#, VB.NET, ASP) / Re: Unir dos arrays en un tercero en: 13 Enero 2014, 18:27 pm
la idea es que los resulatdos de result1 y result2 unirlos para eliminar repetidos

( Siguiendo el código de arriba ) ~> Enumerable.Distinct (Método)

Código
  1. Dim Result As Integer() = arr1.Concat(arr2).Concat(arr3).Distinct.ToArray

Saludos
7586  Programación / .NET (C#, VB.NET, ASP) / Re: Unir dos arrays en un tercero en: 13 Enero 2014, 18:12 pm
Puedes usar LINQ:

Código
  1.        Dim arr1 As Integer() = {1, 2, 3}
  2.        Dim arr2 As Integer() = {4, 5, 6}
  3.        Dim arr3 As Integer() = {7, 8, 9}
  4.  
  5.        Dim Result As Integer() =
  6.            arr1.
  7.            Concat(arr2).
  8.            Concat(arr3).
  9.            ToArray
  10.  
  11.        MsgBox(String.Join(", ", Result)) ' Result = {1, 2, 3, 4, 5, 6, 7, 8, 9}

¿Cual es el problema que tienes al concatenarlos?

Si tienes un Array puedes convertirlo/castearlo a un Enumerable para manejar LINQ.

Código
  1.        Dim arr1 As Array = {1, 2, 3}
  2.        Dim arr2 As Array = {4, 5, 6}
  3.        Dim arr3 As Array = {7, 8, 9}
  4.  
  5.        Dim Result As Integer() =
  6.            arr1.Cast(Of Integer).
  7.            Concat(arr2.Cast(Of Integer)).
  8.            Concat(arr3.Cast(Of Integer)).
  9.            ToArray
  10.  
  11.        MsgBox(String.Join(", ", Result)) ' Result = {1, 2, 3, 4, 5, 6, 7, 8, 9}

Saludos!
7587  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 13 Enero 2014, 17:46 pm
Una Helper Class con utilidades variadas relacionadas con los colores:

Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Created  : 01-13-2014
  4. ' Modified : 01-13-2014
  5. ' ***********************************************************************
  6.  
  7. ' --------------
  8. ' Public Methods
  9. ' --------------
  10. '
  11. ' Screen.GetPixelColor
  12. ' Screen.GetPixelBrush
  13. ' Screen.GetPixelPen
  14. '
  15. ' ColorConvert.ColorToBrush
  16. ' ColorConvert.ColorToPen
  17. ' ColorConvert.BrushToColor
  18. ' ColorConvert.PentoColor
  19. '
  20. ' StringConvert.ColorToString
  21. ' StringConvert.BrushToString
  22. ' StringConvert.PenToString
  23. ' StringConvert.StringToColor
  24. ' StringConvert.StringToBrush
  25. ' StringConvert.StringToPen
  26. ' StringConvert.StringToString
  27. '
  28. ' RandomGenerators.ARGB
  29. ' RandomGenerators.RGB
  30. ' RandomGenerators.QB
  31. ' RandomGenerators.ConsoleColor
  32. ' RandomGenerators.Brush
  33. ' RandomGenerators.Pen

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

Ejemplos de uso:

Código
  1. ' Gets the color of the pixel at the 50,100 coordinates:
  2. Dim c As Color = ColorTools.Screen.GetPixelColor(50, 100)
  3.  
  4. ' Generates a random Brush
  5. Dim br As SolidBrush = ColorTools.RandomGenerators.Brush
  6.  
  7. ' Converts a SolidBrush to a Color:
  8. Dim c As Color = ColorTools.ColorConvert.BrushToColor(New SolidBrush(Color.Red))
  9.  
  10. ' Converts an HTML Color-String to a Color:
  11. PictureBox1.BackColor = ColorTools.StringConvert.StringToColor("#FF00FFFF",
  12.                                                                ColorTools.StringConvert.ValueFormat.HTML,
  13.                                                                ColorTools.StringConvert.StringSyntax.None)
  14.  
  15. ' Converts an Hex Color-String to a Color:
  16. MsgBox(ColorTools.StringConvert.StringToColor("0x003399",
  17.                                               ColorTools.StringConvert.ValueFormat.Hexadecimal,
  18.                                               ColorTools.StringConvert.StringSyntax.None))
  19.  
  20. ' Converts a Byte Color-String with VisyalStudio's property grid syntax to a Color:
  21. MsgBox(ColorTools.StringConvert.StringToColor("255; 255; 255; 255",
  22.                                               ColorTools.StringConvert.ValueFormat.Byte,
  23.                                               ColorTools.StringConvert.StringSyntax.VisualStudioPropertyGrid).
  24.                                               Name)
  25.  
  26. ' Converts a HEX Color-String with VB.NET syntax to a Color:
  27. MsgBox(ColorTools.StringConvert.StringToColor("Color.FromArgb(&HFF, &H5F, &HEC, &H12)",
  28.                                               ColorTools.StringConvert.ValueFormat.Hexadecimal,
  29.                                               ColorTools.StringConvert.StringSyntax.VBNET).
  30.                                               ToString)
  31.  
  32. ' Converts an HTML Color-String with C# Syntax to a Brush:
  33. Dim br As Brush = ColorTools.StringConvert.StringToBrush("ColorTranslator.FromHtml(""#F71608"");",
  34.                                                          ColorTools.StringConvert.ValueFormat.HTML,
  35.                                                          ColorTools.StringConvert.StringSyntax.VBNET)
  36.  
  37. ' Converts a Color-String to other Color-String:
  38. MsgBox(ColorTools.StringConvert.StringToString("ColorTranslator.FromHtml(""#AF0CCAFE"");",
  39.                                                ColorTools.StringConvert.ValueFormat.HTML,
  40.                                                ColorTools.StringConvert.StringSyntax.CSharp,
  41.                                                ColorTools.StringConvert.ValueFormat.Byte,
  42.                                                ColorTools.StringConvert.StringSyntax.None,
  43.                                                True))



7588  Programación / Scripting / Re: Proyecto Batch- Cleverbot en: 12 Enero 2014, 18:06 pm
Batch es (muy) limitado en comparación con el resto de lenguajes (lenguajes de verdad), sobretodo por las escasas (inexistentes) herramientas de trabajo del lenguaje y la pobre velocidad.
Si reálmente quieres llevar una idea de estas proporciones entonces lo primero que debes hacer es olvidarte del retrasado Batch y aprender un lenguaje.

Por otro lado entiendo que lo que pretendes hacer es una "IA" muy básica sin algoritmos complejos, pero de todas formas el hecho de intentar hacer esto en Batch es una completa pérdida de tiempo, no te va a servir para nada reálmente, ni para aprender.

Segúramente habrán "buenos" ejemplos por Google, pero cualquier cosa parecida hecha en Batch es una pérdida de tiempo.

PD: Empecé a escribir un código para mostrarte un ejemplo hecho en Batch, pero me ví tan limitado en cada acción sin nisiquiera un triste Array o expresiones regulares (actuales) para poder calcular la frase con más coincidencias, que al final no terminé el código ...es una completa pérdida de tiempo pudiendo disponer de la capacidad de cualquier otro lenguaje.

Como utilizo un "find" / "findstr" o "for" para conseguir buscar cierto segmento delimitado por un signo de puntuación,de la misma línea?

FINDSTR soporta Expresiones regulares limitadas, leete la ayuda del comando en la consola, es el único commando que te puede servir de alguna manera dentro de lo poco que te va a servir (junto a un FOR para hacerle un split a la cadena).

Ejemplo de uso:

Código
  1. @Echo OFF
  2.  
  3. Set "String=Probando 123"
  4.  
  5. Echo "%String%" | FINDSTR "Probando.[0-9][0-9][0-9]" 1>NUL && (
  6. Set "Match=True"
  7. ) || (
  8. Set "Match=False"
  9. )
  10.  
  11. Echo Coincide: %Match%
  12.  
  13. Pause&Exit

Saludos
7589  Programación / .NET (C#, VB.NET, ASP) / [SOURCE] Color.Net v2.2 en: 12 Enero 2014, 16:38 pm





¿Qué es Color.Net?



Color.Net es una sencilla herramienta para para obtener la información del color del pixel actual sobre en pantalla.

Color.Net está enfocado para programadores, pudiendo representar los valores ARGB en distintos lenguajes y formatos con un solo click !!.





Características



  • Representación del color en formatos ARGB, RGB, Hex, Web, Win32, HSL, Delphi, C# (Int), C# (Hex), C# (Web), Vb.Net (Int), Vb.Net (Hex), Vb.Net (Web), Visual Studio (Int), y Visual Studio (Hex).
  • Magnificador de imagen (o lupa)
  • Panel desplegable con selector de color.
  • Atajos del teclado para copiar el formato al portapapeles sin perder el tiempo, o detenerse en un pixel en concreto.
  • Vista previa de la aplicación de un color sobre distintos controles.





Imágenes











DESCARGA (v2.2)


Compilación e Instalador

Código fuente






SI TE HA GUSTADO MI APORTE, ¡COMENTA! :)




7590  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 12 Enero 2014, 09:30 am
Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Created  : 01-12-2014
  4. ' Modified : 01-12-2014
  5. ' ***********************************************************************
  6. ' <copyright file="FormBorderManager.vb" company="Elektro Studios">
  7. '     Copyright (c) Elektro Studios. All rights reserved.
  8. ' </copyright>
  9. ' ***********************************************************************
  10.  
  11. #Region " Usage Examples "
  12.  
  13. 'Public Class Form1
  14.  
  15. '    ' Disable resizing on all border edges.
  16. '    Private FormBorders As New FormBorderManager(Me) With
  17. '            {
  18. '                .Edges = New FormBorderManager.FormEdges With
  19. '                         {
  20. '                             .Top = FormBorderManager.WindowHitTestRegions.TitleBar,
  21. '                             .Left = FormBorderManager.WindowHitTestRegions.TitleBar,
  22. '                             .Right = FormBorderManager.WindowHitTestRegions.TitleBar,
  23. '                             .Bottom = FormBorderManager.WindowHitTestRegions.TitleBar,
  24. '                             .TopLeft = FormBorderManager.WindowHitTestRegions.TitleBar,
  25. '                             .TopRight = FormBorderManager.WindowHitTestRegions.TitleBar,
  26. '                             .BottomLeft = FormBorderManager.WindowHitTestRegions.TitleBar,
  27. '                             .BottomRight = FormBorderManager.WindowHitTestRegions.TitleBar
  28. '                         }
  29. '            }
  30.  
  31. '    Private Shadows Sub Load(sender As Object, e As EventArgs) Handles MyBase.Load
  32.  
  33. '        ' Disables the moving on all border edges.
  34. '        FormBorders.SetAllEdgesToNonMoveable()
  35.  
  36. '    End Sub
  37.  
  38. 'End Class
  39.  
  40. #End Region
  41.  
  42. #Region " Imports "
  43.  
  44. Imports System.ComponentModel
  45.  
  46. #End Region
  47.  
  48. #Region " FormBorderManager "
  49.  
  50. ''' <summary>
  51. ''' Class FormBorderManager.
  52. ''' Manages each Form border to indicate their Hit-Region.
  53. ''' </summary>
  54. <Description("Manages each Form border to indicate their Hit-Region")>
  55. Public Class FormBorderManager : Inherits NativeWindow : Implements IDisposable
  56.  
  57. #Region " Members "
  58.  
  59. #Region " Miscellaneous "
  60.  
  61.    ''' <summary>
  62.    ''' The form to manage their borders.
  63.    ''' </summary>
  64.    Private WithEvents form As Form = Nothing
  65.  
  66. #End Region
  67.  
  68. #Region " Properties "
  69.  
  70.    ''' <summary>
  71.    ''' Gets or sets the Hit-Region of the edges.
  72.    ''' </summary>
  73.    ''' <value>The Form edges.</value>
  74.    Public Property Edges As New FormEdges
  75.  
  76.    ''' <summary>
  77.    ''' The Edges of the Form.
  78.    ''' </summary>
  79.    Partial Public NotInheritable Class FormEdges
  80.  
  81.        ''' <summary>
  82.        ''' Gets or sets the Hit-Region of the Top form border.
  83.        ''' </summary>
  84.        Public Property Top As WindowHitTestRegions = WindowHitTestRegions.TopSizeableBorder
  85.  
  86.        ''' <summary>
  87.        ''' Gets or sets the Hit-Region of the Left form border.
  88.        ''' </summary>
  89.        Public Property Left As WindowHitTestRegions = WindowHitTestRegions.LeftSizeableBorder
  90.  
  91.        ''' <summary>
  92.        ''' Gets or sets the Hit-Region of the Right form border.
  93.        ''' </summary>
  94.        Public Property Right As WindowHitTestRegions = WindowHitTestRegions.RightSizeableBorder
  95.  
  96.        ''' <summary>
  97.        ''' Gets or sets the Hit-Region of the Bottom form border.
  98.        ''' </summary>
  99.        Public Property Bottom As WindowHitTestRegions = WindowHitTestRegions.BottomSizeableBorder
  100.  
  101.        ''' <summary>
  102.        ''' Gets or sets the Hit-Region of the Top-Left form border.
  103.        ''' </summary>
  104.        Public Property TopLeft As WindowHitTestRegions = WindowHitTestRegions.TopLeftSizeableCorner
  105.  
  106.        ''' <summary>
  107.        ''' Gets or sets the Hit-Region of the Top-Right form border.
  108.        ''' </summary>
  109.        Public Property TopRight As WindowHitTestRegions = WindowHitTestRegions.TopRightSizeableCorner
  110.  
  111.        ''' <summary>
  112.        ''' Gets or sets the Hit-Region of the Bottom-Left form border.
  113.        ''' </summary>
  114.        Public Property BottomLeft As WindowHitTestRegions = WindowHitTestRegions.BottomLeftSizeableCorner
  115.  
  116.        ''' <summary>
  117.        ''' Gets or sets the Hit-Region of the Bottom-Right form border.
  118.        ''' </summary>
  119.        Public Property BottomRight As WindowHitTestRegions = WindowHitTestRegions.BottomRightSizeableCorner
  120.  
  121.    End Class
  122.  
  123. #End Region
  124.  
  125. #Region " Enumerations "
  126.  
  127.    ''' <summary>
  128.    ''' Known Windows Message Identifiers.
  129.    ''' </summary>
  130.    <Description("Messages to process in WndProc")>
  131.    Private Enum KnownMessages As Integer
  132.  
  133.        ''' <summary>
  134.        ''' Sent to a window in order to determine what part of the window corresponds to a particular screen coordinate.
  135.        ''' This can happen, for example, when the cursor moves, when a mouse button is pressed or released,
  136.        ''' or in response to a call to a function such as WindowFromPoint.
  137.        ''' If the mouse is not captured, the message is sent to the window beneath the cursor.
  138.        ''' Otherwise, the message is sent to the window that has captured the mouse.
  139.        ''' <paramref name="WParam" />
  140.        ''' This parameter is not used.
  141.        ''' <paramref name="LParam" />
  142.        ''' The low-order word specifies the x-coordinate of the cursor.
  143.        ''' The coordinate is relative to the upper-left corner of the screen.
  144.        ''' The high-order word specifies the y-coordinate of the cursor.
  145.        ''' The coordinate is relative to the upper-left corner of the screen.
  146.        ''' </summary>
  147.        WM_NCHITTEST = &H84
  148.  
  149.    End Enum
  150.  
  151.    ''' <summary>
  152.    ''' Indicates the position of the cursor hot spot.
  153.    ''' Options available when a form is tested for mose positions with 'WM_NCHITTEST' message.
  154.    ''' </summary>
  155.    <Description("Return value of the 'WM_NCHITTEST' message")>
  156.    Public Enum WindowHitTestRegions
  157.  
  158.        ''' <summary>
  159.        ''' HTERROR: On the screen background or on a dividing line between windows.
  160.        ''' (same as HTNOWHERE, except that the DefWindowProc function produces a system beep to indicate an error).
  161.        ''' </summary>
  162.        [Error] = -2
  163.  
  164.        ''' <summary>
  165.        ''' HTTRANSPARENT: In a window currently covered by another window in the same thread.
  166.        ''' (the message will be sent to underlying windows in the same thread
  167.        ''' until one of them returns a code that is not HTTRANSPARENT).
  168.        ''' </summary>
  169.        TransparentOrCovered = -1
  170.  
  171.        ''' <summary>
  172.        ''' HTNOWHERE: On the screen background or on a dividing line between windows.
  173.        ''' </summary>
  174.        NoWhere = 0
  175.  
  176.        ''' <summary>
  177.        ''' HTCLIENT: In a client area.
  178.        ''' </summary>
  179.        ClientArea = 1
  180.  
  181.        ''' <summary>
  182.        ''' HTCAPTION: In a title bar.
  183.        ''' </summary>
  184.        TitleBar = 2
  185.  
  186.        ''' <summary>
  187.        ''' HTSYSMENU: In a window menu or in a Close button in a child window.
  188.        ''' </summary>
  189.        SystemMenu = 3
  190.  
  191.        ''' <summary>
  192.        ''' HTGROWBOX: In a size box (same as HTSIZE).
  193.        ''' </summary>
  194.        GrowBox = 4
  195.  
  196.        ''' <summary>
  197.        ''' HTMENU: In a menu.
  198.        ''' </summary>
  199.        Menu = 5
  200.  
  201.        ''' <summary>
  202.        ''' HTHSCROLL: In a horizontal scroll bar.
  203.        ''' </summary>
  204.        HorizontalScrollBar = 6
  205.  
  206.        ''' <summary>
  207.        ''' HTVSCROLL: In the vertical scroll bar.
  208.        ''' </summary>
  209.        VerticalScrollBar = 7
  210.  
  211.        ''' <summary>
  212.        ''' HTMINBUTTON: In a Minimize button.
  213.        ''' </summary>
  214.        MinimizeButton = 8
  215.  
  216.        ''' <summary>
  217.        ''' HTMAXBUTTON: In a Maximize button.
  218.        ''' </summary>
  219.        MaximizeButton = 9
  220.  
  221.        ''' <summary>
  222.        ''' HTLEFT: In the left border of a resizable window.
  223.        ''' (the user can click the mouse to resize the window horizontally).
  224.        ''' </summary>
  225.        LeftSizeableBorder = 10
  226.  
  227.        ''' <summary>
  228.        ''' HTRIGHT: In the right border of a resizable window.
  229.        ''' (the user can click the mouse to resize the window horizontally).
  230.        ''' </summary>
  231.        RightSizeableBorder = 11
  232.  
  233.        ''' <summary>
  234.        ''' HTTOP: In the upper-horizontal border of a window.
  235.        ''' </summary>
  236.        TopSizeableBorder = 12
  237.  
  238.        ''' <summary>
  239.        ''' HTTOPLEFT: In the upper-left corner of a window border.
  240.        ''' </summary>
  241.        TopLeftSizeableCorner = 13
  242.  
  243.        ''' <summary>
  244.        ''' HTTOPRIGHT: In the upper-right corner of a window border.
  245.        ''' </summary>
  246.        TopRightSizeableCorner = 14
  247.  
  248.        ''' <summary>
  249.        ''' HTBOTTOM: In the lower-horizontal border of a resizable window.
  250.        ''' (the user can click the mouse to resize the window vertically).
  251.        ''' </summary>
  252.        BottomSizeableBorder = 15
  253.  
  254.        ''' <summary>
  255.        ''' HTBOTTOMLEFT: In the lower-left corner of a border of a resizable window.
  256.        ''' (the user can click the mouse to resize the window diagonally).
  257.        ''' </summary>
  258.        BottomLeftSizeableCorner = 16
  259.  
  260.        ''' <summary>
  261.        ''' HTBOTTOMRIGHT: In the lower-right corner of a border of a resizable window.
  262.        ''' (the user can click the mouse to resize the window diagonally).
  263.        ''' </summary>
  264.        BottomRightSizeableCorner = 17
  265.  
  266.        ''' <summary>
  267.        ''' HTBORDER: In the border of a window that does not have a sizing border.
  268.        ''' </summary>
  269.        NonSizableBorder = 18
  270.  
  271.        ' ''' <summary>
  272.        ' ''' HTOBJECT: Not implemented.
  273.        ' ''' </summary>
  274.        ' [Object] = 19
  275.  
  276.        ''' <summary>
  277.        ''' HTCLOSE: In a Close button.
  278.        ''' </summary>
  279.        CloseButton = 20
  280.  
  281.        ''' <summary>
  282.        ''' HTHELP: In a Help button.
  283.        ''' </summary>
  284.        HelpButton = 21
  285.  
  286.        ''' <summary>
  287.        ''' HTSIZE: In a size box (same as HTGROWBOX).
  288.        ''' (Same as GrowBox).
  289.        ''' </summary>
  290.        SizeBox = GrowBox
  291.  
  292.        ''' <summary>
  293.        ''' HTREDUCE: In a Minimize button.
  294.        ''' (Same as MinimizeButton).
  295.        ''' </summary>
  296.        ReduceButton = MinimizeButton
  297.  
  298.        ''' <summary>
  299.        ''' HTZOOM: In a Maximize button.
  300.        ''' (Same as MaximizeButton).
  301.        ''' </summary>
  302.        ZoomButton = MaximizeButton
  303.  
  304.    End Enum
  305.  
  306. #End Region
  307.  
  308. #End Region
  309.  
  310. #Region " Constructor "
  311.  
  312.    ''' <summary>
  313.    ''' Initializes a new instance of the <see cref="FormBorderManager"/> class.
  314.    ''' </summary>
  315.    ''' <param name="form">The form to assign.</param>
  316.    Public Sub New(ByVal form As Form)
  317.  
  318.        ' Assign the Formulary.
  319.        Me.form = form
  320.  
  321.        ' Assign the form handle.
  322.        Me.SetFormHandle()
  323.  
  324.    End Sub
  325.  
  326. #End Region
  327.  
  328. #Region " Event Handlers "
  329.  
  330.    ''' <summary>
  331.    ''' Assign the handle of the target form to this NativeWindow,
  332.    ''' necessary to override WndProc.
  333.    ''' </summary>
  334.    Private Sub SetFormHandle() _
  335.    Handles Form.HandleCreated, Form.Load, Form.Shown
  336.  
  337.        Try
  338.            If Not MyBase.Handle.Equals(Me.form.Handle) Then
  339.                MyBase.AssignHandle(Me.form.Handle)
  340.            End If
  341.        Catch ' ex As InvalidOperationException
  342.        End Try
  343.  
  344.    End Sub
  345.  
  346.    ''' <summary>
  347.    ''' Releases the Handle.
  348.    ''' </summary>
  349.    Private Sub OnHandleDestroyed() _
  350.    Handles Form.HandleDestroyed
  351.  
  352.        MyBase.ReleaseHandle()
  353.  
  354.    End Sub
  355.  
  356. #End Region
  357.  
  358. #Region " WndProc "
  359.  
  360.    ''' <summary>
  361.    ''' Invokes the default window procedure associated with this window to process messages for this Window.
  362.    ''' </summary>
  363.    ''' <param name="m">
  364.    ''' A <see cref="T:System.Windows.Forms.Message" /> that is associated with the current Windows message.
  365.    ''' </param>
  366.    Protected Overrides Sub WndProc(ByRef m As Message)
  367.  
  368.        MyBase.WndProc(m)
  369.  
  370.        Select Case m.Msg
  371.  
  372.            Case KnownMessages.WM_NCHITTEST
  373.  
  374.                Select Case CType(m.Result, WindowHitTestRegions)
  375.  
  376.                    Case WindowHitTestRegions.TopSizeableBorder ' The mouse hotspot is pointing to Top border.
  377.                        m.Result = New IntPtr(Edges.Top)
  378.  
  379.                    Case WindowHitTestRegions.LeftSizeableBorder ' The mouse hotspot is pointing to Left border.
  380.                        m.Result = New IntPtr(Edges.Left)
  381.  
  382.                    Case WindowHitTestRegions.RightSizeableBorder ' The mouse hotspot is pointing to Right border.
  383.                        m.Result = New IntPtr(Edges.Right)
  384.  
  385.                    Case WindowHitTestRegions.BottomSizeableBorder ' The mouse hotspot is pointing to Bottom border.
  386.                        m.Result = New IntPtr(Edges.Bottom)
  387.  
  388.                    Case WindowHitTestRegions.TopLeftSizeableCorner ' The mouse hotspot is pointing to Top-Left border.
  389.                        m.Result = New IntPtr(Edges.TopLeft)
  390.  
  391.                    Case WindowHitTestRegions.TopRightSizeableCorner ' The mouse hotspot is pointing to Top-Right border.
  392.                        m.Result = New IntPtr(Edges.TopRight)
  393.  
  394.                    Case WindowHitTestRegions.BottomLeftSizeableCorner ' The mouse hotspot is pointing to Bottom-Left border.
  395.                        m.Result = New IntPtr(Edges.BottomLeft)
  396.  
  397.                    Case WindowHitTestRegions.BottomRightSizeableCorner ' The mouse hotspot is pointing to Bottom-Right border.
  398.                        m.Result = New IntPtr(Edges.BottomRight)
  399.  
  400.                End Select
  401.  
  402.        End Select
  403.  
  404.    End Sub
  405.  
  406. #End Region
  407.  
  408. #Region " Public Methods "
  409.  
  410.    ''' <summary>
  411.    ''' Disables the resizing on all border edges.
  412.    ''' </summary>
  413.    Public Sub SetAllEdgesToNonResizable()
  414.  
  415.        DisposedCheck()
  416.  
  417.        Me.Edges.Top = WindowHitTestRegions.TitleBar
  418.        Me.Edges.Left = WindowHitTestRegions.TitleBar
  419.        Me.Edges.Right = WindowHitTestRegions.TitleBar
  420.        Me.Edges.Bottom = WindowHitTestRegions.TitleBar
  421.        Me.Edges.TopLeft = WindowHitTestRegions.TitleBar
  422.        Me.Edges.TopRight = WindowHitTestRegions.TitleBar
  423.        Me.Edges.BottomLeft = WindowHitTestRegions.TitleBar
  424.        Me.Edges.BottomRight = WindowHitTestRegions.TitleBar
  425.  
  426.    End Sub
  427.  
  428.    ''' <summary>
  429.    ''' Enables the resizing on all border edges.
  430.    ''' </summary>
  431.    Public Sub SetAllEdgesToResizable()
  432.  
  433.        DisposedCheck()
  434.  
  435.        Me.Edges.Top = WindowHitTestRegions.TopSizeableBorder
  436.        Me.Edges.Left = WindowHitTestRegions.LeftSizeableBorder
  437.        Me.Edges.Right = WindowHitTestRegions.RightSizeableBorder
  438.        Me.Edges.Bottom = WindowHitTestRegions.BottomSizeableBorder
  439.        Me.Edges.TopLeft = WindowHitTestRegions.TopLeftSizeableCorner
  440.        Me.Edges.TopRight = WindowHitTestRegions.TopRightSizeableCorner
  441.        Me.Edges.BottomLeft = WindowHitTestRegions.BottomLeftSizeableCorner
  442.        Me.Edges.BottomRight = WindowHitTestRegions.BottomRightSizeableCorner
  443.  
  444.    End Sub
  445.  
  446.    ''' <summary>
  447.    ''' Enabled the moving on all border edges.
  448.    ''' </summary>
  449.    Public Sub SetAllEdgesToMoveable()
  450.  
  451.        DisposedCheck()
  452.  
  453.        Me.Edges.Top = WindowHitTestRegions.TopSizeableBorder
  454.        Me.Edges.Left = WindowHitTestRegions.LeftSizeableBorder
  455.        Me.Edges.Right = WindowHitTestRegions.RightSizeableBorder
  456.        Me.Edges.Bottom = WindowHitTestRegions.BottomSizeableBorder
  457.        Me.Edges.TopLeft = WindowHitTestRegions.TopLeftSizeableCorner
  458.        Me.Edges.TopRight = WindowHitTestRegions.TopRightSizeableCorner
  459.        Me.Edges.BottomLeft = WindowHitTestRegions.BottomLeftSizeableCorner
  460.        Me.Edges.BottomRight = WindowHitTestRegions.BottomRightSizeableCorner
  461.  
  462.    End Sub
  463.  
  464.    ''' <summary>
  465.    ''' Disables the moving on all border edges.
  466.    ''' </summary>
  467.    Public Sub SetAllEdgesToNonMoveable()
  468.  
  469.        DisposedCheck()
  470.  
  471.        Me.Edges.Top = WindowHitTestRegions.NoWhere
  472.        Me.Edges.Left = WindowHitTestRegions.NoWhere
  473.        Me.Edges.Right = WindowHitTestRegions.NoWhere
  474.        Me.Edges.Bottom = WindowHitTestRegions.NoWhere
  475.        Me.Edges.TopLeft = WindowHitTestRegions.NoWhere
  476.        Me.Edges.TopRight = WindowHitTestRegions.NoWhere
  477.        Me.Edges.BottomLeft = WindowHitTestRegions.NoWhere
  478.        Me.Edges.BottomRight = WindowHitTestRegions.NoWhere
  479.  
  480.    End Sub
  481.  
  482. #End Region
  483.  
  484. #Region " Hidden methods "
  485.  
  486.    ' These methods and properties are purposely hidden from Intellisense just to look better without unneeded methods.
  487.    ' NOTE: The methods can be re-enabled at any-time if needed.
  488.  
  489.    ''' <summary>
  490.    ''' Assigns the handle.
  491.    ''' </summary>
  492.    <EditorBrowsable(EditorBrowsableState.Never)>
  493.    Public Shadows Sub AssignHandle()
  494.    End Sub
  495.  
  496.    ''' <summary>
  497.    ''' Creates the handle.
  498.    ''' </summary>
  499.    <EditorBrowsable(EditorBrowsableState.Never)>
  500.    Public Shadows Sub CreateHandle()
  501.    End Sub
  502.  
  503.    ''' <summary>
  504.    ''' Creates the object reference.
  505.    ''' </summary>
  506.    <EditorBrowsable(EditorBrowsableState.Never)>
  507.    Public Shadows Sub CreateObjRef()
  508.    End Sub
  509.  
  510.    ''' <summary>
  511.    ''' Definitions the WND proc.
  512.    ''' </summary>
  513.    <EditorBrowsable(EditorBrowsableState.Never)>
  514.    Public Shadows Sub DefWndProc()
  515.    End Sub
  516.  
  517.    ''' <summary>
  518.    ''' Destroys the window and its handle.
  519.    ''' </summary>
  520.    <EditorBrowsable(EditorBrowsableState.Never)>
  521.    Public Shadows Sub DestroyHandle()
  522.    End Sub
  523.  
  524.    ''' <summary>
  525.    ''' Equalses this instance.
  526.    ''' </summary>
  527.    <EditorBrowsable(EditorBrowsableState.Never)>
  528.    Public Shadows Sub Equals()
  529.    End Sub
  530.  
  531.    ''' <summary>
  532.    ''' Gets the hash code.
  533.    ''' </summary>
  534.    <EditorBrowsable(EditorBrowsableState.Never)>
  535.    Public Shadows Sub GetHashCode()
  536.    End Sub
  537.  
  538.    ''' <summary>
  539.    ''' Gets the lifetime service.
  540.    ''' </summary>
  541.    <EditorBrowsable(EditorBrowsableState.Never)>
  542.    Public Shadows Sub GetLifetimeService()
  543.    End Sub
  544.  
  545.    ''' <summary>
  546.    ''' Initializes the lifetime service.
  547.    ''' </summary>
  548.    <EditorBrowsable(EditorBrowsableState.Never)>
  549.    Public Shadows Sub InitializeLifetimeService()
  550.    End Sub
  551.  
  552.    ''' <summary>
  553.    ''' Releases the handle associated with this window.
  554.    ''' </summary>
  555.    <EditorBrowsable(EditorBrowsableState.Never)>
  556.    Public Shadows Sub ReleaseHandle()
  557.    End Sub
  558.  
  559.    ''' <summary>
  560.    ''' Gets the handle for this window.
  561.    ''' </summary>
  562.    <EditorBrowsable(EditorBrowsableState.Never)>
  563.    Public Shadows Property Handle()
  564.  
  565. #End Region
  566.  
  567. #Region " IDisposable "
  568.  
  569.    ''' <summary>
  570.    ''' To detect redundant calls when disposing.
  571.    ''' </summary>
  572.    Private IsDisposed As Boolean = False
  573.  
  574.    ''' <summary>
  575.    ''' Prevent calls to methods after disposing.
  576.    ''' </summary>
  577.    ''' <exception cref="System.ObjectDisposedException"></exception>
  578.    Private Sub DisposedCheck()
  579.        If Me.IsDisposed Then
  580.            Throw New ObjectDisposedException(Me.GetType().FullName)
  581.        End If
  582.    End Sub
  583.  
  584.    ''' <summary>
  585.    ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  586.    ''' </summary>
  587.    Public Sub Dispose() Implements IDisposable.Dispose
  588.        Dispose(True)
  589.        GC.SuppressFinalize(Me)
  590.    End Sub
  591.  
  592.    ''' <summary>
  593.    ''' Releases unmanaged and - optionally - managed resources.
  594.    ''' </summary>
  595.    ''' <param name="IsDisposing">
  596.    ''' <c>true</c> to release both managed and unmanaged resources;
  597.    ''' <c>false</c> to release only unmanaged resources.
  598.    ''' </param>
  599.  
  600.    Protected Sub Dispose(IsDisposing As Boolean)
  601.  
  602.        If Not Me.IsDisposed Then
  603.  
  604.            If IsDisposing Then
  605.                Me.form = Nothing
  606.                MyBase.ReleaseHandle()
  607.                MyBase.DestroyHandle()
  608.            End If
  609.  
  610.        End If
  611.  
  612.        Me.IsDisposed = True
  613.  
  614.    End Sub
  615.  
  616. #End Region
  617.  
  618. End Class
  619.  
  620. #End Region
Páginas: 1 ... 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 [759] 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 ... 1236
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines