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

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)
0 Usuarios y 2 Visitantes están viendo este tema.
Páginas: 1 2 3 4 5 [6] 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... 58 Ir Abajo Respuesta Imprimir
Autor Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)  (Leído 480,134 veces)
arts

Desconectado Desconectado

Mensajes: 103


Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #50 en: 18 Marzo 2013, 12:33 pm »

Checkar si un número está entre un rango de números.

PD: Si conocen un método mejor porfavor postéenlo

Código
  1. #Region " Number Is In Range Function "
  2.  
  3.    ' [ Number Is In Range Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(NumberIsInRange(50, 0, 100))
  9.    ' If NumberIsInRange(5, 1, 10) then...
  10.  
  11.    Private Function NumberIsInRange(ByVal Number As Integer, ByVal MIN As Integer, ByVal MAX As Integer) As Boolean
  12.        Select Case Number
  13.            Case MIN To MAX : Return True
  14.            Case Else : Return False
  15.        End Select
  16.    End Function
  17.  
  18. #End Region


A mi se me ocurre otra manera pero no tengo ni idea de cual es más rápida.
Código
  1. Function numero(ByVal MIN As Integer, ByVal MAX As Integer) As Boolean
  2.        Dim N As Integer
  3.        N = InputBox("Escribe un nº cualquiera", "hola", 0)
  4.  
  5.        If N >= MIN And N <= MAX Then
  6.            MsgBox("EL NUMERO SE ENCUENTRA ENTRE " & MIN & " Y " & MAX)
  7.        Else
  8.            MsgBox("EL NUMERO NO SE ENCUENTRA ENTRE LOS VALORES")
  9.        End If
  10.    End Function


En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #51 en: 19 Marzo 2013, 15:32 pm »

@arts
la verdad es que según tengo entendido entre las comprbocaciones de IF y Select Case no hay diferencia así que creo que deben ser igual.




Generador de captchas.





Código
  1. #Region " Captcha Generator Function "
  2.  
  3.    ' [ Captcha Generator Function ]
  4.    '
  5.    ' Instructions:
  6.    ' Copy the Captcha Class into a new Class "Captcha.vb"
  7.    '
  8.    ' Examples :
  9.    ' Dim myCaptcha As New Captcha
  10.    ' PictureBox1.Image = myCaptcha.GenerateCaptcha(5) ' Generate a captcha of 5 letters
  11.    ' MsgBox(myCaptcha.Check(TextBox1.Text, True)) ' Check if the given text is correct
  12.  
  13.  
  14.    ' Captcha.vb
  15. #Region " Captcha Class "
  16.  
  17.    Imports System.Drawing
  18.    Imports System.Drawing.Drawing2D
  19.  
  20.    Public Class Captcha
  21.  
  22.        Dim cap As String
  23.  
  24.        Public ReadOnly Property CaptchaString As String
  25.            Get
  26.                Return cap
  27.            End Get
  28.        End Property
  29.  
  30.        ' Generate Captcha
  31.        Function GenerateCaptcha(ByVal NumberOfCharacters As Integer) As Bitmap
  32.            Dim R As New Random
  33.            Dim VerticalLineSpaceing As Integer = R.Next(5, 10) ' The space between each horizontal line
  34.            Dim HorisontalLineSpaceing As Integer = R.Next(5, 10) ' The space between each Vertical line
  35.            Dim CWidth As Integer = (NumberOfCharacters * 120) 'Generating the width
  36.            Dim CHeight As Integer = 180 ' the height
  37.            Dim CAPTCHA As New Bitmap(CWidth, CHeight)
  38.            Dim allowedCharacters() As Char = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM123456789".ToCharArray 'Guess
  39.            Dim str(NumberOfCharacters - 1) As Char ' The String to turn into a captcha
  40.  
  41.            For i = 0 To NumberOfCharacters - 1
  42.                str(i) = allowedCharacters(R.Next(0, 61)) ' Generating random characters
  43.            Next
  44.  
  45.            Using g As Graphics = Graphics.FromImage(CAPTCHA)
  46.  
  47.                ' the gradient brush for the background
  48.                Dim gradient As New Drawing2D.LinearGradientBrush(New Point(0, CInt(CHeight / 2)), New Point(CWidth, CInt(CHeight / 2)), Drawing.Color.FromArgb(R.Next(&HFF7D7D7D, &HFFFFFFFF)), Drawing.Color.FromArgb(R.Next(&HFF7D7D7D, &HFFFFFFFF)))
  49.  
  50.                g.FillRectangle(gradient, New Rectangle(0, 0, CWidth, CHeight))
  51.                Dim plist As New List(Of Point) ' the list of points the curve goes through
  52.  
  53.                For i = 0 To str.Length - 1
  54.                    Dim FHeight As Integer = R.Next(60, 100) 'Font height in EM
  55.                    Dim Font As New Font("Arial", FHeight)
  56.                    Dim Y As Integer = R.Next(0, (CHeight - FHeight) - 40) 'Generating the Y value of a char: will be between the top  and (bottom - 40) to prevent half characters
  57.                    Dim X As Integer = CInt((((i * CWidth) - 10) / NumberOfCharacters))  'Some formula that made sense At the time that I typed it to generate the X value
  58.                    Dim p As New Point(X, Y)
  59.  
  60.                    g.DrawString(str(i).ToString, Font, Brushes.Black, p)
  61.  
  62.                    plist.Add(New Point(X, R.Next(CInt((CHeight / 2) - 40), CInt((CHeight / 2) + 40)))) ' add the points to the array
  63.                Next
  64.  
  65.                plist.Add(New Point(CWidth, CInt(CHeight / 2))) 'for some reason it doesn't go to the end so we manually add the last point
  66.                Dim ppen As New Pen(Brushes.Black, R.Next(5, 10)) ' the pen used to draw the curve
  67.                g.DrawCurve(ppen, plist.ToArray)
  68.                Dim pen As New Pen(Brushes.SteelBlue, CSng(R.Next(1, 2))) 'the pen that will draw the horisontal and vertical lines.
  69.  
  70.                ' Drawing the vertical lines
  71.                For i = 1 To CWidth
  72.                    Dim ptop As New Point(i * VerticalLineSpaceing, 0)
  73.                    Dim pBottom As New Point(i * VerticalLineSpaceing, CHeight)
  74.                    g.DrawLine(pen, ptop, pBottom)
  75.                Next
  76.  
  77.                ' Drawing the horizontal lines
  78.                For i = 1 To CHeight
  79.                    Dim ptop As New Point(0, i * HorisontalLineSpaceing)
  80.                    Dim pBottom As New Point(CWidth, i * HorisontalLineSpaceing)
  81.                    g.DrawLine(pen, ptop, pBottom)
  82.                Next
  83.  
  84.                ' Drawing the Black noise particles
  85.                Dim numnoise As Integer = CInt(CWidth * CHeight / 25) 'calculating the  number of noise for the block. This will generate 1 Noise per 25X25 block of pixels if im correct
  86.  
  87.                For i = 1 To numnoise / 2
  88.                    Dim X As Integer = R.Next(0, CWidth)
  89.                    Dim Y As Integer = R.Next(0, CHeight)
  90.                    Dim int As Integer = R.Next(1, 2)
  91.                    g.FillEllipse(Brushes.Black, New Rectangle(X, Y, R.Next(2, 5), R.Next(2, 5))) 'Size of the white noise
  92.                Next
  93.  
  94.                ' Drawing the white noise particles
  95.                For i = 1 To numnoise / 2
  96.                    Dim X As Integer = R.Next(0, CWidth)
  97.                    Dim Y As Integer = R.Next(0, CHeight)
  98.                    Dim int As Integer = R.Next(1, 2)
  99.                    g.FillEllipse(Brushes.White, New Rectangle(X, Y, R.Next(2, 5), R.Next(2, 5))) 'Size of the white noise
  100.                Next
  101.  
  102.            End Using
  103.  
  104.            cap = str
  105.            Return CAPTCHA
  106.        End Function
  107.  
  108.        ' Check captcha
  109.        Function Check(ByVal captcha As String, Optional ByVal IgnoreCase As Boolean = False) As Boolean
  110.            If IgnoreCase Then
  111.                If captcha.ToLower = CaptchaString.ToLower Then
  112.                    Return True
  113.                Else
  114.                    Return False
  115.                End If
  116.            Else
  117.                If captcha = CaptchaString Then
  118.                    Return True
  119.                Else
  120.                    Return False
  121.                End If
  122.            End If
  123.        End Function
  124.  
  125.    End Class
  126.  
  127. #End Region
  128.  
  129. #End Region


En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #52 en: 19 Marzo 2013, 17:34 pm »

Código:
Minimizar la IDE del VisualStudio cuando la APP está en debug:

[code=vbnet]#Region " Minimize VS IDE when APP is in execution "

    Declare Function ShowWindow Lib "User32.dll" (ByVal hwnd As IntPtr, ByVal nCmdShow As UInteger) As Boolean

    ' Minimize VS IDE when APP is in execution
    Private Sub Minimize_VS_IDE_when_APP_is_in_execution(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
#If DEBUG Then
        Dim Pr() As Process = Process.GetProcesses
        For Each P As Process In Pr
            If P.MainWindowTitle.Contains(My.Application.Info.AssemblyName) Then
                Dim hwnd As IntPtr = P.MainWindowHandle
                ShowWindow(hwnd, 6)
                Exit For
            End If
        Next
#End If
    End Sub

#End Region



Redondear los bordes de cualquier control:

Código
  1. #Region " Round Borders "
  2.  
  3.    ' [ Round Borders ]
  4.    '
  5.    ' Examples :
  6.    ' Round_Border(TextBox1)
  7.    ' Round_Border(PictureBox1, 100)
  8.  
  9.    Private Sub Round_Borders(ByVal vbObject As Object, Optional ByVal RoundSize As Integer = 20)
  10.        Try
  11.            Dim p As New Drawing2D.GraphicsPath()
  12.            p.StartFigure()
  13.            p.AddArc(New Rectangle(0, 0, RoundSize, RoundSize), 180, 90)
  14.            p.AddLine(RoundSize, 0, vbObject.Width - RoundSize, 0)
  15.            p.AddArc(New Rectangle(vbObject.Width - RoundSize, 0, RoundSize, RoundSize), -90, 90)
  16.            p.AddLine(vbObject.Width, RoundSize, vbObject.Width, vbObject.Height - RoundSize)
  17.            p.AddArc(New Rectangle(vbObject.Width - RoundSize, vbObject.Height - RoundSize, RoundSize, RoundSize), 0, 90)
  18.            p.AddLine(vbObject.Width - RoundSize, vbObject.Height, RoundSize, vbObject.Height)
  19.            p.AddArc(New Rectangle(0, vbObject.Height - RoundSize, RoundSize, RoundSize), 90, 90)
  20.            p.CloseFigure()
  21.            vbObject.Region = New Region(p)
  22.        Catch ex As Exception : Throw New Exception(ex.Message)
  23.        End Try
  24.    End Sub
  25.  
  26. #End Region



Decodificar URL:

Código
  1. #Region " URL Decode Function "
  2.  
  3.    ' [ URL Decode Function ]
  4.    '
  5.    ' Examples :
  6.    ' Dim URL As String = URL_Decode("http%3A%2F%2Fwww%2Esomesite%2Ecom%2Fpage%2Easp%3Fid%3D5%26test%3DHello+World")
  7.  
  8.    Public Function URL_Decode(ByVal Source As String) As String
  9.        Dim x As Integer = 0
  10.        Dim CharVal As Byte = 0
  11.        Dim sb As New System.Text.StringBuilder()
  12.        For x = 0 To (Source.Length - 1)
  13.            Dim c As Char = Source(x)
  14.            If (c = "+") Then
  15.                sb.Append(" ")
  16.            ElseIf c <> "%" Then
  17.                sb.Append(c)
  18.            Else
  19.                CharVal = Int("&H" & Source(x + 1) & Source(x + 2))
  20.                sb.Append(Chr(CharVal))
  21.                x += 2
  22.            End If
  23.        Next
  24.        Return sb.ToString()
  25.    End Function
  26.  
  27. #End Region



Codificar URL:

Código
  1. #Region " URL Encode Function "
  2.  
  3.    ' [ URL Encode Function ]
  4.    '
  5.    ' Examples :
  6.    ' Dim URL As String = URL_Encode("http://www.somesite.com/page.asp?id=5&test=Hello World")
  7.  
  8.    Public Function URL_Encode(ByVal Source As String) As String
  9.        Dim chars() As Char = Source.ToCharArray()
  10.        Dim sb As New System.Text.StringBuilder()
  11.        For Each c As Char In chars
  12.            If c Like "[A-Z-a-z-0-9]" Then
  13.                sb.Append(c)
  14.            ElseIf c = " " Then
  15.                sb.Append("+")
  16.            Else
  17.                Dim sHex As String = Hex(Asc(c))
  18.                sHex = "%" & sHex.PadLeft(2, "0")
  19.                sb.Append(sHex)
  20.            End If
  21.        Next
  22.        Erase chars ' Clean Up
  23.        Return sb.ToString()
  24.    End Function
  25.  
  26. #End Region

[/code]
« Última modificación: 10 Abril 2013, 13:17 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #53 en: 19 Marzo 2013, 18:52 pm »

Grabar audio del PC:

Código
  1. #Region " Rec Sound Function "
  2.  
  3.    ' [ Rec Sound Function ]
  4.    '
  5.    ' Examples :
  6.    ' Rec_Sound("C:\Audio.wav", Rec.Start_Record)
  7.    ' Rec_Sound("C:\Audio.wav", Rec.Stop_Record)
  8.  
  9.    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
  10.  
  11.    Public Enum Rec
  12.        Start_Record
  13.        Stop_Record
  14.    End Enum
  15.  
  16.    Private Function Rec_Sound(ByVal Path As String, ByVal Rec As Rec) As Boolean
  17.        Select Case Rec
  18.            Case Rec.Start_Record
  19.                mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
  20.                mciSendString("record recsound", "", 0, 0)
  21.                Return True
  22.            Case Rec.Stop_Record
  23.                mciSendString("save recsound " & Path & "", "", 0, 0)
  24.                mciSendString("close recsound", "", 0, 0)
  25.                Return True
  26.            Case Else : Return Nothing
  27.        End Select
  28.    End Function
  29.  
  30. #End Region
En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #54 en: 19 Marzo 2013, 20:57 pm »

Esta función es para escribir "hints" (o "cues") en los TextBox por ejemplo.

Código
  1. #Region " Set Control Hint Function "
  2.  
  3.    ' [ Set Control Hint Function ]
  4.    '
  5.    ' Examples :
  6.    ' Set_Control_Hint(TextBox1, "Put text here...")
  7.  
  8.    <System.Runtime.InteropServices.DllImport("user32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
  9.    Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
  10.    End Function
  11.  
  12.    Private Function Set_Control_Hint(ByVal control As Control, ByVal text As String) As Boolean
  13.        Try
  14.            SendMessage(control.Handle, &H1501, 0, text)
  15.            Return True
  16.        Catch ex As Exception
  17.            Throw New Exception(ex.Message)
  18.        End Try
  19.    End Function
  20.  
  21. #End Region



Enviar POST por PHP:

Código
  1. #Region " Send POST PHP Function "
  2.  
  3.    ' [ Send POST PHP Function ]
  4.    '
  5.    ' Examples :
  6.    ' Dim htmlcode As String = PHP("http://somesite.com/somephpfile.php", "POST", "name=Jim&age=27&pizza=suasage")
  7.  
  8.    Public Function Send_POST_PHP(ByVal URL As String, ByVal Method As String, ByVal Data As String) As String
  9.        Try
  10.            Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(URL)
  11.            request.Method = Method
  12.            Dim postData = Data
  13.            Dim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes(postData)
  14.            request.ContentType = "application/x-www-form-urlencoded"
  15.            request.ContentLength = byteArray.Length
  16.            Dim dataStream As System.IO.Stream = request.GetRequestStream()
  17.            dataStream.Write(byteArray, 0, byteArray.Length)
  18.            dataStream.Close()
  19.            Dim response As System.Net.WebResponse = request.GetResponse()
  20.            dataStream = response.GetResponseStream()
  21.            Dim reader As New System.IO.StreamReader(dataStream)
  22.            Dim responseFromServer As String = reader.ReadToEnd()
  23.            reader.Close()
  24.            dataStream.Close()
  25.            response.Close()
  26.            Return (responseFromServer)
  27.        Catch ex As Exception
  28.            Dim PHP_Error As String = ErrorToString()
  29.            If PHP_Error = "Invalid URI: The format of the URI could not be determined." Then
  30.                MsgBox("ERROR! Must have HTTP:// before the URL.")
  31.            Else
  32.                Throw New Exception(ex.Message)
  33.            End If
  34.            Return ("ERROR")
  35.        End Try
  36.    End Function
  37.  
  38. #End Region
En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #55 en: 22 Marzo 2013, 13:07 pm »

FTP Uploader:

Código
  1. #Region " FTP Upload Function "
  2.  
  3.    ' [ FTP Upload Function ]
  4.    '
  5.    ' Examples :
  6.    ' FTP_Upload("C:\File.txt", "ftp://127.0.0.1/File.txt", "User")
  7.    ' MsgBox(FTP_Upload("C:\File.txt", "ftp://127.0.0.1/File.txt", "User", "Pass"))
  8.  
  9.    Public Function FTP_Upload(ByVal FilePath As String, ByVal FTP_FilePath As String, _
  10.                    Optional ByVal User As String = Nothing, _
  11.                    Optional ByVal Pass As String = Nothing) As Boolean
  12.  
  13.        Dim FTP_request As System.Net.FtpWebRequest
  14.        Dim FTP_stream As System.IO.Stream
  15.        Dim FTP_bytes() As Byte
  16.  
  17.        Try
  18.            FTP_request = DirectCast(System.Net.WebRequest.Create(FTP_FilePath), System.Net.FtpWebRequest)
  19.            FTP_request.Credentials = New System.Net.NetworkCredential(User, Pass)
  20.            FTP_request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
  21.            FTP_stream = FTP_request.GetRequestStream()
  22.            FTP_bytes = System.IO.File.ReadAllBytes(FilePath)
  23.  
  24.            With FTP_stream
  25.                .Write(FTP_bytes, 0, FTP_bytes.Length)
  26.                .Close()
  27.                .Dispose()
  28.            End With
  29.  
  30.            Return True
  31.  
  32.        Catch ex As Exception : Return False
  33.        End Try
  34.  
  35.    End Function
  36.  
  37. #End Region
En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #56 en: 23 Marzo 2013, 15:50 pm »

¡ PACK DE SNIPPETS ACTUALIZADO EN EL POST PRINCIPAL !

Ya puedes descargar la colección completa de 178 funciones útiles.

PD: Y no te olvides de ser generoso compartiendo tu conocimiento con los demás en este post...
En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #57 en: 23 Marzo 2013, 23:45 pm »

Copiar un archivo con posibilidad de cancelar la operación y reemplazar:

Código
  1. #Region " Copy File In Chunks "
  2.  
  3.    ' [ Copy File In Chunks Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Copy_File_In_Chunks("C:\BigFile.mkv", "C:\BigFile_copy.mkv")
  9.    ' Copy_File_In_Chunks("C:\BigFile.mkv", "C:\BigFile_copy.mkv", 9999, True, True)
  10.  
  11.    Dim Cancel_Copy As Boolean = False
  12.  
  13.    Public Function Copy_File_In_Chunks(ByVal InputFile As String, ByVal OutputFile As String, _
  14.                                        Optional ByVal BufferSize As Int16 = 1024, _
  15.                                        Optional ByVal Overwrite As Boolean = False, _
  16.                                        Optional ByVal DeleteFileOnCancel As Boolean = False) As Boolean
  17.  
  18.        Dim InputStream As New IO.FileStream(InputFile, IO.FileMode.Open, IO.FileAccess.Read)
  19.        Dim OutputStream As IO.FileStream
  20.  
  21.        If Overwrite Then
  22.            OutputStream = New IO.FileStream(OutputFile, IO.FileMode.Create, IO.FileAccess.Write)
  23.        Else
  24.            OutputStream = New IO.FileStream(OutputFile, IO.FileMode.CreateNew, IO.FileAccess.Write)
  25.        End If
  26.  
  27.        Dim Buffer = New Byte(BufferSize) {}
  28.        Dim BytesRead As Integer = 0
  29.  
  30.        Do : If Cancel_Copy Then : GoTo Close_Copy
  31.            Else
  32.                Application.DoEvents() ' Remove it if you don't like...
  33.                BytesRead = InputStream.Read(Buffer, 0, Buffer.Length)
  34.                If BytesRead > 0 Then OutputStream.Write(Buffer, 0, BytesRead)
  35.            End If
  36.        Loop While (BytesRead > 0)
  37.  
  38. Close_Copy:
  39.  
  40.        OutputStream.Flush() : InputStream.Close() : OutputStream.Close()
  41.  
  42.        If DeleteFileOnCancel Then
  43.            Try : IO.File.Delete(OutputFile) : Catch : End Try
  44.            Return False
  45.        Else : Return True
  46.        End If
  47.  
  48.    End Function
  49.  
  50. #End Region
« Última modificación: 23 Marzo 2013, 23:55 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



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

Form Docking

Junta un form secundario al borde del form principal (para que se muevan sincronizádamente...)

Código
  1.    Public Moving_From_Secondary_Form As Boolean = False
  2.  
  3.    ' Move Event Main Form
  4.    Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Move
  5.        If Not Moving_From_Secondary_Form Then Form2.Location = New Point(Me.Right, Me.Top)
  6.    End Sub
  7.  
  8.    ' Move Event Secondary Form
  9.    Private Sub Form2_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Move
  10.        Form1.Moving_From_Secondary_Form = True
  11.        Form1.Location = New Point(Me.Left - Form1.Width, Me.Top)
  12.        Form1.Moving_From_Secondary_Form = False
  13.    End Sub
En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #59 en: 8 Abril 2013, 08:43 am »

· Unir argumentos:

Código
  1. #Region " Join Arguments Function "
  2.  
  3.    ' [ Join Arguments Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Join_Arguments())
  9.    ' MsgBox(Join_Arguments(";"))
  10.    ' If Join_Arguments() Is Nothing Then MsgBox("No arguments")
  11.  
  12.    Private Function Join_Arguments(Optional Delimiter As String = " ") As String
  13.  
  14.        ' Check if exist at least one argument
  15.        If Environment.GetCommandLineArgs().Length = 1 Then Return Nothing
  16.  
  17.        ' Store all arguments
  18.        Dim Arguments As [String]() = Environment.GetCommandLineArgs()
  19.  
  20.        ' Delete Argument 0 (It's the name of the APP)
  21.        For x = 1 To UBound(Arguments) : Arguments(x - 1) = Arguments(x) : Next x
  22.  
  23.        ' Redimensione the array
  24.        ReDim Preserve Arguments(UBound(Arguments) - 1)
  25.  
  26.        ' Return the string
  27.        Return [String].Join(Delimiter, Arguments)
  28.  
  29.    End Function
  30.  
  31. #End Region





· Ignorar excepciones:

Código
  1. #Region " Ignore Exceptions "
  2.  
  3.    ' [ Ignore Exceptions ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  9.    '   IO.File.OpenText("X:\Failed_To_Open.txt")
  10.    ' End Sub
  11.  
  12.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  13.        Try : AddHandler Application.ThreadException, AddressOf Application_Exception_Handler _
  14.            : Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, False) _
  15.            : Catch : End Try
  16.    End Sub
  17.  
  18.    Private Sub Application_Exception_Handler(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
  19.        ' Here you can manage the exceptions:
  20.        ' Dim ex As Exception = CType(e.Exception, Exception)
  21.        ' MsgBox(ex.Message)
  22.        ' ...Or leave empty to ignore it.
  23.    End Sub
  24.  
  25. #End Region





· Devuelve el nombre de la aplicación actual:

EDITO: Mejorado

Código
  1. #Region " Get Current APP Name Function "
  2.  
  3.    ' [ Get Current APP Name Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Get_Current_APP_Name())
  9.    ' MsgBox(Get_Current_APP_Name(False))
  10.  
  11.    Private Function Get_Current_APP_Name(Optional ByVal WithFileExtension As Boolean = True) As String
  12.        Dim EXE_Filename As String = System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName
  13.  
  14.        If WithFileExtension Then : Return EXE_Filename
  15.        Else : Return EXE_Filename.Substring(0, EXE_Filename.Length - 4)
  16.        End If
  17.  
  18.    End Function
  19.  
  20. #End Region





· Devuelve la ruta parcial o la ruta absoluta de la aplicación actual:

EDITO: SIMPLIFICADO

Código
  1. #Region " Get Current APP Path Function "
  2.  
  3.    ' [ Get Current APP Path Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Get_Current_APP_Path())
  9.    ' MsgBox(Get_Current_APP_Path(True))
  10.  
  11.    Private Function Get_Current_APP_Path(Optional ByVal FullPath As Boolean = False) As String
  12.        If FullPath Then : Return CurDir() & "\" & System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName
  13.        Else : Return CurDir()
  14.        End If
  15.    End Function
  16.  
  17. #End Region





· Sleep

Código
  1. #Region " Sleep "
  2.  
  3.    ' [ Sleep ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Sleep(5) : MsgBox("Test")
  9.    ' Sleep(5, Measure.Seconds) : MsgBox("Test")
  10.  
  11.    Public Enum Measure
  12.        Milliseconds = 1
  13.        Seconds = 2
  14.        Minutes = 3
  15.        Hours = 4
  16.    End Enum
  17.  
  18.    Private Sub Sleep(ByVal Duration As Int64, Optional ByVal Measure As Measure = Measure.Seconds)
  19.  
  20.        Dim Starttime = DateTime.Now
  21.  
  22.        Select Case Measure
  23.            Case Measure.Milliseconds : Do While (DateTime.Now - Starttime).TotalMilliseconds < Duration : Application.DoEvents() : Loop
  24.            Case Measure.Seconds : Do While (DateTime.Now - Starttime).TotalSeconds < Duration : Application.DoEvents() : Loop
  25.            Case Measure.Minutes : Do While (DateTime.Now - Starttime).TotalMinutes < Duration : Application.DoEvents() : Loop
  26.            Case Measure.Hours : Do While (DateTime.Now - Starttime).TotalHours < Duration : Application.DoEvents() : Loop
  27.            Case Else
  28.        End Select
  29.  
  30.    End Sub
  31.  
  32. #End Region





· Devuelve un color RGB aleatorio:

Código
  1. #Region " Get Random RGB Color Function "
  2.  
  3.    ' [ Get Random RGB Color Function ]
  4.    '
  5.    ' Examples :
  6.    ' Label1.ForeColor = Get_Random_RGB_Color()
  7.  
  8.    Private Function Get_Random_RGB_Color() As Color
  9.        Return Color.FromArgb(255, _
  10.            m_Rnd.Next(0, 255), _
  11.            m_Rnd.Next(0, 255), _
  12.            m_Rnd.Next(0, 255))
  13.    End Function
  14.  
  15. #End Region





· Devuelve un color QB aleatorio:
http://msdn.microsoft.com/en-us/library/d2dz8078%28v=vs.80%29.aspx

Código
  1. #Region " Get Random QB Color Function "
  2.  
  3.    ' [ Get Random QB Color Function ]
  4.    '
  5.    ' Examples :
  6.    ' Label1.ForeColor = Get_Random_QB_Color()
  7.  
  8.    Private QB_Random As New Random
  9.    Public Function Get_Random_QB_Color() As Color
  10.        Return Color.FromArgb(QBColor(QB_Random.Next(0, 15)) + &HFF000000)
  11.    End Function
  12.  
  13. #End Region
« Última modificación: 10 Abril 2013, 10:44 am por EleKtro H@cker » En línea

Páginas: 1 2 3 4 5 [6] 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... 58 Ir Arriba Respuesta Imprimir 

Ir a:  

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