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

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


  Mostrar Mensajes
Páginas: 1 ... 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 [1018] 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 ... 1232
10171  Programación / .NET (C#, VB.NET, ASP) / Re: [VS] ¿clonar evento para varios elementos? ¿FOR? en: 19 Noviembre 2012, 23:24 pm
No Kubox, he usado ahora mismo tu ejemplo y solo se muestra UN checkbox:



Te lo agradezco de todas formas, a ver si doy con el fallo..
10172  Programación / .NET (C#, VB.NET, ASP) / Re: [VS] ¿clonar evento para varios elementos? ¿FOR? en: 19 Noviembre 2012, 23:14 pm
Pero no estás haciendo i-1 en todos los casos en los que i actúa como índice.

Tienes razón, estoy un poco gilipo**** xD!

Lo he modificado correctamente (Eso creo) y por fin me funciona, muchisimas gracias

Pero los problemas sigueeeen!


Voy a poner un ejemplo visual:

se carga la app, pincho en el primer checkbox de todos, el "0", y cierro la app:




Vuelvo a abrir la app, y me aparece esto:




¿Serías tán amables de ayudarme a buscar el error en mi form?
(además, no se que coñ* he tocado para que el índice empieze con "checkbox0" y no con "checkbox1", ya me he mirado la variable "i" pero me ha parecido estar bien)


Código
  1. Imports System.Windows.Forms
  2. Imports System.IO
  3.  
  4. Public Class Form1
  5.    Dim filesystem As Object, ThisDir As Object
  6.    Dim mCheck(0) As CheckBox 'matriz que contendrá los "X" CheckBox
  7.  
  8.    ' Start of Propertys
  9.    Public Property userSelectedPlayerFilePath() As String
  10.        Get
  11.            Return playertextbox.Text
  12.        End Get
  13.        Set(value As String)
  14.            playertextbox.Text = value
  15.        End Set
  16.    End Property
  17.  
  18.    Public Property userSelectedFolderPath() As String
  19.        Get
  20.            Return foldertextbox.Text
  21.        End Get
  22.        Set(value As String)
  23.            foldertextbox.Text = value
  24.        End Set
  25.    End Property
  26.  
  27.    Public Sub GenerarPropiedades() 'metodo que generará la propiedad al producirse el cierre del formulario
  28.        Dim CheckedN As String = Nothing 'la cadena que contendrá los CheckBoxes que estén Checkados
  29.        For i As Int32 = 0 To mCheck.Length - 1 'recorro la matriz de los CheckBoxes
  30.            If mCheck(i).Checked = True Then 'Si el CheckBox actual está checkado
  31.                CheckedN &= i + 1 'Obtengo su indice y lo meto al string (si es Checkbox1 pues 1, si es chckbx2 pues 2) ...
  32.            End If
  33.        Next
  34.        My.Settings.CuantosChecked = CheckedN 'Actualizo la propiedad
  35.        My.Settings.Save() 'Guardo la propiedad
  36.    End Sub
  37.  
  38.  
  39.    Public Sub CargarPropiedad() 'método que comprobará que CheckBoxes fueron tildados la útlima vez
  40.        Dim mCuantosChecked As Char() = My.Settings.CuantosChecked.ToCharArray 'Paso el String de la propiedad a una matriz
  41.        'Simplemente hago esto para separar el String por indices (un caracter por indice)
  42.        For Each caracter As Char In mCuantosChecked 'Recorro la matriz caracteres que contendrá los checboxes tildados
  43.            For Each CheckboxN In mCheck 'Recorro la matriz de CheckBoxes, para comparar si está o no está tildado
  44.                If CheckboxN.Name.Contains(caracter) Then
  45.                    'Si el CheckBox actual contiene cualquier caracter de la propiedad
  46.                    'que tiene los indices de los CheckBoxes tildados
  47.                    CheckboxN.Checked = True 'Lo tildo
  48.                End If
  49.            Next
  50.        Next
  51.    End Sub
  52.  
  53.  
  54.    ' update checkboxes
  55.    Public Sub updatecheckboxes()
  56.        ' delete the old checkboxes
  57.        Panel1.Controls.Clear()
  58.        ' create the new checkboxes
  59.        Dim filesystem = CreateObject("Scripting.FileSystemObject")
  60.        Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
  61.        Dim i As Int32 = 1
  62.        'Dim mCheck() As CheckBox
  63.        For Each folder In ThisDir.Subfolders
  64.  
  65.            'mCheck(i - 1) = New CheckBox()
  66.            Array.Resize(mCheck, i)
  67.            mCheck(i - 1) = New CheckBox()
  68.            'MessageBox.Show("test")
  69.            Me.Panel1.Controls.Add(mCheck(i - 1))
  70.            With mCheck(i - 1)
  71.                .Name = "Checkbox" & i - 1
  72.                .Text = "Checkbox" & i - 1
  73.                ' .Text = folder.Name
  74.                .Location = New Point(10, i * 20)
  75.            End With
  76.            AddHandler mCheck(i - 1).CheckedChanged, AddressOf LlamadaCheckBox
  77.            i = i + 1
  78.        Next
  79.        CargarPropiedad()
  80.    End Sub
  81.  
  82.    ' Form close
  83.    Public Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
  84.        GenerarPropiedades()
  85.        'My.Settings.Save()
  86.    End Sub
  87.  
  88.  
  89.    ' Form load
  90.    Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  91.        playertextbox.Text = My.Settings.playerpath
  92.        foldertextbox.Text = My.Settings.folderpath
  93.        updatecheckboxes()
  94.    End Sub
  95.  
  96.  
  97.    ' Folder button
  98.    Public Sub C1Button3_Click(sender As Object, e As EventArgs) Handles folderbutton.Click
  99.        Dim folderselected As New System.Windows.Forms.FolderBrowserDialog
  100.        Dim Resultado As DialogResult
  101.        folderselected.RootFolder = Environment.SpecialFolder.Desktop
  102.        Resultado = folderselected.ShowDialog
  103.        If Resultado.ToString() = "OK" Then
  104.            userSelectedFolderPath = folderselected.SelectedPath
  105.            My.Settings.folderpath = folderselected.SelectedPath
  106.            My.Settings.Save()
  107.            updatecheckboxes()
  108.        End If
  109.    End Sub
  110.  
  111.  
  112.    ' Player button
  113.    Public Sub C1Button1_Click(sender As Object, e As EventArgs) Handles playerbutton.Click
  114.        Dim playerselected As New OpenFileDialog()
  115.        playerselected.InitialDirectory = Environ("programfiles")
  116.        playerselected.Title = "Select your favorite music player"
  117.        playerselected.Filter = "Music players|mpc.exe;mpc-hc.exe;mpc-hc64.exe;umplayer.exe;vlc.exe;winamp.exe;wmp.exe"
  118.        PlayerDialog.FilterIndex = 1
  119.        Dim selection As System.Windows.Forms.DialogResult = playerselected.ShowDialog()
  120.        If selection = DialogResult.OK Then
  121.            userSelectedPlayerFilePath = playerselected.FileName
  122.            My.Settings.playerpath = playerselected.FileName
  123.            My.Settings.Save()
  124.        End If
  125.    End Sub
  126.  
  127.  
  128.    ' Play button
  129.    Public Sub C1Button2_Click(sender As Object, e As EventArgs) Handles C1Button2.Click
  130.        'Process.Start(userSelectedPlayerFilePath, ControlChars.Quote & Path.Combine(ThisDir.Path, checkedpath1) & ControlChars.Quote)
  131.    End Sub
  132.  
  133.  
  134.  
  135.    ' función que se ejecuta cuando cualquier checkbox es clickado
  136.    Public Sub LlamadaCheckBox(ByVal sender As Object, ByVal e As System.EventArgs)
  137.        Dim CheckboxN As CheckBox = CType(sender, CheckBox) 'a partir del sender creo el CheckBox (paso de objet a CheckBox para poder utilizar sus propiedades)
  138.        'MsgBox(CheckboxN.Name)
  139.  
  140.    End Sub
  141.  
  142. End Class
10173  Programación / .NET (C#, VB.NET, ASP) / Re: [VS] ¿clonar evento para varios elementos? ¿FOR? en: 19 Noviembre 2012, 22:54 pm
Nada, gracias Hdm y Kubox, puse exactamente lo que me dijeron pero no me quiere funcionar esto:


Código
  1. Public Class Form1
  2.    Dim filesystem As Object, ThisDir As Object
  3.    Dim mCheck(0) As CheckBox 'matriz que contendrá los "X" CheckBox
  4. ...


Código
  1.    ' Form load
  2.    Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3.        foldertextbox.Text = My.Settings.folderpath
  4.        updatecheckboxes()
  5.    End Sub



1er intento:
El messagebox solo aparece 1 vez, y en el panel no aparece ningún checkbox.

Código
  1.    ' update checkboxes
  2.    Public Sub updatecheckboxes()
  3.        Dim filesystem = CreateObject("Scripting.FileSystemObject")
  4.        Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
  5.        Dim i As Int32 = 0
  6.        For Each folder In ThisDir.Subfolders
  7.            i = i + 1
  8.            Array.Resize(mCheck, i)
  9.            mCheck(i - 1) = New CheckBox()
  10.            MessageBox.Show("test")
  11.            Me.Panel1.Controls.Add(mCheck(i))
  12.            With mCheck(i)
  13.                .Name = "Checkbox" & i
  14.                .Text = folder.Name
  15.                .Location = New Point(10, i * 20)
  16.            End With
  17.            AddHandler mCheck(i).CheckedChanged, AddressOf LlamadaCheckBox
  18.        Next
  19.        CargarPropiedad()
  20.    End Sub



2ndo intento:

El msgbox aparece todas las veces,
se cargan todos los checkboxes,

Pero no puedo cerrar el form, y como he "omitido" el "Array.resize" y lo que me dijo el compañero Hdm pues no creo que el índice del "mcheck" funcione para cargar/guardar las settings

Además he vuelto a las mismas de antes declarando el mcheck con un valor alto (999), así que esto no creo que me sirva para nada, solo es un ejemplo.

Código
  1. Public Class Form1
  2. ' el número aumentado a 999, sino no me funciona el segundo intento xD
  3.    Dim mCheck(999) As CheckBox
  4. ...

Código
  1.    ' update checkboxes
  2.    Public Sub updatecheckboxes()
  3.        Dim filesystem = CreateObject("Scripting.FileSystemObject")
  4.        Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
  5.        Dim i As Int32 = 0
  6.        For Each folder In ThisDir.Subfolders
  7.            i = i + 1
  8.            mCheck(i) = New CheckBox()
  9.            'Array.Resize(mCheck, i)
  10.            MessageBox.Show("test")
  11.            Me.Panel1.Controls.Add(mCheck(i))
  12.            With mCheck(i)
  13.                .Name = "Checkbox" & i
  14.                .Text = folder.Name
  15.                .Location = New Point(10, i * 20)
  16.            End With
  17.            AddHandler mCheck(i).CheckedChanged, AddressOf LlamadaCheckBox 'Asocio el evento CheckedChange del CheckBox actual a la función LlamadaCheckBox
  18.        Next
  19.        CargarPropiedad() 'Cargo las propiedades una vez dibujados los CheckBoxes
  20.    End Sub
10174  Programación / .NET (C#, VB.NET, ASP) / Re: [VS] ¿clonar evento para varios elementos? ¿FOR? en: 19 Noviembre 2012, 21:20 pm
Nada, tu contesta cuando puedas y solamente si te apetece, sinó mandame a buscarme la vida por ahí xD

¿Me puedes decir si está bien el For?
Bueno, no está bien, porque al cargar el form no se muestra NINGUN checkbox

Código
  1.    ' update checkboxes
  2.    Public Sub updatecheckboxes()
  3.        ' delete the old checkboxes
  4.        Panel1.Controls.Clear()
  5.        ' create the new checkboxes
  6.        Dim filesystem = CreateObject("Scripting.FileSystemObject")
  7.        Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
  8.        Dim i As Int32 = 0
  9.        For Each folder In ThisDir.Subfolders
  10.            i += 1
  11.            Array.Resize(mCheck, i)
  12.            MessageBox.Show("test")
  13.            mCheck(i) = New CheckBox()
  14.            With mCheck(i)
  15.                .Name = "Checkbox" & i
  16.                .Text = folder.Name
  17.                .Location = New Point(10, i * 20)
  18.            End With
  19.            AddHandler mCheck(i).CheckedChanged, AddressOf LlamadaCheckBox 'Asocio el evento CheckedChange del CheckBox actual a la función LlamadaCheckBox
  20.            Panel1.Controls.Add(mCheck(i))
  21.        Next
  22.        CargarPropiedad() 'Cargo las propiedades una vez dibujados los CheckBoxes
  23.    End Sub

Tengo declarado el mcheck así como me dijiste:
Código:
  Dim mCheck(0) As CheckBox

PD: El messagebox solo se muesta UNA vez :S
Muchas gracias por tu tiempo
10175  Sistemas Operativos / Windows / Re: error hotmail en: 19 Noviembre 2012, 20:01 pm
Si habitualmente adjuntas archivos mejor olvídate de Hotmail (y sus problemas) y usa esa utilidad gratis tanto online como standalone sin casi-límite de tamaño ni restriccion de tipo de archivos:

https://www.zeta-uploader.com/es




Saludos.
10176  Programación / .NET (C#, VB.NET, ASP) / Re: [VS] ¿clonar evento para varios elementos? ¿FOR? en: 19 Noviembre 2012, 19:56 pm
Pero entonces donde pone ".Text = folder.Name", ¿como puedo hacerlo?

¿Debo crear una lista que contenga cada nombre de carpeta en un string para luego usarlo en la propiedad "text" del segundo FOR? puf...

¿No se puede hacer esto en un solo bucle?
Código
  1.       Dim filesystem = CreateObject("Scripting.FileSystemObject")
  2.        Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
  3.        Dim folderindex As Integer = 0
  4.  
  5.        For Each folder In ThisDir.Subfolders
  6.            folderindex += 1
  7.            Array.Resize(mCheck, folderindex)
  8.        Next
  9.  
  10.        For i As Int32 = 0 To mCheck.Length - 1
  11.            mCheck(i) = New CheckBox()
  12.            With mCheck(i)
  13.                .Name = "Checkbox" & i
  14.                .Text = folder.Name
  15.                .Location = New Point(10, i * 20)
  16.            End With
  17.        Next

PD: Da error en ".Text = folder.Name" obviamente porque nada tiene que ver, pero no se como hacerlo.


EDITO: He conseguido "salir" de la app cambiando esto:

Código
  1. Dim mCheck(5) As CheckBox 'matriz que contendrá los "X" CheckBox
(Si el número 5 es mayor que las "carpetas" en total, osea, los checkboxes añadidos al cargarse el form, entonces sigue sin poderse cerrar)
(Vamos, que si en la app se cargan 20 checkboxes pues debería poner mcheck(19) manualmente para poder cerrar el form)

Código
  1. For i As Int32 = 1 To mCheck.Length - 1 'recorro la matriz de los CheckBoxes
Además de cambiar lo de antes, debo cambiar el valor inicial de 0, a 1, ¿algo raro pasa con el índice no?

Lo bueno viene ahora, puedo cerrar el form pero las propiedades no se me guardan!, bueno, yo que sé si se guardan, pero cuando vuelvo a abrir la app la casilla que estaba seleccionada no se selecciona...

En resumen, creo que la solución está arreglando el code de la forma que me has intnetado explicar Kubox, añadiendo un índice por cada carpeta encontrada, porque sinó no puedo salir del form ni tampoco se me guardan las settings arreglando el problema de "salir"  :xD.
10177  Programación / .NET (C#, VB.NET, ASP) / Re: [VS] ¿clonar evento para varios elementos? ¿FOR? en: 19 Noviembre 2012, 19:12 pm
Tu ejemplo me funciona perfectamente en un winform nuevo, pero cuando intento acoplarlo a mi winform ocurre una cosa... EL FORM NO SE CIERRA AL PULSAR EL BOTON DE CERRAR :  :huh: :huh: :huh:

Te lo agradezco mucho, ya me has ayudado bastante, pero ahora no se como "salir" de aquí, y como no puedo cerrarlo tampoco puedo saber si se guardan correctamente en my.settings xD

Te pongo mi form COMPLETO por si sabes donde puede estar mi error:

PD: uso Dim mCheck(9999) porque la cantidad de checkboxes a agregar es indeterminada, se agrega un checkbox nuevo en el form por cada carpeta de una ruta previamente cargada, no se si puedo hacerlo de mejor manera eso...

Código
  1. Imports System.Windows.Forms
  2. Imports System.IO
  3.  
  4. Public Class Form1
  5.    Dim filesystem As Object, ThisDir As Object
  6.    Public newCheckBox As New CheckBox()
  7.    Dim mCheck(9999) As CheckBox 'matriz que contendrá los "X" CheckBox
  8.  
  9.    ' Start of Propertys
  10.    Public Property userSelectedPlayerFilePath() As String
  11.        Get
  12.            Return playertextbox.Text
  13.        End Get
  14.        Set(value As String)
  15.            playertextbox.Text = value
  16.        End Set
  17.    End Property
  18.  
  19.    Public Property userSelectedFolderPath() As String
  20.        Get
  21.            Return foldertextbox.Text
  22.        End Get
  23.        Set(value As String)
  24.            foldertextbox.Text = value
  25.        End Set
  26.    End Property
  27.  
  28.    Public Property checkedpath1() As String
  29.        Get
  30.            Return newCheckBox.Text
  31.        End Get
  32.        Set(value As String)
  33.            newCheckBox.Text = value
  34.        End Set
  35.    End Property
  36.    ' End of propertys
  37.  
  38.  
  39.    ' update checkboxes
  40.    Public Sub updatecheckboxes()
  41.        ' delete the old checkboxes
  42.        Panel1.Controls.Clear()
  43.        ' create the new checkboxes
  44.        Dim i As Int32 = 0
  45.        Dim posy As Integer = 0
  46.        Dim filesystem = CreateObject("Scripting.FileSystemObject")
  47.        Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
  48.        For Each folder In ThisDir.Subfolders
  49.            i = i + 1
  50.            mCheck(i) = New CheckBox() 'creo un CheckBox en cada espacio de la matriz
  51.            With mCheck(i)
  52.                .Name = "Checkbox" & i ' Le adjunto un nombre Checkbox1 / Checkbox2 y 3
  53.                .Text = folder.name
  54.                .Location = New Point(10, i * 20)
  55.            End With
  56.            'MessageBox.Show(mCheck(i).Name)
  57.            AddHandler mCheck(i).CheckedChanged, AddressOf LlamadaCheckBox 'Asocio el evento CheckedChange del CheckBox actual a la función LlamadaCheckBox
  58.            Panel1.Controls.Add(mCheck(i))
  59.        Next
  60.        CargarPropiedad() 'Cargo las propiedades una vez dibujados los CheckBoxes
  61.    End Sub
  62.  
  63.  
  64.    Public Sub CargarPropiedad() 'método que comprobará que CheckBoxes fueron tildados la útlima vez
  65.        Dim mCuantosChecked As Char() = My.Settings.CuantosChecked.ToCharArray 'Paso el String de la propiedad a una matriz
  66.        'Simplemente hago esto para separar el String por indices (un caracter por indice)
  67.        For Each caracter As Char In mCuantosChecked 'Recorro la matriz caracteres que contendrá los checboxes tildados
  68.            For Each CheckboxN In mCheck 'Recorro la matriz de CheckBoxes, para comparar si está o no está tildado
  69.                If CheckboxN.Name.Contains(caracter) Then
  70.                    'Si el CheckBox actual contiene cualquier caracter de la propiedad
  71.                    'que tiene los indices de los CheckBoxes tildados
  72.                    CheckboxN.Checked = True 'Lo tildo
  73.                End If
  74.            Next
  75.        Next
  76.    End Sub
  77.  
  78.  
  79.    Private Sub GenerarPropiedades() 'metodo que generará la propiedad al producirse el cierre del formulario
  80.        Dim CheckedN As String = Nothing 'la cadena que contendrá los CheckBoxes que estén Checkados
  81.        For i As Int32 = 0 To mCheck.Length - 1 'recorro la matriz de los CheckBoxes
  82.            If mCheck(i).Checked = True Then 'Si el CheckBox actual está checkado
  83.                CheckedN &= i + 1 'Obtengo su indice y lo meto al string (si es Checkbox1 pues 1, si es chckbx2 pues 2) ...
  84.            End If
  85.            Me.Close()
  86.        Next
  87.  
  88.        My.Settings.CuantosChecked = CheckedN 'Actualizo la propiedad
  89.        My.Settings.Save() 'Guardo la propiedad
  90.  
  91.    End Sub
  92.  
  93.  
  94.    ' Form close
  95.    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  96.        'Este es el evento al que se llamará cuando se cierre la aplicación
  97.        'Como ves al cerrar la aplicación llamamos al método GenerarPropiedades() para guardar los CheckBoxes que fueron tildados
  98.        '      My.Settings.Save()
  99.        GenerarPropiedades()
  100.        Me.Close()
  101.    End Sub
  102.  
  103.  
  104.    ' Form load
  105.    Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  106.        playertextbox.Text = My.Settings.playerpath
  107.        foldertextbox.Text = My.Settings.folderpath
  108.        updatecheckboxes()
  109.        CargarPropiedad() 'Cargo las propiedades una vez dibujados los CheckBoxes
  110.    End Sub
  111.  
  112.    ' Folder button
  113.    Private Sub C1Button3_Click(sender As Object, e As EventArgs) Handles folderbutton.Click
  114.        Dim folderselected As New System.Windows.Forms.FolderBrowserDialog
  115.        Dim Resultado As DialogResult
  116.        folderselected.RootFolder = Environment.SpecialFolder.Desktop
  117.        Resultado = folderselected.ShowDialog
  118.        If Resultado.ToString() = "OK" Then
  119.            userSelectedFolderPath = folderselected.SelectedPath
  120.            My.Settings.folderpath = folderselected.SelectedPath
  121.            My.Settings.Save()
  122.            updatecheckboxes()
  123.        End If
  124.    End Sub
  125.  
  126.  
  127.    ' Player button
  128.    Public Sub C1Button1_Click(sender As Object, e As EventArgs) Handles playerbutton.Click
  129.        Dim playerselected As New OpenFileDialog()
  130.        playerselected.InitialDirectory = Environ("programfiles")
  131.        playerselected.Title = "Select your favorite music player"
  132.        playerselected.Filter = "Music players|mpc.exe;mpc-hc.exe;mpc-hc64.exe;umplayer.exe;vlc.exe;winamp.exe;wmp.exe"
  133.        PlayerDialog.FilterIndex = 1
  134.        Dim selection As System.Windows.Forms.DialogResult = playerselected.ShowDialog()
  135.        If selection = DialogResult.OK Then
  136.            userSelectedPlayerFilePath = playerselected.FileName
  137.            My.Settings.playerpath = playerselected.FileName
  138.            My.Settings.Save()
  139.        End If
  140.    End Sub
  141.  
  142.  
  143.    ' Play button
  144.    Public Sub C1Button2_Click(sender As Object, e As EventArgs) Handles C1Button2.Click
  145.        Process.Start(userSelectedPlayerFilePath, ControlChars.Quote & Path.Combine(ThisDir.Path, checkedpath1) & ControlChars.Quote)
  146.    End Sub
  147.  
  148.    ' función que se ejecuta cuando cualquier checkbox es clickado
  149.    Public Sub LlamadaCheckBox(ByVal sender As Object, ByVal e As System.EventArgs)
  150.        Dim CheckboxN As CheckBox = CType(sender, CheckBox) 'a partir del sender creo el CheckBox (paso de objet a CheckBox para poder utilizar sus propiedades)
  151.        MsgBox(CheckboxN.Name)
  152.  
  153.    End Sub
  154.  
  155.  
  156.  
  157. End Class
  158.  
  159.  
10178  Programación / .NET (C#, VB.NET, ASP) / Re: [VS] ¿clonar evento para varios elementos? ¿FOR? en: 19 Noviembre 2012, 17:11 pm
Gracias,

una pregunta tonta.... ¿Como coñ* lo utilizo? ¿Que tipo de argumento "mCheckBox" debo pasarle al sub? xD

Aparte, me da este error en "Configuration.SettingsProperty":

Cita de: VS
Error   1   'Configuration' is ambiguous, imported from the namespaces or types 'System, System.Drawing'.



EDITO:
Alguien me ha proporcionado este code en otro sitio, pero por más que lo intento no sé como utilizarlo:

Código
  1. Public Sub AnyCB_CheckedChanged(sender As Object, e As EventArgs)
  2.  
  3.        Dim cb = DirectCast(sender, CheckBox)
  4.        If cb.Checked AndAlso Not My.Settings.MyCBs.Contains(cb.Name) Then
  5.            My.Settings.MyCBs.Add(cb.Name)
  6.        ElseIf Not cb.Checked AndAlso My.Settings.MyCBs.Contains(cb.Name) Then
  7.            My.Settings.MyCBs.Remove(cb.Name)
  8.        End If
  9.  
  10.    End Sub
  11.  
  12.    Public Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
  13.  
  14.        If My.Settings.MyCBs Is Nothing Then My.Settings.MyCBs = New Collections.Specialized.StringCollection
  15.  
  16.        For Each s In My.Settings.MyCBs
  17.            DirectCast(Me.Controls(s), CheckBox).Checked = True
  18.        Next
  19.  
  20.        For Each cb In Me.Controls.OfType(Of CheckBox)()
  21.            AddHandler cb.CheckedChanged, AddressOf AnyCB_CheckedChanged
  22.        Next
  23.  
  24.    End Sub
Cuando clicko en un checkbox este no se guarda en "my.settings" así que cuando vuelvo a abrir la app, el checkbox no se auto-selecciona.

PD: Tengo creada la entrada "MyCBs" de tipo "Collections.Specialized.StringCollection" en "my.settings"
10179  Programación / .NET (C#, VB.NET, ASP) / Re: [VS] ¿clonar evento para varios elementos? ¿FOR? en: 19 Noviembre 2012, 16:34 pm
Ya he acoplado tu code a mi form, muchas gracias de nuevo

Lo que intento hacer es guardar en las settings los checkboxes que están clickados antes de cerrar el form:

Código
  1.    ' función que se ejecuta cuando cualquier checkbox es clickado
  2.    Public Sub LlamadaCheckBox(ByVal sender As Object, ByVal e As System.EventArgs)
  3.        Dim CheckboxN As CheckBox = CType(sender, CheckBox) 'a partir del sender creo el CheckBox (paso de objet a CheckBox para poder utilizar sus propiedades)
  4.        MsgBox(CheckboxN.Name)
  5.        If CheckboxN.Checked = True Then My.Settings.Selected_Checkboxes.Add(CheckboxN.Name.ToString())
  6.    End Sub

pero me dice: Object reference not set to an instance of an object.

La setting la tengo como tipo: "system.collection.specialized.stringcollection", no se si es la correcta.



Una vez conseguido eso, al volver a abrir la app (el form) necesitaría averiguar cuales checkboxes estaban clickados para seleccionarlos automáticamente


ojalá puedas ayudarme con eso
10180  Programación / Scripting / Re: Algun script para eliminar carpetas en: 19 Noviembre 2012, 14:25 pm
En Windows puedes crear lo que se llaman "Tareas programadas", para realizar cierta acción cada "X" minutos/horas, pienso que eso te serviría más que un script.

Puedes crear una tarea desde la interfaz del programador de tareas de Windows, o desde la consola con el comando AT o SCHTASKS (El comando AT solo soporta repetición de taréas en "días")

Código
  1. schtasks /create /sc minute /mo 30 /tn "Nombre de la tarea" /tr "CMD /C \"Comando\""

PD:
Código:
"SC (minute/hour)"
"/MO (Tiempo en minutos u horas)"

Saludos.
Páginas: 1 ... 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 [1018] 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 ... 1232
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines