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

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


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

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #310 en: 13 Octubre 2013, 03:55 am »

Este código reemplaza una palabra en un string, por una secuencia numérica:

Código
  1. #Region " Replace Word (Increment method) "
  2.  
  3.    ' [ Replace Word (Increment method) ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Replace_Word_By_Increment("Hello World!, Hello World!", "Hello", , 3)) ' Result: 001 World!, 002 World!
  9.  
  10.    Private Function Replace_Word_By_Increment(ByVal str As String, _
  11.                                               ByVal replace As String, _
  12.                                               Optional ByVal IgnoreCase As System.StringComparison = StringComparison.CurrentCulture, _
  13.                                               Optional ByVal DigitLength As Long = 0) As String
  14.  
  15.        Dim str_split() As String = str.Split
  16.        Dim replacement As String = Nothing
  17.        Dim IndexCount As Long = 0
  18.  
  19.        DigitLength = If(DigitLength = 0, replace.Length, DigitLength)
  20.  
  21.        For Item As Long = 0 To str_split.LongCount - 1
  22.  
  23.            If str_split(Item).Equals(replace, IgnoreCase) Then
  24.  
  25.                replacement &= Threading.Interlocked.Increment(IndexCount).ToString
  26.  
  27.                While Not replacement.Length >= DigitLength
  28.                    replacement = replacement.Insert(0, "0")
  29.                End While
  30.  
  31.                str_split(Item) = replacement
  32.                replacement = Nothing
  33.  
  34.            End If
  35.  
  36.        Next Item
  37.  
  38.        Return String.Join(Convert.ToChar(Keys.Space), str_split)
  39.  
  40.    End Function
  41.  
  42. #End Region


Este código reemplaza un patrón de búsqueda en un string, por una secuencia numérica:

Código
  1. #Region " Replace String (Increment method) "
  2.  
  3.    ' [ Replace String (Increment method) ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Replace_String_By_Increment("Hello World!, Hello World!", New System.Text.RegularExpressions.Regex("Hello\sWorld", RegexOptions.IgnoreCase), 3)) ' Result: 001!, 002!
  9.  
  10.    Private Function Replace_String_By_Increment(ByVal str As String, _
  11.                                                 ByVal replace As System.Text.RegularExpressions.Regex, _
  12.                                                 Optional ByVal DigitLength As Long = 0) As String
  13.  
  14.        DigitLength = If(DigitLength = 0, replace.ToString.Length, DigitLength)
  15.  
  16.        Dim IndexCount As Integer = 0
  17.        Dim replacement As String = Nothing
  18.        Dim matches As System.Text.RegularExpressions.MatchCollection = replace.Matches(str)
  19.  
  20.        For Each match As System.Text.RegularExpressions.Match In matches
  21.  
  22.            replacement &= Threading.Interlocked.Increment(IndexCount).ToString
  23.  
  24.            While Not replacement.Length >= DigitLength
  25.                replacement = replacement.Insert(0, "0")
  26.            End While
  27.  
  28.            str = replace.Replace(str, replacement, 1, match.Index - (match.Length * (IndexCount - 1)))
  29.            replacement = Nothing
  30.  
  31.        Next
  32.  
  33.        matches = Nothing
  34.        replacement = Nothing
  35.        IndexCount = 0
  36.        Return str
  37.  
  38.    End Function
  39.  
  40. #End Region

EDITO:

Un sencillo proyecto para testear:

   

Descarga: http://www.mediafire.com/?6b6qdy9iyigm63v


« Última modificación: 14 Octubre 2013, 04:36 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



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

He descubierto este mensaje de Windows para mover el ScrollBar de un control pudiendo especificar la cantidad de lineas a mover, y la dirección.

Código
  1.    <System.Runtime.InteropServices.DllImport("user32.dll")> _
  2.    Private Shared Function SendMessage(hWnd As IntPtr, wMsg As UInteger, wParam As UIntPtr, lParam As IntPtr) As Integer
  3.    End Function
  4.  
  5.    ' Examples:
  6.    '
  7.    ' SendMessage(RichTextBox1.Handle, &HB6, 0, 1)  ' Move 1 line to down
  8.    ' SendMessage(RichTextBox1.Handle, &HB6, 0, 5)  ' Move 5 lines to down
  9.    ' SendMessage(RichTextBox1.Handle, &HB6, 0, -1) ' Move 1 line to up
  10.    ' SendMessage(RichTextBox1.Handle, &HB6, 0, -5) ' Move 5 lines to up


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #312 en: 13 Octubre 2013, 14:50 pm »

Con estas funciones podemos acceder a la información de la ScrollBar integrada de un control (la scrollbar vertical de un RichTextBox por ejemplo), para averiguar si la barra está scrolleada hacia abajo del todo, o hacia arriba del todo, o si ha sobrepasado el límite de abajo/arriba (aunque esto último creo que no pede suceder, pero bueno).

Esto es útil para prevenir el molesto efecto de "rebote" del método ScrollToCaret cuando intentamos scrollear la ScrollBar de un richtextbox cuando ha llegado al límite.

Ejemplo de uso:
Código
  1.        RichTextBox1.Select(RichTextBox1.TextLength - 1, 1)
  2.        If Not ScrollBarInfo.IsAtBottom(RichTextBox1) Then
  3.            RichTextBox1.ScrollToCaret()
  4.        End If


Código
  1. Public Class ScrollBarInfo
  2.  
  3.    <System.Runtime.InteropServices.DllImport("user32")> _
  4.    Private Shared Function GetScrollInfo(hwnd As IntPtr, nBar As Integer, ByRef scrollInfo As SCROLLINFO) As Integer
  5.    End Function
  6.  
  7.    Private Shared scrollInf As New SCROLLINFO()
  8.  
  9.    Private Structure SCROLLINFO
  10.        Public cbSize As Integer
  11.        Public fMask As Integer
  12.        Public min As Integer
  13.        Public max As Integer
  14.        Public nPage As Integer
  15.        Public nPos As Integer
  16.        Public nTrackPos As Integer
  17.    End Structure
  18.  
  19.    Private Shared Sub Get_ScrollInfo(control As Control)
  20.        scrollInf = New SCROLLINFO()
  21.        scrollInf.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(scrollInf)
  22.        scrollInf.fMask = &H10 Or &H1 Or &H2 'SIF_RANGE = &H1, SIF_PAGE= &H2, SIF_TRACKPOS = &H10
  23.        GetScrollInfo(control.Handle, 1, scrollInf)
  24.    End Sub
  25.  
  26.    Public Shared Function ReachedBottom(control As Control) As Boolean
  27.        Get_ScrollInfo(control)
  28.        Return scrollInf.max = scrollInf.nTrackPos + scrollInf.nPage
  29.    End Function
  30.  
  31.    Public Shared Function ReachedTop(control As Control) As Boolean
  32.        Get_ScrollInfo(control)
  33.        Return scrollInf.nTrackPos < 0
  34.    End Function
  35.  
  36.    Public Shared Function IsAtBottom(control As Control) As Boolean
  37.        Get_ScrollInfo(control)
  38.        Return scrollInf.max = (scrollInf.nTrackPos + scrollInf.nPage) - 1
  39.    End Function
  40.  
  41.    Public Shared Function IsAtTop(control As Control) As Boolean
  42.        Get_ScrollInfo(control)
  43.        Return scrollInf.nTrackPos = 0
  44.    End Function
  45.  
  46. End Class
« Última modificación: 14 Octubre 2013, 04:40 am por EleKtro H@cker » En línea

MauriH

Desconectado Desconectado

Mensajes: 12


Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #313 en: 13 Octubre 2013, 21:27 pm »

Este código reemplaza una palabra en un string, por una secuencia numérica:

Código
  1. #Region " Replace Word (Increment method) "
  2.  
  3.    ' [ Replace Word (Increment method) ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Replace_Word_By_Increment("Hello World!, Hello World!", "Hello", , 3)) ' Result: 001 World!, 002 World!
  9.  
  10.    Private Function Replace_Word_By_Increment(ByVal str As String, _
  11.                                               ByVal replace As String, _
  12.                                               Optional ByVal IgnoreCase As System.StringComparison = StringComparison.CurrentCulture, _
  13.                                               Optional ByVal DigitLength As Long = 0) As String
  14.  
  15.        Dim str_split() As String = str.Split
  16.        Dim replacement As String = Nothing
  17.        Dim IndexCount As Long = 0
  18.  
  19.        DigitLength = If(DigitLength = 0, replace.Length, DigitLength)
  20.  
  21.        For Item As Long = 0 To str_split.LongCount - 1
  22.  
  23.            If str_split(Item).Equals(replace, IgnoreCase) Then
  24.  
  25.                replacement &= Threading.Interlocked.Increment(IndexCount).ToString
  26.  
  27.                While Not replacement.Length >= DigitLength
  28.                    replacement = replacement.Insert(0, "0")
  29.                End While
  30.  
  31.                str_split(Item) = replacement
  32.                replacement = Nothing
  33.  
  34.            End If
  35.  
  36.        Next Item
  37.  
  38.        Return String.Join(Convert.ToChar(Keys.Space), str_split)
  39.  
  40.    End Function
  41.  
  42. #End Region


Este código reemplaza un patrón de búsqueda en un string, por una secuencia numérica:

Código
  1. #Region " Replace String (Increment method) "
  2.  
  3.    ' [ Replace String (Increment method) ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Replace_String_By_Increment("Hello World!, Hello World!", New System.Text.RegularExpressions.Regex("Hello\sWorld", RegexOptions.IgnoreCase), 3)) ' Result: 001!, 002!
  9.  
  10.    Private Function Replace_String_By_Increment(ByVal str As String, _
  11.                                                 ByVal replace As System.Text.RegularExpressions.Regex, _
  12.                                                 Optional ByVal DigitLength As Long = 0) As String
  13.  
  14.        DigitLength = If(DigitLength = 0, replace.ToString.Length, DigitLength)
  15.  
  16.        Dim IndexCount As Integer = 0
  17.        Dim replacement As String = Nothing
  18.        Dim matches As System.Text.RegularExpressions.MatchCollection = replace.Matches(str)
  19.  
  20.        For Each match As System.Text.RegularExpressions.Match In matches
  21.  
  22.            replacement &= Threading.Interlocked.Increment(IndexCount).ToString
  23.  
  24.            While Not replacement.Length >= DigitLength
  25.                replacement = replacement.Insert(0, "0")
  26.            End While
  27.  
  28.            str = replace.Replace(str, replacement, 1, match.Index - (match.Length * (IndexCount - 1)))
  29.            replacement = Nothing
  30.  
  31.        Next
  32.  
  33.        matches = Nothing
  34.        replacement = Nothing
  35.        IndexCount = 0
  36.        Return str
  37.  
  38.    End Function
  39.  
  40. #End Region

Disculpen la ignorancia, apenas conozco algo de batch, este codigo me interesa, pero la verdad es q no sé como utilizarlo, q se supone q debo hacer con el codigo? lo copie a un archivo de texto y le puse la extension .vbs, hice bien? crei q funcionaría como un batch, lo ejecuté y me salio error de compilación o algo así, por favor q alguien me ayude  :-\
En línea

Novlucker
Ninja y
Colaborador
***
Desconectado Desconectado

Mensajes: 10.683

Yo que tu lo pienso dos veces


Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #314 en: 14 Octubre 2013, 00:02 am »

Estamos en el subforo de .NET, es VB.NET :¬¬

Saludos
En línea

Contribuye con la limpieza del foro, reporta los "casos perdidos" a un MOD XD
"Hay dos cosas infinitas: el Universo y la estupidez  humana. Y de la primera no estoy muy seguro."
Albert Einstein
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #315 en: 14 Octubre 2013, 04:37 am »

@MauriH

Vuelve a leer este post hasta el final: http://foro.elhacker.net/net/libreria_de_snippets_posteen_aqui_sus_snippets-t378770.0.html;msg1891125#msg1891125

He subido un proyecto de prueba a Mediafire.

Saludos
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #316 en: 14 Octubre 2013, 07:14 am »

Añadir la funcionalidad 'Find Next' y 'Find Previous' en un RichTextBox,
Le añadi soporte para poder utilizar expresiones regulares y también para poder resaltar el text seleccionado en colores :).



Código
  1. #Region " [RichTextBox] FindNext "
  2.  
  3.    ' [ FindNext ]
  4.    '
  5.    ' //By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' RichTextBox1.Text = "Hello World!, Hello World!, Hello World!"
  10.    '
  11.    ' FindNext(RichTextBox1, "hello", FindDirection.Down, RegexOptions.IgnoreCase, Color.LightBlue, Color.Black)
  12.    ' FindNext(RichTextBox1, "hello", FindDirection.Up, RegexOptions.IgnoreCase, Color.Red, Color.Black)
  13.    '
  14.    ' Private Sub RichTextBox_Enter(sender As Object, e As EventArgs) ' Handles RichTextBox1.Enter
  15.    '    ' Restore Selection Colors before search next match.
  16.    '    sender.SelectionBackColor = DefaultBackColor
  17.    '    sender.SelectionColor = DefaultForeColor
  18.    ' End Sub
  19.  
  20.    Public Enum FindDirection
  21.        Up = 0
  22.        Down = 1
  23.    End Enum
  24.  
  25.    ' FindNext
  26.    Private Sub FindNext(ByVal [Control] As RichTextBox, _
  27.                               ByVal SearchText As String, _
  28.                               ByVal Direction As FindDirection, _
  29.                               Optional ByVal IgnoreCase As System.Text.RegularExpressions.RegexOptions = RegexOptions.None, _
  30.                               Optional ByVal Highlight_BackColor As Color = Nothing, _
  31.                               Optional ByVal Highlight_ForeColor As Color = Nothing)
  32.  
  33.        If [Control].TextLength = 0 Then Exit Sub
  34.  
  35.        ' Start searching at 'SelectionStart'.
  36.        Dim Search_StartIndex As Integer = [Control].SelectionStart
  37.  
  38.        ' Stores the MatchIndex count
  39.        Dim matchIndex As Integer = 0
  40.  
  41.        ' Flag to check if it's first find call
  42.        Static First_Find As Boolean = True
  43.  
  44.        ' Checks to don't ommit the selection of first match if match index is exactly at 0 start point.
  45.        If First_Find _
  46.            AndAlso Search_StartIndex = 0 _
  47.            AndAlso Direction = FindDirection.Down Then
  48.            Search_StartIndex = -1
  49.            First_Find = False
  50.        ElseIf Not First_Find _
  51.            AndAlso Search_StartIndex = 0 _
  52.            AndAlso Direction = FindDirection.Down Then
  53.            First_Find = False
  54.            Search_StartIndex = 0
  55.        End If
  56.  
  57.        ' Store the matches
  58.        Dim matches As System.Text.RegularExpressions.MatchCollection = _
  59.            System.Text.RegularExpressions.Regex.Matches([Control].Text, _
  60.                                                         SearchText, _
  61.                                                         IgnoreCase Or If(Direction = FindDirection.Up, _
  62.                                                                          RegexOptions.RightToLeft, _
  63.                                                                          RegexOptions.None))
  64.  
  65.        If matches.Count = 0 Then First_Find = True : Exit Sub
  66.  
  67.        ' Restore Highlight colors of previous selection
  68.        [Control].SelectionBackColor = [Control].BackColor
  69.        [Control].SelectionColor = [Control].ForeColor
  70.  
  71.        ' Set next selection Highlight colors
  72.        If Highlight_BackColor = Nothing Then Highlight_BackColor = [Control].BackColor
  73.        If Highlight_ForeColor = Nothing Then Highlight_ForeColor = [Control].ForeColor
  74.  
  75.        ' Set the match selection
  76.        For Each match As System.Text.RegularExpressions.Match In matches
  77.  
  78.            matchIndex += 1
  79.  
  80.            Select Case Direction
  81.  
  82.                Case FindDirection.Down
  83.                    If match.Index > Search_StartIndex Then ' Select next match
  84.                        [Control].Select(match.Index, match.Length)
  85.                        Exit For
  86.                    ElseIf match.Index <= Search_StartIndex _
  87.                    AndAlso matchIndex = matches.Count Then ' Select first match
  88.                        [Control].Select(matches.Item(0).Index, matches.Item(0).Length)
  89.                        Exit For
  90.                    End If
  91.  
  92.                Case FindDirection.Up
  93.                    If match.Index < Search_StartIndex Then ' Select previous match
  94.                        [Control].Select(match.Index, match.Length)
  95.                        Exit For
  96.                    ElseIf match.Index >= Search_StartIndex _
  97.                    AndAlso matchIndex = matches.Count Then ' Select last match
  98.                        [Control].Select(matches.Item(0).Index, matches.Item(0).Length)
  99.                        Exit For
  100.                    End If
  101.  
  102.            End Select
  103.  
  104.        Next match
  105.  
  106.        ' Set the current selection BackColor
  107.        [Control].SelectionBackColor = Highlight_BackColor
  108.        ' Set the current selection ForeColor
  109.        [Control].SelectionColor = Highlight_ForeColor
  110.        ' Scroll to Caret/Cursor selection position
  111.        [Control].ScrollToCaret()
  112.  
  113.    End Sub
  114.  
  115. #End Region


EDITO:

Aquí dejo una versión alternativa, no soporta RegEx y no soporta búsqueda hacia arriba,
el código no es peor, símplemente si no se requiere el uso de búsqueda por RegEx ni buscar hacia arriba entonces es preferible usar este snippet.

Código
  1. #Region " [RichTextBox] FindNext String "
  2.  
  3.    ' [ FindNext String ]
  4.    '
  5.    ' //By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' FindNext(RichTextBox1, "Hello", RichTextBoxFinds.MatchCase, Color.LightBlue, Color.Black)
  10.    '
  11.    ' Private Sub RichTextBox_Enter(sender As Object, e As EventArgs) ' Handles RichTextBox1.Enter
  12.    '    ' Restore Selection Colors before search next match.
  13.    '    sender.SelectionBackColor = DefaultBackColor
  14.    '    sender.SelectionColor = DefaultForeColor
  15.    ' End Sub
  16.  
  17.    ' FindNext
  18.    Private Sub FindNext(ByVal [Control] As RichTextBox, _
  19.                        ByVal SearchText As String, _
  20.                        ByVal IgnoreCase As RichTextBoxFinds, _
  21.                        Optional ByVal Highlight_BackColor As Color = Nothing, _
  22.                        Optional ByVal Highlight_ForeColor As Color = Nothing)
  23.  
  24.        ' Start searching at 'SelectionStart'.
  25.        Dim Search_StartIndex As Integer = [Control].SelectionStart
  26.        Static Next_Count As Integer = 0
  27.  
  28.        ' Restore Highlight colors of previous selection
  29.        [Control].SelectionBackColor = [Control].BackColor
  30.        [Control].SelectionColor = [Control].ForeColor
  31.  
  32.        ' Set next selection Highlight colors
  33.        If Highlight_BackColor = Nothing Then Highlight_BackColor = [Control].BackColor
  34.        If Highlight_ForeColor = Nothing Then Highlight_ForeColor = [Control].ForeColor
  35.  
  36.        ' If is not first FindNext call then...
  37.        If Next_Count <> 0 Then
  38.            Search_StartIndex += SearchText.Length
  39.        Else ' If is first FindNext call then...
  40.            Next_Count += 1
  41.        End If
  42.  
  43.        ' Set Search_StartIndex
  44.        Search_StartIndex = _
  45.        [Control].Find(SearchText, Search_StartIndex, IgnoreCase)
  46.        ' ...And prevent search at End Of File
  47.        If Search_StartIndex = -1 Then
  48.            Search_StartIndex = _
  49.            [Control].Find(SearchText, 0, IgnoreCase)
  50.        End If
  51.  
  52.        If Search_StartIndex = -1 Then
  53.            Exit Sub ' No matches found
  54.        End If
  55.  
  56.        ' Set the match selection
  57.        [Control].Select(Search_StartIndex, SearchText.Length)
  58.        ' Set the BackColor
  59.        [Control].SelectionBackColor = Highlight_BackColor
  60.        ' Set the ForeColor
  61.        [Control].SelectionColor = Highlight_ForeColor
  62.        ' Scroll to Caret/Cursor position
  63.        [Control].ScrollToCaret()
  64.  
  65.    End Sub
  66.  
  67. #End Region
« Última modificación: 14 Octubre 2013, 07:35 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #317 en: 14 Octubre 2013, 19:09 pm »

Una class para manejar bases de clientes,
En principio el código original lo descargué de la página CodeProject, pero lo modifiqué casi por completo y además le añadi +20 funciones genéricas para que las operaciones más comunes no requieran escritura de código adicional.

(La lista de contactos es facil de añadir en un Listview/DataGridView)

Esto es un ejemplo de para que sirve:



EDITO: He añadido un par de funciones más.

Código
  1. #Region " Contact "
  2.  
  3. #Region " Examples (Normal usage)"
  4.  
  5. ' Create a new list of contacts
  6. ' Dim Contacts As List(Of Contact) = New List(Of Contact)
  7. ' Or load ContactList from previous serialized file
  8. ' Dim Contacts As List(Of Contact) = ContactSerializer.Deserialize("C:\Contacts.bin")
  9.  
  10. ' Set a variable to store the current contact position
  11. ' Dim CurrentPosition As Integer = 0
  12.  
  13. ' Create a new contact
  14. ' Dim CurrentContact As Contact = New Contact With { _
  15. '     .Name = "Manolo", _
  16. '     .Surname = "El del Bombo", _
  17. '     .Country = "Spain", _
  18. '     .City = "Valencia", _
  19. '     .Street = "Av. Mestalla", _
  20. '     .ZipCode = "42731", _
  21. '     .Phone = "96.XXX.XX.XX", _
  22. '     .CellPhone = "651.XXX.XXX", _
  23. '     .Email = "ManoloToLoko@Gmail.com"}
  24.  
  25. ' Add a contact to contacts list
  26. ' Contacts.Add(CurrentContact)
  27.  
  28. ' Update the CurrentPosition index value
  29. ' CurrentPosition = Contacts.IndexOf(CurrentContact)
  30.  
  31. #End Region
  32.  
  33. #Region " Examples (Generic functions) "
  34.  
  35.  
  36. ' Examples:
  37. '
  38. ' -----------------
  39. ' Add a new contact
  40. ' -----------------
  41. ' Contact.Add_Contact(ContactList, "Manolo", "El del Bombo", "Spain", "Valencia", "Av. Mestalla", "42731", "96.XXX.XX.XX", "651.XXX.XXX", "ManoloToLoko@Gmail.com")
  42. '
  43. '
  44. ' -----------------------------------------------------------------
  45. ' Load a contact from an existing contacts list into TextBox Fields
  46. ' -----------------------------------------------------------------
  47. ' Contact.Load_Contact(ContactList, 0, TextBox_Name, textbox_surName, TextBox_Country, textbox_City, TextBox_Street, TextBox_ZipCode, TextBox_Phone, TextBox_CellPhone, TextBox_email)
  48. '
  49. '
  50. ' ----------------------------------
  51. ' Load a contact into TextBox Fields
  52. ' ----------------------------------
  53. ' Contact.Load_Contact(Contact, TextBox_Name, textbox_surName, TextBox_Country, textbox_City, TextBox_Street, TextBox_ZipCode, TextBox_Phone, TextBox_CellPhone, TextBox_email)
  54. '
  55. '
  56. ' ---------------------------------
  57. ' Load a contact list into ListView
  58. ' ---------------------------------
  59. ' Contact.Load_ContactList_Into_ListView(ContactList, ListView1)
  60. '
  61. '
  62. ' -------------------------------------
  63. ' Load a contact list into DataGrivView
  64. ' -------------------------------------
  65. ' Contact.Load_ContactList_Into_DataGrivView(ContactList, DataGrivView1)
  66. '
  67. '
  68. ' -------------------------------------------
  69. ' Load a contacts list from a serialized file
  70. ' -------------------------------------------
  71. ' Dim ContactList As List(Of Contact) = Contact.Load_ContactList("C:\Contacts.bin")
  72. '
  73. '
  74. ' -----------------------------------------------------------------------
  75. ' Find the first occurrence of a contact name in a existing contacts list
  76. ' -----------------------------------------------------------------------
  77. ' Dim ContactFound As Contact = Contact.Match_Contact_Name_FirstOccurrence(ContactList, "Manolo")
  78. '
  79. '
  80. ' ----------------------------------------------------------------------
  81. ' Find all the occurrences of a contact name in a existing contacts list
  82. ' ----------------------------------------------------------------------
  83. ' Dim ContactsFound As List(Of Contact) = Contact.Match_Contact_Name(ContactList, "Manolo")
  84. '
  85. '
  86. ' -------------------------------------------------------------
  87. ' Remove a contact from a Contact List giving the contact index
  88. ' -------------------------------------------------------------
  89. ' Remove_Contact(ContactList, 0)
  90. '
  91. '
  92. ' -------------------------------------------------------
  93. ' Remove a contact from a Contact List giving the contact
  94. ' -------------------------------------------------------
  95. ' Remove_Contact(ContactList, MyContact)
  96. '
  97. '
  98. ' -------------------------
  99. ' Save the contacts to file
  100. ' -------------------------
  101. ' Contact.Save_ContactList(ContactList, "C:\Contacts.bin")
  102. '
  103. '
  104. ' -------------------------
  105. ' Sort the contacts by name
  106. ' -------------------------
  107. ' Dim SorteredContacts As List(Of Contact) = Contact.Sort_ContactList_By_Name(ContactList, Contact.ContectSortMode.Ascending)
  108. '
  109. '
  110. ' --------------------------------------------------------------------
  111. ' Get a formatted string containing the details of an existing contact
  112. ' --------------------------------------------------------------------
  113. ' MsgBox(Contact.Get_Contact_Details(ContactList, 0))
  114. ' MsgBox(Contact.Get_Contact_Details(CurrentContact))
  115. '    
  116. '
  117. ' ----------------------------------------------------------------------------------
  118. ' Copy to clipboard a formatted string containing the details of an existing contact
  119. ' ----------------------------------------------------------------------------------
  120. ' Contact.Copy_Contact_Details_To_Clipboard(ContactList, 0)
  121. ' Contact.Copy_Contact_Details_To_Clipboard(CurrentContact)
  122.  
  123.  
  124. #End Region
  125.  
  126. <Serializable()> _
  127. Public Class Contact
  128.  
  129.    Public Enum ContectSortMode As Short
  130.        Ascending = 0
  131.        Descending = 1
  132.    End Enum
  133.  
  134. #Region "Member Variables"
  135.  
  136.    Private mId As System.Guid
  137.    Private mName As String
  138.    Private mSurname As String
  139.    Private mCountry As String
  140.    Private mCity As String
  141.    Private mStreet As String
  142.    Private mZip As String
  143.    Private mPhone As String
  144.    Private mCellPhone As String
  145.    Private mEmail As String
  146.  
  147. #End Region
  148.  
  149. #Region "Constructor"
  150.  
  151.    Public Sub New()
  152.        mId = Guid.NewGuid()
  153.    End Sub
  154.  
  155.  
  156.    Public Sub New(ByVal ID As System.Guid)
  157.        mId = ID
  158.    End Sub
  159.  
  160. #End Region
  161.  
  162. #Region "Properties"
  163.  
  164.    Public Property Name() As String
  165.        Get
  166.            Return mName
  167.        End Get
  168.        Set(ByVal value As String)
  169.            mName = value
  170.        End Set
  171.    End Property
  172.  
  173.    Public Property Surname() As String
  174.        Get
  175.            Return mSurname
  176.        End Get
  177.        Set(ByVal value As String)
  178.            mSurname = value
  179.        End Set
  180.    End Property
  181.  
  182.    Public Property Street() As String
  183.        Get
  184.            Return mStreet
  185.        End Get
  186.        Set(ByVal value As String)
  187.            mStreet = value
  188.        End Set
  189.    End Property
  190.  
  191.    Public Property City() As String
  192.        Get
  193.            Return mCity
  194.        End Get
  195.        Set(ByVal value As String)
  196.            mCity = value
  197.        End Set
  198.    End Property
  199.  
  200.    Public Property Country() As String
  201.        Get
  202.            Return mCountry
  203.        End Get
  204.        Set(ByVal value As String)
  205.            mCountry = value
  206.        End Set
  207.    End Property
  208.  
  209.    Public Property ZipCode() As String
  210.        Get
  211.            Return mZip
  212.        End Get
  213.        Set(ByVal value As String)
  214.            mZip = value
  215.        End Set
  216.    End Property
  217.  
  218.    Public Property Email() As String
  219.        Get
  220.            Return mEmail
  221.        End Get
  222.        Set(ByVal value As String)
  223.            mEmail = value
  224.        End Set
  225.    End Property
  226.  
  227.    Public Property Phone() As String
  228.        Get
  229.            Return mPhone
  230.        End Get
  231.        Set(ByVal value As String)
  232.            mPhone = value
  233.        End Set
  234.    End Property
  235.  
  236.    Public Property CellPhone() As String
  237.        Get
  238.            Return mCellPhone
  239.        End Get
  240.        Set(ByVal value As String)
  241.            mCellPhone = value
  242.        End Set
  243.    End Property
  244.  
  245. #End Region
  246.  
  247. #Region " ContactSerializer "
  248.  
  249.    Public Class ContactSerializer
  250.  
  251.        ''' <summary>
  252.        ''' Serialize a contact list into a contacts file.
  253.        ''' </summary>
  254.        ''' <param name="ContactList"></param>
  255.        ''' <param name="FilePath"></param>
  256.        ''' <remarks></remarks>
  257.        Public Shared Sub Save(ByVal ContactList As List(Of Contact), _
  258.                                    ByVal FilePath As String)
  259.  
  260.            Dim fs As IO.FileStream = Nothing
  261.            Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
  262.  
  263.            Try
  264.                fs = New IO.FileStream(FilePath, IO.FileMode.OpenOrCreate)
  265.                formatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
  266.                formatter.Serialize(fs, ContactList)
  267.  
  268.            Catch ex As Exception
  269.  
  270.                MessageBox.Show(String.Format("{0}:{1}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace), _
  271.                                "Error", _
  272.                                MessageBoxButtons.OK, _
  273.                                MessageBoxIcon.Error)
  274.  
  275.            Finally
  276.                If fs IsNot Nothing Then fs.Dispose()
  277.  
  278.            End Try
  279.  
  280.        End Sub
  281.  
  282.        ''' <summary>
  283.        ''' Deserialize an existing file into a contact list.
  284.        ''' </summary>
  285.        ''' <param name="FilePath"></param>
  286.        ''' <returns></returns>
  287.        ''' <remarks></remarks>
  288.        Public Shared Function Load(ByVal FilePath As String) As List(Of Contact)
  289.  
  290.            Dim fs As IO.FileStream = Nothing
  291.            Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
  292.  
  293.            Try
  294.                fs = New IO.FileStream(FilePath, IO.FileMode.Open)
  295.                formatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
  296.                Return formatter.Deserialize(fs)
  297.  
  298.            Catch ex As Exception
  299.  
  300.                MessageBox.Show(String.Format("{0}:{1}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace), _
  301.                                "Error", _
  302.                                MessageBoxButtons.OK, _
  303.                                MessageBoxIcon.Error)
  304.                Return Nothing
  305.  
  306.            Finally
  307.                If fs IsNot Nothing Then fs.Dispose()
  308.  
  309.            End Try
  310.  
  311.        End Function
  312.  
  313.    End Class
  314.  
  315. #End Region
  316.  
  317. #Region " Generic Functions "
  318.  
  319.    ' Formatted String of contact detailed information
  320.    Shared ReadOnly DetailsFormat As String = _
  321.    "Name.....: {1}{0}Surname..: {2}{0}Country..: {3}{0}City.....: {4}{0}Street...: {5}{0}Zipcode..: {6}{0}Phone....: {7}{0}CellPhone: {8}{0}Email....: {9}"
  322.  
  323.    ''' <summary>
  324.    ''' Add a new contact into a existing contacts list.
  325.    ''' </summary>
  326.    Public Shared Sub Add_Contact(ByVal ContactList As List(Of Contact), _
  327.                           ByVal Name As String, _
  328.                           ByVal Surname As String, _
  329.                           ByVal Country As String, _
  330.                           ByVal City As String, _
  331.                           ByVal Street As String, _
  332.                           ByVal ZipCode As String, _
  333.                           ByVal Phone As String, _
  334.                           ByVal CellPhone As String, _
  335.                           ByVal Email As String)
  336.  
  337.        ContactList.Add(New Contact With { _
  338.                        .Name = Name, _
  339.                        .Surname = Surname, _
  340.                        .Country = Country, _
  341.                        .City = City, _
  342.                        .Street = Street, _
  343.                        .ZipCode = ZipCode, _
  344.                        .Phone = Phone, _
  345.                        .CellPhone = CellPhone, _
  346.                        .Email = Email _
  347.                    })
  348.  
  349.    End Sub
  350.  
  351.    ''' <summary>
  352.    ''' Remove a contact from an existing contacts list.
  353.    ''' </summary>
  354.    Public Shared Sub Remove_Contact(ByVal ContactList As List(Of Contact), ByVal ContactIndex As Integer)
  355.        ContactList.RemoveAt(ContactIndex)
  356.    End Sub
  357.  
  358.    ''' <summary>
  359.    ''' Remove a contact from an existing contacts list.
  360.    ''' </summary>
  361.    Public Shared Sub Remove_Contact(ByVal ContactList As List(Of Contact), ByVal Contact As Contact)
  362.        ContactList.Remove(Contact)
  363.    End Sub
  364.  
  365.    ''' <summary>
  366.    ''' Find the first occurrence of a contact name in an existing contacts list.
  367.    ''' </summary>
  368.    Public Shared Function Match_Contact_Name_FirstOccurrence(ByVal ContactList As List(Of Contact), ByVal Name As String) As Contact
  369.  
  370.        Return ContactList.Find(Function(contact) contact.Name.ToLower.StartsWith(Name.ToLower) _
  371.                                OrElse contact.Name.ToLower.Contains(Name.ToLower))
  372.    End Function
  373.  
  374.    ''' <summary>
  375.    ''' Find all the occurrences of a contact name in a existing contacts list.
  376.    ''' </summary>
  377.    Public Shared Function Match_Contact_Name(ByVal ContactList As List(Of Contact), ByVal Name As String) As List(Of Contact)
  378.  
  379.        Return ContactList.FindAll(Function(contact) contact.Name.ToLower.StartsWith(Name.ToLower) _
  380.                                   OrElse contact.Name.ToLower.Contains(Name.ToLower))
  381.  
  382.    End Function
  383.  
  384.    ''' <summary>
  385.    ''' Load a contact from an existing contacts list into textbox fields.
  386.    ''' </summary>
  387.    Public Shared Sub Load_Contact(ByVal ContactList As List(Of Contact), _
  388.                            ByVal ContactIndex As Integer, _
  389.                            ByVal TextBox_Name As TextBox, _
  390.                            ByVal TextBox_Surname As TextBox, _
  391.                            ByVal TextBox_Country As TextBox, _
  392.                            ByVal TextBox_City As TextBox, _
  393.                            ByVal TextBox_Street As TextBox, _
  394.                            ByVal TextBox_Zipcode As TextBox, _
  395.                            ByVal TextBox_Phone As TextBox, _
  396.                            ByVal TextBox_CellPhone As TextBox, _
  397.                            ByVal TextBox_Email As TextBox)
  398.  
  399.        TextBox_Name.Text = ContactList.Item(ContactIndex).Name
  400.        TextBox_Surname.Text = ContactList.Item(ContactIndex).Surname
  401.        TextBox_Country.Text = ContactList.Item(ContactIndex).Country
  402.        TextBox_City.Text = ContactList.Item(ContactIndex).City
  403.        TextBox_Street.Text = ContactList.Item(ContactIndex).Street
  404.        TextBox_Zipcode.Text = ContactList.Item(ContactIndex).ZipCode
  405.        TextBox_Phone.Text = ContactList.Item(ContactIndex).Phone
  406.        TextBox_CellPhone.Text = ContactList.Item(ContactIndex).CellPhone
  407.        TextBox_Email.Text = ContactList.Item(ContactIndex).Email
  408.  
  409.    End Sub
  410.  
  411.    ''' <summary>
  412.    ''' Load a contact into textbox fields.
  413.    ''' </summary>
  414.    Public Shared Sub Load_Contact(ByVal Contact As Contact, _
  415.                            ByVal TextBox_Name As TextBox, _
  416.                            ByVal TextBox_Surname As TextBox, _
  417.                            ByVal TextBox_Country As TextBox, _
  418.                            ByVal TextBox_City As TextBox, _
  419.                            ByVal TextBox_Street As TextBox, _
  420.                            ByVal TextBox_Zipcode As TextBox, _
  421.                            ByVal TextBox_Phone As TextBox, _
  422.                            ByVal TextBox_CellPhone As TextBox, _
  423.                            ByVal TextBox_Email As TextBox)
  424.  
  425.        TextBox_Name.Text = Contact.Name
  426.        TextBox_Surname.Text = Contact.Surname
  427.        TextBox_Country.Text = Contact.Country
  428.        TextBox_City.Text = Contact.City
  429.        TextBox_Street.Text = Contact.Street
  430.        TextBox_Zipcode.Text = Contact.ZipCode
  431.        TextBox_Phone.Text = Contact.Phone
  432.        TextBox_CellPhone.Text = Contact.CellPhone
  433.        TextBox_Email.Text = Contact.Email
  434.  
  435.    End Sub
  436.  
  437.    ''' <summary>
  438.    ''' Seriale a contacts list to a file.
  439.    ''' </summary>
  440.    Public Shared Sub Save_ContactList(ByVal ContactList As List(Of Contact), ByVal FilePath As String)
  441.  
  442.        Contact.ContactSerializer.Save(ContactList, FilePath)
  443.  
  444.    End Sub
  445.  
  446.    ''' <summary>
  447.    ''' Load a contacts list from a serialized file.
  448.    ''' </summary>
  449.    Public Shared Function Load_ContactList(ByVal FilePath As String) As List(Of Contact)
  450.  
  451.        Return Contact.ContactSerializer.Load(FilePath)
  452.  
  453.    End Function
  454.  
  455.    ''' <summary>
  456.    ''' Reorder the contacts of a Contacts List by the Name field.
  457.    ''' </summary>
  458.    Public Shared Function Sort_ContactList_By_Name(ByVal ContactList As List(Of Contact), _
  459.                                              ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  460.  
  461.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  462.                  ContactList.OrderBy(Function(contact) contact.Name).ToList(), _
  463.                  ContactList.OrderByDescending(Function(contact) contact.Name).ToList())
  464.  
  465.    End Function
  466.  
  467.    ''' <summary>
  468.    ''' Reorder the contacts of a Contacts List by the Surname field.
  469.    ''' </summary>
  470.    Public Shared Function Sort_ContactList_By_Surname(ByVal ContactList As List(Of Contact), _
  471.                                                 ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  472.  
  473.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  474.                  ContactList.OrderBy(Function(contact) contact.Surname).ToList(), _
  475.                  ContactList.OrderByDescending(Function(contact) contact.Surname).ToList())
  476.  
  477.    End Function
  478.  
  479.    ''' <summary>
  480.    ''' Reorder the contacts of a Contacts List by the Country field.
  481.    ''' </summary>
  482.    Public Shared Function Sort_ContactList_By_Country(ByVal ContactList As List(Of Contact), _
  483.                                                 ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  484.  
  485.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  486.                  ContactList.OrderBy(Function(contact) contact.Country).ToList(), _
  487.                  ContactList.OrderByDescending(Function(contact) contact.Country).ToList())
  488.  
  489.    End Function
  490.  
  491.    ''' <summary>
  492.    ''' Reorder the contacts of a Contacts List by the City field.
  493.    ''' </summary>
  494.    Public Shared Function Sort_ContactList_By_City(ByVal ContactList As List(Of Contact), _
  495.                                              ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  496.  
  497.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  498.                  ContactList.OrderBy(Function(contact) contact.City).ToList(), _
  499.                  ContactList.OrderByDescending(Function(contact) contact.City).ToList())
  500.  
  501.    End Function
  502.  
  503.    ''' <summary>
  504.    ''' Reorder the contacts of a Contacts List by the Street field.
  505.    ''' </summary>
  506.    Public Shared Function Sort_ContactList_By_Street(ByVal ContactList As List(Of Contact), _
  507.                                                ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  508.  
  509.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  510.                  ContactList.OrderBy(Function(contact) contact.Street).ToList(), _
  511.                  ContactList.OrderByDescending(Function(contact) contact.Street).ToList())
  512.  
  513.    End Function
  514.  
  515.    ''' <summary>
  516.    ''' Reorder the contacts of a Contacts List by the Zipcode field.
  517.    ''' </summary>
  518.    Public Shared Function Sort_ContactList_By_Zipcode(ByVal ContactList As List(Of Contact), _
  519.                                                 ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  520.  
  521.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  522.                  ContactList.OrderBy(Function(contact) contact.ZipCode).ToList(), _
  523.                  ContactList.OrderByDescending(Function(contact) contact.ZipCode).ToList())
  524.  
  525.    End Function
  526.  
  527.    ''' <summary>
  528.    ''' Reorder the contacts of a Contacts List by the Phone field.
  529.    ''' </summary>
  530.    Public Shared Function Sort_ContactList_By_Phone(ByVal ContactList As List(Of Contact), _
  531.                                               ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  532.  
  533.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  534.                  ContactList.OrderBy(Function(contact) contact.Phone).ToList(), _
  535.                  ContactList.OrderByDescending(Function(contact) contact.Phone).ToList())
  536.  
  537.    End Function
  538.  
  539.    ''' <summary>
  540.    ''' Reorder the contacts of a Contacts List by the CellPhone field.
  541.    ''' </summary>
  542.    Public Shared Function Sort_ContactList_By_CellPhone(ByVal ContactList As List(Of Contact), _
  543.                                                   ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  544.  
  545.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  546.                  ContactList.OrderBy(Function(contact) contact.CellPhone).ToList(), _
  547.                  ContactList.OrderByDescending(Function(contact) contact.CellPhone).ToList())
  548.  
  549.    End Function
  550.  
  551.    ''' <summary>
  552.    ''' Reorder the contacts of a Contacts List by the Email field.
  553.    ''' </summary>
  554.    Public Shared Function Sort_ContactList_By_Email(ByVal ContactList As List(Of Contact), _
  555.                                               ByVal ContectSortMode As Contact.ContectSortMode) As List(Of Contact)
  556.  
  557.        Return If(ContectSortMode = Contact.ContectSortMode.Ascending, _
  558.                  ContactList.OrderBy(Function(contact) contact.Email).ToList(), _
  559.                  ContactList.OrderByDescending(Function(contact) contact.Email).ToList())
  560.  
  561.    End Function
  562.  
  563.    ''' <summary>
  564.    ''' Get a formatted string containing the details of an existing contact.
  565.    ''' </summary>
  566.    Public Shared Function Get_Contact_Details(ByVal ContactList As List(Of Contact), ByVal ContactIndex As Integer) As String
  567.  
  568.        Return String.Format(DetailsFormat, _
  569.                             Environment.NewLine, _
  570.                             ContactList.Item(ContactIndex).Name, _
  571.                             ContactList.Item(ContactIndex).Surname, _
  572.                             ContactList.Item(ContactIndex).Country, _
  573.                             ContactList.Item(ContactIndex).City, _
  574.                             ContactList.Item(ContactIndex).Street, _
  575.                             ContactList.Item(ContactIndex).ZipCode, _
  576.                             ContactList.Item(ContactIndex).Phone, _
  577.                             ContactList.Item(ContactIndex).CellPhone, _
  578.                             ContactList.Item(ContactIndex).Email)
  579.  
  580.    End Function
  581.  
  582.    ''' <summary>
  583.    ''' Get a formatted string containing the details of an existing contact.
  584.    ''' </summary>
  585.    Public Shared Function Get_Contact_Details(ByVal Contact As Contact) As String
  586.  
  587.        Return String.Format(DetailsFormat, _
  588.                             Environment.NewLine, _
  589.                             Contact.Name, _
  590.                             Contact.Surname, _
  591.                             Contact.Country, _
  592.                             Contact.City, _
  593.                             Contact.Street, _
  594.                             Contact.ZipCode, _
  595.                             Contact.Phone, _
  596.                             Contact.CellPhone, _
  597.                             Contact.Email)
  598.  
  599.    End Function
  600.  
  601.    ''' <summary>
  602.    ''' Copy to clipboard a formatted string containing the details of an existing contact.
  603.    ''' </summary>
  604.    Public Shared Sub Copy_Contact_Details_To_Clipboard(ByVal ContactList As List(Of Contact), ByVal ContactIndex As Integer)
  605.  
  606.        Clipboard.SetText(String.Format(DetailsFormat, _
  607.                          Environment.NewLine, _
  608.                          ContactList.Item(ContactIndex).Name, _
  609.                          ContactList.Item(ContactIndex).Surname, _
  610.                          ContactList.Item(ContactIndex).Country, _
  611.                          ContactList.Item(ContactIndex).City, _
  612.                          ContactList.Item(ContactIndex).Street, _
  613.                          ContactList.Item(ContactIndex).ZipCode, _
  614.                          ContactList.Item(ContactIndex).Phone, _
  615.                          ContactList.Item(ContactIndex).CellPhone, _
  616.                          ContactList.Item(ContactIndex).Email))
  617.  
  618.    End Sub
  619.  
  620.    ''' <summary>
  621.    ''' Copy to clipboard a formatted string containing the details of an existing contact.
  622.    ''' </summary>
  623.    Public Shared Sub Copy_Contact_Details_To_Clipboard(ByVal Contact As Contact)
  624.  
  625.        Clipboard.SetText(String.Format(DetailsFormat, _
  626.                          Environment.NewLine, _
  627.                          Contact.Name, _
  628.                          Contact.Surname, _
  629.                          Contact.Country, _
  630.                          Contact.City, _
  631.                          Contact.Street, _
  632.                          Contact.ZipCode, _
  633.                          Contact.Phone, _
  634.                          Contact.CellPhone, _
  635.                          Contact.Email))
  636.  
  637.    End Sub
  638.  
  639.    ''' <summary>
  640.    ''' Load an existing contacts list into a ListView.
  641.    ''' </summary>
  642.    Public Shared Sub Load_ContactList_Into_ListView(ByVal ContactList As List(Of Contact), _
  643.                                                     ByVal Listview As ListView)
  644.  
  645.        Listview.Items.AddRange( _
  646.                       ContactList _
  647.                       .Select(Function(Contact) _
  648.                               New ListViewItem(New String() { _
  649.                                                                Contact.Name, _
  650.                                                                Contact.Surname, _
  651.                                                                Contact.Country, _
  652.                                                                Contact.City, _
  653.                                                                Contact.Street, _
  654.                                                                Contact.ZipCode, _
  655.                                                                Contact.Phone, _
  656.                                                                Contact.CellPhone, _
  657.                                                                Contact.Email _
  658.                                                             })).ToArray())
  659.  
  660.    End Sub
  661.  
  662.    ''' <summary>
  663.    ''' Load an existing contacts list into a DataGridView.
  664.    ''' </summary>
  665.    Public Shared Sub Load_ContactList_Into_DataGridView(ByVal ContactList As List(Of Contact), _
  666.                                                         ByVal DataGridView As DataGridView)
  667.  
  668.        DataGridView.DataSource = ContactList
  669.        ' Sortered:
  670.        ' DataGridView.DataSource = (From Contact In ContactList Order By Contact.Name Ascending Select Contact).ToList
  671.  
  672.    End Sub
  673.  
  674.  
  675. #End Region
  676.  
  677. End Class
  678.  
  679. #End Region
« Última modificación: 15 Octubre 2013, 10:00 am por EleKtro H@cker » En línea

MauriH

Desconectado Desconectado

Mensajes: 12


Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #318 en: 14 Octubre 2013, 20:23 pm »


Solo quiero decir una cosa:

Un millón de gracias!!  ;D
Estuve averiguando y al parecer tengo q usar Visual Studio para utilizar los codigos posteados o me equivoco?

Saludos.
« Última modificación: 14 Octubre 2013, 20:25 pm por MauriH » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #319 en: 14 Octubre 2013, 20:47 pm »

Estuve averiguando y al parecer tengo q usar Visual Studio para utilizar los codigos posteados o me equivoco?

Si, estás en lo cierto, tienes que usar VisualStudio,
existen otras IDES como SharpDevelop, MonoDevelop, e incluso puedes programar/compilar C# online desde la página -> CodeRun,
pero en mi opinión como la IDE de Microsoft no hay ninguna que se pueda comparar, aunque si tienes un PC lento quizás prefieras usar sharpdevelop porque VisualStudio consume bastantes recursos del sistema (no se puede ser el mejor sin tener algún inconveniente).

EDITO:
En -> IDEOne y -> CompileOnline puedes compilar código VBNET.

Un saludo!
« Última modificación: 14 Octubre 2013, 21:13 pm por EleKtro H@cker » En línea

Páginas: 1 ... 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 [32] 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 ... 59 Ir Arriba Respuesta Imprimir 

Ir a:  

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