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

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

0 Miembros y 1 Visitante están viendo este tema.

Eleкtro

#130
Una función para devolver una lista con todas las coincidencias de un RegEx:

Código (vbnet) [Seleccionar]
#Region " RegEx Matches To List "

   ' [ RegEx Matches To List Function ]
   '
   ' // By Elektro H@cker
   '
   ' Examples :
   ' Dim str As String = "<span class=""genres""><a href=""http://www.mp3crank.com/genre/alternative"" rel=""tag"">Alternative</a> / <a href=""http://www.mp3crank.com/genre/indie"" rel=""tag"">Indie</a> / <a href=""http://www.mp3crank.com/genre/rock"" rel=""tag"">Rock</a></span>"
   ' For Each match In RegEx_Matches_To_List(str, <a><![CDATA[tag">(\w+)<]]></a>.Value) : MsgBox(match) : Next

   Private Function RegEx_Matches_To_List(ByVal str As String, ByVal RegEx_Pattern As String) As List(Of String)

       Dim match As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(str, RegEx_Pattern)
       Dim Match_List As New List(Of String)

       Do While match.Success
           Match_List.Add(match.Groups(1).ToString)
           match = match.NextMatch()
           Application.DoEvents()
       Loop

       Return Match_List

   End Function

#End Region







Unas cuantas expresiones regulares que he escrito para facilitar algunas taréas:

Código (vbnet) [Seleccionar]
   
   ' Dim str As String = <a><![CDATA[<href="http://www.mp3crank.com/feed"]]></a>.Value
   ' MsgBox(Match_RegEx_MainBase_Url(Str)) ' Result: http://www.mp3crank.com

   Private Function Match_RegEx_MainBase_Url(ByVal str As String) As String

       ' Match criteria:
       '
       ' http://url.domain
       ' https://url.domain
       ' www.url.domain

       Dim RegEx As New System.Text.RegularExpressions.Regex( _
       <a><![CDATA[(http://|https://|www).+\.[0-9A-z]]]></a>.Value)

       Return RegEx.Match(str).Groups(0).ToString
   End Function


Código (vbnet) [Seleccionar]
   
   ' Dim str As String = <a><![CDATA[<href="http://www.mp3crank.com/feed"]]></a>.Value
   ' MsgBox(Match_RegEx_Url(str)) ' Result: http://www.mp3crank.com/feed

   Private Function Match_RegEx_Url(ByVal str As String) As String

       ' Match criteria:
       '
       ' http://url
       ' https://url
       ' www.url

       Dim RegEx As New System.Text.RegularExpressions.Regex( _
       <a><![CDATA[(http://|https://|www).+\b]]></a>.Value)

       Return RegEx.Match(str).Groups(0).ToString
   End Function


Código (vbnet) [Seleccionar]
   
   ' Dim str As String = <a><![CDATA[href="http://www.mp3crank.com/the-rolling-stones/deluxe-edition.htm"]]></a>.Value
   ' MsgBox(Match_RegEx_htm_html(str)) ' Result: http://www.mp3crank.com/the-rolling-stones/deluxe-edition.htm

   Private Function Match_RegEx_htm_html(ByVal str As String) As String

       ' Match criteria:
       '
       ' http://Text.htm
       ' http://Text.html
       ' https://Text.htm
       ' https://Text.html
       ' www.Text.htm
       ' www.Text.html

       Dim RegEx As New System.Text.RegularExpressions.Regex( _
       <a><![CDATA[(http://|https://|www).*\.html?]]></a>.Value)

       Return RegEx.Match(str).Groups(0).ToString
   End Function


Código (vbnet) [Seleccionar]
   
   ' Dim str As String = <a><![CDATA[href=>Drifter - In Search of Something More [EP] (2013)</a>]]></a>.Value
   ' MsgBox(Match_RegEx_Tag(str)) ' Result: Drifter - In Search of Something More [EP] (2013)

   Private Function Match_RegEx_Tag(ByVal str As String) As String

       ' Match criteria:
       '
       ' >..Text..<

       Dim RegEx As New System.Text.RegularExpressions.Regex( _
       <a><![CDATA[>([^<]+?)<]]></a>.Value)

       Return RegEx.Match(str).Groups(1).ToString
   End Function








z3nth10n

Deberías poner mi code para que cambien las imagenes al pasar el mouse...

Tengo otro code, que adapta una imagen al fondo del Form... (Es decir si el form es de 800x600 y la imagen 1024x768 se redimensiona automaticamente)

Un saludo.

Te paso los codes?  ;)

Interesados hablad por Discord.

Eleкtro

#132
Cita de: Seazoux en 31 Mayo 2013, 15:08 PMDeberías poner mi code para que cambien las imagenes al pasar el mouse...

Puedes colaborar publicando tus códigos aquí, yo publico solo lo mio, o lo que encuentro por ahí en zonas prohibidas de la red xD.
Eres libre de publicar aquí tus snippets.

Cita de: Seazoux en 31 Mayo 2013, 15:08 PMTengo otro code, que adapta una imagen al fondo del Form... (Es decir si el form es de 800x600 y la imagen 1024x768 se redimensiona automaticamente)

Miedo me da ese código, no sé si querrás publicar eso, te lo digo más que nada porque no le veo sentido ni utilidad cuando existe una propiedad para redimensionar la imágen:
Me.BackgroundImageLayout = ImageLayout.Stretch

Saludos!








z3nth10n

Cita de: EleKtro H@cker en 31 Mayo 2013, 16:26 PM
Miedo me da ese código, no sé si querrás publicar eso, te lo digo más que nada porque no le veo sentido ni utilidad cuando existe una propiedad para redimensionar la imágen:
Me.BackgroundImageLayout = ImageLayout.Stretch

Seriusly? xD Y yo buscando como un negro 20000 código por Interné...

Interesados hablad por Discord.

Eleкtro

#134
Cita de: Seazoux en 31 Mayo 2013, 16:28 PMSeriusly? xD Y yo buscando como un negro 20000 código por Interné...

Claro, si alguna vez me hicieras caso y leyeras el nombre y la descripción de cada propiedad, ni 3 minutos lleva mirarse las propiedades de un Form, aparte de aprender un poco más no perderías tiempo buscando códigos tontos.
...Pero lo que me hace gracia es que alguien haya gastado tiempo escribiendo ese código que comentas, me imagino que también lo habrá escrito sin saber que existia dicha propiedad, el colmo xD.

En fín, publica lo que quieras de todas formas he?, pa eso está esta sección.

saludos








z3nth10n

#135
Pos yasta aquí están los codes  :rolleyes:

Cambiar imagen al pasar el Mouse en VB.NET (Google indexando) :laugh:

Cita de: Seazoux
Código (vbnet) [Seleccionar]
   Private Sub picMini_MouseEnter(sender As Object, e As EventArgs) Handles picMini.MouseEnter
       sender.Image = Mini_Off
   End Sub

   Private Sub picMini_MouseLeave(sender As Object, e As EventArgs) Handles picMini.MouseLeave
       sender.Image = Mini_On
   End Sub


Código (vbnet) [Seleccionar]
   Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       picMini.Image = Mini_On 'Aqui se carga la que se va a mostrar por defecto
       picMini.BackColor = Color.Transparent 'Por si tiene transparencias la imagen


Código (vbnet) [Seleccionar]
   Dim Mini_Off As Image = Image.FromFile(".\Art\Buttons\Mini_Off.png")
   Dim Mini_On As Image = Image.FromFile(".\Art\Buttons\Mini_On.png")


Adaptar imagen de Fondo al Form VB.NET (Para los que seáis unos negros y no sepáis las propiedades un Form como yo :laugh: :laugh: )

Código (vbnet) [Seleccionar]
       
   Dim Fondo As Image = Image.FromFile(".\Art\fondo.jpg")

       Dim ancho As String = Me.Width
       Dim alto As String = Me.Height

Dim bm_source As Bitmap = New Bitmap(Fondo)
       Dim bm_dest As New Bitmap(CInt(ancho), CInt(alto))
       Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)  
       gr_dest.DrawImage(bm_source, 0, 0, bm_dest.Width + 1, bm_dest.Height + 1)
       Me.BackgroundImage = bm_dest


Un saludo.  ;D

Interesados hablad por Discord.

Eleкtro

[FastColoredTextBox] Scroll Text

Scrollea hasta el final del texto y posiciona el cursor del teclado en el último caracter.

PD: Se requiere el control extendido FastColoredTextbox.



Código (vbnet) [Seleccionar]
#Region " [FastColoredTextBox] Scroll Text "

    ' FastColoredTextBox] Scroll Text
    '
    ' // By Elektro H@cker

    Private Sub FastColoredTextBox1_TextChanged(sender As Object, e As FastColoredTextBoxNS.TextChangedEventArgs) _
        Handles FastColoredTextBox1.TextChangedDelayed

        sender.ScrollLeft()
        sender.Navigate(sender.Lines.Count - 1) ' Scroll to down
        sender.SelectionStart = sender.Text.Length ' Set the keyboard cursor position

    End Sub

#End Region








Eleкtro

Convierte código Hexadecimal a número Win32Hex

Código (vbnet) [Seleccionar]

#Region " Hex To Win32Hex "

   ' [ Hex To Win32Hex Function ]
   '
   ' // By Elektro H@cker
   '
   ' Examples:
   ' MsgBox(Hex_To_Win32Hex("FF4"))   ' Result: &HFF4
   ' MsgBox(Hex_To_Win32Hex("0xFF4")) ' Result: &HFF4
   ' Dim Number As Int32 = Hex_To_Win32Hex("0xFF4") ' Result: 4084

   Private Function Hex_To_Win32Hex(ByVal Hex As String) As String
       If Hex.ToLower.StartsWith("0x") Then Hex = Hex.Substring(2, Hex.Length - 2)
       Return "&H" & Hex
   End Function

#End Region








Eleкtro

- Detect mouse wheel direction.

Comprueba en que dirección se movió la rueda del mouse.

Código (vbnet) [Seleccionar]
   Private Sub Form_MouseWheel(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseWheel

       Select Case Math.Sign(e.Delta)
           Case Is < 0
               MsgBox("MouseWheel Down")
           Case Is > 0
               MsgBox("MouseWheel Up")
       End Select

   End Sub







Comprueba en que dirección se movió la rueda del mouse.
...Lo mismo que antes pero usando los mensajes de Windows:


Código (vbnet) [Seleccionar]
   Public Shared Mouse_Have_Wheel As Boolean = My.Computer.Mouse.WheelExists

   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Application.AddMessageFilter(New MouseWheelMessageFilter())
   End Sub

   Public Class MouseWheelMessageFilter
       Implements IMessageFilter

       Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage

           If Mouse_Have_Wheel Then

               If m.Msg = &H20A Then

                   If Form.ActiveForm IsNot Nothing Then

                       Try ' "Try" solves too fast wheeling.

                           Dim delta As Integer = m.WParam.ToInt32() >> 16

                           If delta > 0 Then
                               MsgBox("MouseWheel Up")
                           Else
                               MsgBox("MouseWheel Down")
                           End If

                       Catch : End Try

                   End If

                   Return True
               End If

           End If

           Return False

       End Function

   End Class







Ejemplo de como modificar la fuente de texto actual de un control:

Código (vbnet) [Seleccionar]
Me.Font = New Font("Lucida Console", 16, FontStyle.Regular, GraphicsUnit.Point)








z3nth10n

Anda esto me viene bien para mi topic de scroll de imagenes, que casualidad  ;-) :laugh:

Interesados hablad por Discord.