Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúNamespace ListBoxExtensions
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Contains custom extension methods to use with <see cref="ListBox"/> control.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
<HideModuleName>
Public Module ListBoxExtensions
#Region " Public Extension Methods "
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Removes items of the specified type in the source <see cref="ListBox"/> given a condition.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <typeparam name="T">
''' The <see cref="Type"/> of items to remove.
''' </typeparam>
'''
''' <param name="sender">
''' The source <see cref="ListBox"/>.
''' </param>
'''
''' <param name="predicate">
''' A <see cref="Func(Of T, Boolean)"/> function to test each element for a condition.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
<Extension>
<EditorBrowsable(EditorBrowsableState.Always)>
Public Sub RemoveItems(Of T)(ByVal sender As ListBox, ByVal predicate As Func(Of T, Boolean))
Dim collection As ListBox.ObjectCollection = sender.Items
Dim indices As New Stack(Of Integer)
For index As Integer = 0 To (collection.Count - 1)
Dim obj As Object = collection(index)
If (TypeOf obj Is T) AndAlso (predicate.Invoke(DirectCast(obj, T))) Then
indices.Push(index)
End If
Next index
sender.BeginUpdate()
sender.SelectedIndex = -1
Do While (indices.Any())
collection.RemoveAt(indices.Pop())
Loop
sender.EndUpdate()
collection = Nothing
indices = Nothing
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Removes any empty string items (<see cref="String.Empty"/>) in the source <see cref="ListBox"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="sender">
''' The source <see cref="ListBox"/>.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
<Extension>
<EditorBrowsable(EditorBrowsableState.Always)>
Public Sub RemoveEmptyStrings(ByVal sender As ListBox)
Dim predicate As Func(Of String, Boolean) =
Function(str As String) As Boolean
Return String.IsNullOrEmpty(str)
End Function
ListBoxExtensions.RemoveItems(Of String)(sender, predicate)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Removes any empty string items (<see cref="String.Empty"/>)
''' and also string items that consists only of white-space characters in the source <see cref="ListBox"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="sender">
''' The source <see cref="ListBox"/>.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
<Extension>
<EditorBrowsable(EditorBrowsableState.Always)>
Public Sub RemoveEmptyOrWhiteSpaceStrings(ByVal sender As ListBox)
Dim predicate As Func(Of String, Boolean) =
Function(str As String) As Boolean
Return String.IsNullOrWhiteSpace(str)
End Function
ListBoxExtensions.RemoveItems(Of String)(sender, predicate)
End Sub
#End Region
End Module
End Namespace
Me.ListBox1.Items.AddRange({"1", "2", "3", "", String.Empty, "4", "5"})
ListBoxExtensions.RemoveEmptyStrings(Me.ListBox1)
Me.ListBox1.Items.AddRange({"1", "2", "3", "", String.Empty, " ", "4", "5"})
ListBoxExtensions.RemoveEmptyOrWhiteSpaceStrings(Me.ListBox1)
Me.ListBox1.Items.AddRange({Color.Red, Color.Green, Color.Blue})
Dim predicate As Func(Of Color, Boolean) =
Function(c As Color) (c = Color.Green)
ListBoxExtensions.RemoveItems(Of Color)(Me.ListBox1, predicate)
Imports Namespace_Principal.ListBoxExtensions
...
Dim lb As ListBox = Me.ListBox1
lb.RemoveEmptyStrings()
lb.RemoveEmptyOrWhiteSpaceStrings()
lb.RemoveItems(Of Type)(Predicate)
Public Class TestClass
Private Sub Metodo()
Dim lb As ListBox = Me.ListBox1
lb.Items.AddRange({Color.Red, Color.Green, Color.Blue})
ListBoxExtensions.RemoveItems(Of Color)(lb, AddressOf Me.ColorPredicate)
End Sub
Private Function ColorPredicate(ByVal c As Color) As Boolean
Select Case c
Case Color.Green
Return True
Case Else
Return False
End Select
End Function
End Class
Cita de: **Aincrad** en 22 Marzo 2018, 19:17 PM
@Elektro el link del File 2 startup v1.1 esta caido .
Cita de: https://foro.elhacker.net/net/libreria_de_snippets_para_vbnet_compartan_aqui_sus_snippets-t378770.0.html;msg2004808#msg2004808Este snippet sirve para añadir o eliminar de forma muuuuuy sencilla un archivo/aplicación al Startup de Windows mediante el registro, con características interesantes...
Modo de empleo:WinStartupUtil.Add(UserType.CurrentUser, StartupType.Run, KeyBehavior.System32,
title:="Application Title",
filePath:="C:\Application.exe",
arguments:="/Arguments",
secureModeByPass:=True)WinStartupUtil.Remove(UserType.CurrentUser, StartupType.Run, KeyBehavior.System32,
title:="Application Title",
throwOnMissingValue:=True)
Source:' ***********************************************************************
' Author : Elektro
' Modified : 25-March-2015
' ***********************************************************************
' <copyright file="WinStartupUtil.vb" company="Elektro Studios">
' Copyright (c) Elektro Studios. All rights reserved.
' </copyright>
' ***********************************************************************
#Region " Usage Examples "
'WinStartupUtil.Add(WinStartupUtil.UserType.CurrentUser,
' WinStartupUtil.StartupType.Run,
' WinStartupUtil.KeyBehavior.System32,
' title:="Application Title",
' filePath:="C:\Application.exe",
' secureModeByPass:=True)
'WinStartupUtil.Remove(WinStartupUtil.UserType.CurrentUser,
' WinStartupUtil.StartupType.Run,
' WinStartupUtil.KeyBehavior.System32,
' title:="Application Title",
' throwOnMissingValue:=True)
#End Region
#Region " Option Statements "
Option Explicit On
Option Strict On
Option Infer Off
#End Region
#Region " Imports "
Imports Microsoft.Win32
#End Region
#Region " WinStartupUtil "
''' <summary>
''' Adds or removes an application to Windows Startup.
''' </summary>
Public NotInheritable Class WinStartupUtil
#Region " Properties "
''' <summary>
''' Gets the 'Run' registry subkey path.
''' </summary>
''' <value>The 'Run' registry subkey path.</value>
Public Shared ReadOnly Property RunSubKeyPath As String
Get
Return "Software\Microsoft\Windows\CurrentVersion\Run"
End Get
End Property
''' <summary>
''' Gets the 'Run' registry subkey path for x86 appications on x64 operating system.
''' </summary>
''' <value>The 'Run' registry subkey path for x86 appications on x64 operating system.</value>
Public Shared ReadOnly Property RunSubKeyPathSysWow64 As String
Get
Return "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"
End Get
End Property
''' <summary>
''' Gets the 'RunOnce' registry subkey path.
''' </summary>
''' <value>The 'RunOnce' registry subkey path.</value>
Public Shared ReadOnly Property RunOnceSubKeyPath As String
Get
Return "Software\Microsoft\Windows\CurrentVersion\RunOnce"
End Get
End Property
''' <summary>
''' Gets the 'RunOnce' registry subkey path for x86 appications on x64 operating system.
''' </summary>
''' <value>The 'RunOnce' registry subkey path for x86 appications on x64 operating system.</value>
Public Shared ReadOnly Property RunOnceSubKeyPathSysWow64 As String
Get
Return "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce"
End Get
End Property
#End Region
#Region " Enumerations "
''' <summary>
''' Specifies an user type.
''' </summary>
Public Enum UserType As Integer
''' <summary>
''' 'HKEY_CURRENT_USER' root key.
''' </summary>
CurrentUser = &H1
''' <summary>
''' 'HKEY_LOCAL_MACHINE' root key.
''' </summary>
AllUsers = &H2
End Enum
''' <summary>
''' Specifies a Startup type.
''' </summary>
Public Enum StartupType As Integer
''' <summary>
''' 'Run' registry subkey.
''' </summary>
Run = &H1
''' <summary>
''' 'RunOnce' registry subkey.
''' </summary>
RunOnce = &H2
End Enum
''' <summary>
''' Specifies a registry key behavior.
''' </summary>
Public Enum KeyBehavior As Integer
''' <summary>
''' System32 registry subkey.
''' </summary>
System32 = &H1
''' <summary>
''' SysWow64 registry subkey.
''' </summary>
SysWow64 = &H2
End Enum
#End Region
#Region " Public Methods "
''' <summary>
''' Adds an application to Windows Startup.
''' </summary>
''' <param name="userType">The type of user.</param>
''' <param name="startupType">The type of startup.</param>
''' <param name="keyBehavior">The registry key behavior.</param>
''' <param name="title">The registry value title.</param>
''' <param name="filePath">The application file path.</param>
''' <param name="secureModeByPass">
''' If set to <c>true</c>, the file is ran even when the user logs into 'Secure Mode' on Windows.
''' </param>
''' <exception cref="System.ArgumentNullException">title or filePath</exception>
Public Shared Sub Add(ByVal userType As UserType,
ByVal startupType As StartupType,
ByVal keyBehavior As KeyBehavior,
ByVal title As String,
ByVal filePath As String,
Optional ByVal arguments As String = "",
Optional secureModeByPass As Boolean = False)
If String.IsNullOrEmpty(title) Then
Throw New ArgumentNullException("title")
ElseIf String.IsNullOrEmpty(filePath) Then
Throw New ArgumentNullException("filePath")
Else
If secureModeByPass Then
title = title.Insert(0, "*")
End If
Dim regKey As RegistryKey = Nothing
Try
regKey = GetRootKey(userType).OpenSubKey(GetSubKeyPath(startupType, keyBehavior), writable:=True)
regKey.SetValue(title, String.Format("""{0}"" {1}", filePath, arguments), RegistryValueKind.String)
Catch ex As Exception
Throw
Finally
If regKey IsNot Nothing Then
regKey.Close()
End If
End Try
End If
End Sub
''' <summary>
''' Removes an application from Windows Startup.
''' </summary>
''' <param name="userType">The type of user.</param>
''' <param name="startupType">The type of startup.</param>
''' <param name="keyBehavior">The registry key behavior.</param>
''' <param name="title">The value name to find.</param>
''' <param name="throwOnMissingValue">if set to <c>true</c>, throws an exception on missing value.</param>
''' <exception cref="System.ArgumentNullException">title</exception>
''' <exception cref="System.ArgumentException">Registry value not found.;title</exception>
Friend Shared Sub Remove(ByVal userType As UserType,
ByVal startupType As StartupType,
ByVal keyBehavior As KeyBehavior,
ByVal title As String,
Optional ByVal throwOnMissingValue As Boolean = False)
If String.IsNullOrEmpty(title) Then
Throw New ArgumentNullException("title")
Else
Dim valueName As String = String.Empty
Dim regKey As RegistryKey = Nothing
Try
regKey = GetRootKey(userType).OpenSubKey(GetSubKeyPath(startupType, keyBehavior), writable:=True)
If regKey.GetValue(title, defaultValue:=Nothing) IsNot Nothing Then
valueName = title
ElseIf regKey.GetValue(title.Insert(0, "*"), defaultValue:=Nothing) IsNot Nothing Then
valueName = title.Insert(0, "*")
Else
If throwOnMissingValue Then
Throw New ArgumentException("Registry value not found.", "title")
End If
End If
regKey.DeleteValue(valueName, throwOnMissingValue:=throwOnMissingValue)
Catch ex As Exception
Throw
Finally
If regKey IsNot Nothing Then
regKey.Close()
End If
End Try
End If
End Sub
#End Region
#Region " Private Methods "
''' <summary>
''' Gets a <see cref="RegistryKey"/> instance of the specified root key.
''' </summary>
''' <param name="userType">The type of user.</param>
''' <returns>A <see cref="RegistryKey"/> instance of the specified root key.</returns>
''' <exception cref="System.ArgumentException">Invalid enumeration value.;userType</exception>
Private Shared Function GetRootKey(ByVal userType As UserType) As RegistryKey
Select Case userType
Case userType.CurrentUser
Return Registry.CurrentUser
Case userType.AllUsers
Return Registry.LocalMachine
Case Else
Throw New ArgumentException("Invalid enumeration value.", "userType")
End Select ' userType
End Function
''' <summary>
''' Gets the proper registry subkey path from the parameters criteria.
''' </summary>
''' <param name="startupType">Type of the startup.</param>
''' <param name="keyBehavior">The key behavior.</param>
''' <returns>The registry subkey path.</returns>
''' <exception cref="System.ArgumentException">
''' Invalid enumeration value.;startupType or
''' Invalid enumeration value.;keyBehavior
''' </exception>
Private Shared Function GetSubKeyPath(ByVal startupType As StartupType,
ByVal keyBehavior As KeyBehavior) As String
Select Case keyBehavior
Case keyBehavior.System32
Select Case startupType
Case startupType.Run
Return RunSubKeyPath
Case startupType.RunOnce
Return RunOnceSubKeyPath
Case Else
Throw New ArgumentException("Invalid enumeration value.", "startupType")
End Select ' startupType
Case keyBehavior.SysWow64
Select Case startupType
Case startupType.Run
Return RunSubKeyPathSysWow64
Case startupType.RunOnce
Return RunOnceSubKeyPathSysWow64
Case Else
Throw New ArgumentException("Invalid enumeration value.", "startupType")
End Select ' startupType
Case Else
Throw New ArgumentException("Invalid enumeration value.", "keyBehavior")
End Select ' keyBehavior
End Function
#End Region
End Class
#End Region
class Program {
static void Main(string[] args) {
int value = Properties.Settings.Default.Countdown;
Debug.WriteLine("Current value: {0}", value);
switch (value) {
case 0:
// ...
// lo que tengas que hacer aquí cuando el contador llega a 0.
// ...
Properties.Settings.Default.Reset(); // Reset Countdown value to 3.
break;
default: // 1, 2 or 3.
Properties.Settings.Default.Countdown -= 1;
break;
}
Properties.Settings.Default.Save();
Environment.Exit(0);
}
}
Cita de: File2Startup by Elektro
Cita de: warcry. en 19 Marzo 2018, 15:44 PM
¿tienes campo abierto entre el punto de la ciudad y el pueblo?
Cita de: PalitroqueZ en 19 Marzo 2018, 19:48 PM
bajo la tesis de la existencia de infinitos universos, es posible.
Cita de: Machacador en 19 Marzo 2018, 19:01 PM
Pues claro que el destino existe, y lo más certero de el es la muerte... ese es el único destino claro e inexorable que a todos los seres vivos nos espera... mientras ese destino nos alcance puede sucedernos cualquier cosa que por predestinada que esté, alguna otra circunstancia de la vida lo puede cambiar...
Cita de: CybeRoot en 18 Marzo 2018, 19:13 PMme pregunto cuál es tu objetivo... Es decir, lo que quieres es no tener que usar los datos?
Cita de: CybeRoot en 18 Marzo 2018, 19:13 PMRespecto a transmitir wifi al móvil mediante un cable, nunca lo había visto ni escuchado.