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..
Te lo agradezco de todas formas, a ver si doy con el fallo..
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úCita de: HdM en 19 Noviembre 2012, 23:02 PM
Pero no estás haciendo i-1 en todos los casos en los que i actúa como índice.
Imports System.Windows.Forms
Imports System.IO
Public Class Form1
Dim filesystem As Object, ThisDir As Object
Dim mCheck(0) As CheckBox 'matriz que contendrá los "X" CheckBox
' Start of Propertys
Public Property userSelectedPlayerFilePath() As String
Get
Return playertextbox.Text
End Get
Set(value As String)
playertextbox.Text = value
End Set
End Property
Public Property userSelectedFolderPath() As String
Get
Return foldertextbox.Text
End Get
Set(value As String)
foldertextbox.Text = value
End Set
End Property
Public Sub GenerarPropiedades() 'metodo que generará la propiedad al producirse el cierre del formulario
Dim CheckedN As String = Nothing 'la cadena que contendrá los CheckBoxes que estén Checkados
For i As Int32 = 0 To mCheck.Length - 1 'recorro la matriz de los CheckBoxes
If mCheck(i).Checked = True Then 'Si el CheckBox actual está checkado
CheckedN &= i + 1 'Obtengo su indice y lo meto al string (si es Checkbox1 pues 1, si es chckbx2 pues 2) ...
End If
Next
My.Settings.CuantosChecked = CheckedN 'Actualizo la propiedad
My.Settings.Save() 'Guardo la propiedad
End Sub
Public Sub CargarPropiedad() 'método que comprobará que CheckBoxes fueron tildados la útlima vez
Dim mCuantosChecked As Char() = My.Settings.CuantosChecked.ToCharArray 'Paso el String de la propiedad a una matriz
'Simplemente hago esto para separar el String por indices (un caracter por indice)
For Each caracter As Char In mCuantosChecked 'Recorro la matriz caracteres que contendrá los checboxes tildados
For Each CheckboxN In mCheck 'Recorro la matriz de CheckBoxes, para comparar si está o no está tildado
If CheckboxN.Name.Contains(caracter) Then
'Si el CheckBox actual contiene cualquier caracter de la propiedad
'que tiene los indices de los CheckBoxes tildados
CheckboxN.Checked = True 'Lo tildo
End If
Next
Next
End Sub
' update checkboxes
Public Sub updatecheckboxes()
' delete the old checkboxes
Panel1.Controls.Clear()
' create the new checkboxes
Dim filesystem = CreateObject("Scripting.FileSystemObject")
Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
Dim i As Int32 = 1
'Dim mCheck() As CheckBox
For Each folder In ThisDir.Subfolders
'mCheck(i - 1) = New CheckBox()
Array.Resize(mCheck, i)
mCheck(i - 1) = New CheckBox()
'MessageBox.Show("test")
Me.Panel1.Controls.Add(mCheck(i - 1))
With mCheck(i - 1)
.Name = "Checkbox" & i - 1
.Text = "Checkbox" & i - 1
' .Text = folder.Name
.Location = New Point(10, i * 20)
End With
AddHandler mCheck(i - 1).CheckedChanged, AddressOf LlamadaCheckBox
i = i + 1
Next
CargarPropiedad()
End Sub
' Form close
Public Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
GenerarPropiedades()
'My.Settings.Save()
End Sub
' Form load
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
playertextbox.Text = My.Settings.playerpath
foldertextbox.Text = My.Settings.folderpath
updatecheckboxes()
End Sub
' Folder button
Public Sub C1Button3_Click(sender As Object, e As EventArgs) Handles folderbutton.Click
Dim folderselected As New System.Windows.Forms.FolderBrowserDialog
Dim Resultado As DialogResult
folderselected.RootFolder = Environment.SpecialFolder.Desktop
Resultado = folderselected.ShowDialog
If Resultado.ToString() = "OK" Then
userSelectedFolderPath = folderselected.SelectedPath
My.Settings.folderpath = folderselected.SelectedPath
My.Settings.Save()
updatecheckboxes()
End If
End Sub
' Player button
Public Sub C1Button1_Click(sender As Object, e As EventArgs) Handles playerbutton.Click
Dim playerselected As New OpenFileDialog()
playerselected.InitialDirectory = Environ("programfiles")
playerselected.Title = "Select your favorite music player"
playerselected.Filter = "Music players|mpc.exe;mpc-hc.exe;mpc-hc64.exe;umplayer.exe;vlc.exe;winamp.exe;wmp.exe"
PlayerDialog.FilterIndex = 1
Dim selection As System.Windows.Forms.DialogResult = playerselected.ShowDialog()
If selection = DialogResult.OK Then
userSelectedPlayerFilePath = playerselected.FileName
My.Settings.playerpath = playerselected.FileName
My.Settings.Save()
End If
End Sub
' Play button
Public Sub C1Button2_Click(sender As Object, e As EventArgs) Handles C1Button2.Click
'Process.Start(userSelectedPlayerFilePath, ControlChars.Quote & Path.Combine(ThisDir.Path, checkedpath1) & ControlChars.Quote)
End Sub
' función que se ejecuta cuando cualquier checkbox es clickado
Public Sub LlamadaCheckBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim CheckboxN As CheckBox = CType(sender, CheckBox) 'a partir del sender creo el CheckBox (paso de objet a CheckBox para poder utilizar sus propiedades)
'MsgBox(CheckboxN.Name)
End Sub
End Class
Public Class Form1
Dim filesystem As Object, ThisDir As Object
Dim mCheck(0) As CheckBox 'matriz que contendrá los "X" CheckBox
...
' Form load
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
foldertextbox.Text = My.Settings.folderpath
updatecheckboxes()
End Sub
' update checkboxes
Public Sub updatecheckboxes()
Dim filesystem = CreateObject("Scripting.FileSystemObject")
Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
Dim i As Int32 = 0
For Each folder In ThisDir.Subfolders
i = i + 1
Array.Resize(mCheck, i)
mCheck(i - 1) = New CheckBox()
MessageBox.Show("test")
Me.Panel1.Controls.Add(mCheck(i))
With mCheck(i)
.Name = "Checkbox" & i
.Text = folder.Name
.Location = New Point(10, i * 20)
End With
AddHandler mCheck(i).CheckedChanged, AddressOf LlamadaCheckBox
Next
CargarPropiedad()
End Sub
Public Class Form1
' el número aumentado a 999, sino no me funciona el segundo intento xD
Dim mCheck(999) As CheckBox
...
' update checkboxes
Public Sub updatecheckboxes()
Dim filesystem = CreateObject("Scripting.FileSystemObject")
Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
Dim i As Int32 = 0
For Each folder In ThisDir.Subfolders
i = i + 1
mCheck(i) = New CheckBox()
'Array.Resize(mCheck, i)
MessageBox.Show("test")
Me.Panel1.Controls.Add(mCheck(i))
With mCheck(i)
.Name = "Checkbox" & i
.Text = folder.Name
.Location = New Point(10, i * 20)
End With
AddHandler mCheck(i).CheckedChanged, AddressOf LlamadaCheckBox 'Asocio el evento CheckedChange del CheckBox actual a la función LlamadaCheckBox
Next
CargarPropiedad() 'Cargo las propiedades una vez dibujados los CheckBoxes
End Sub
' update checkboxes
Public Sub updatecheckboxes()
' delete the old checkboxes
Panel1.Controls.Clear()
' create the new checkboxes
Dim filesystem = CreateObject("Scripting.FileSystemObject")
Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
Dim i As Int32 = 0
For Each folder In ThisDir.Subfolders
i += 1
Array.Resize(mCheck, i)
MessageBox.Show("test")
mCheck(i) = New CheckBox()
With mCheck(i)
.Name = "Checkbox" & i
.Text = folder.Name
.Location = New Point(10, i * 20)
End With
AddHandler mCheck(i).CheckedChanged, AddressOf LlamadaCheckBox 'Asocio el evento CheckedChange del CheckBox actual a la función LlamadaCheckBox
Panel1.Controls.Add(mCheck(i))
Next
CargarPropiedad() 'Cargo las propiedades una vez dibujados los CheckBoxes
End Sub
Dim mCheck(0) As CheckBox
Dim filesystem = CreateObject("Scripting.FileSystemObject")
Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
Dim folderindex As Integer = 0
For Each folder In ThisDir.Subfolders
folderindex += 1
Array.Resize(mCheck, folderindex)
Next
For i As Int32 = 0 To mCheck.Length - 1
mCheck(i) = New CheckBox()
With mCheck(i)
.Name = "Checkbox" & i
.Text = folder.Name
.Location = New Point(10, i * 20)
End With
Next
Dim mCheck(5) As CheckBox 'matriz que contendrá los "X" CheckBox
For i As Int32 = 1 To mCheck.Length - 1 'recorro la matriz de los CheckBoxes
Imports System.Windows.Forms
Imports System.IO
Public Class Form1
Dim filesystem As Object, ThisDir As Object
Public newCheckBox As New CheckBox()
Dim mCheck(9999) As CheckBox 'matriz que contendrá los "X" CheckBox
' Start of Propertys
Public Property userSelectedPlayerFilePath() As String
Get
Return playertextbox.Text
End Get
Set(value As String)
playertextbox.Text = value
End Set
End Property
Public Property userSelectedFolderPath() As String
Get
Return foldertextbox.Text
End Get
Set(value As String)
foldertextbox.Text = value
End Set
End Property
Public Property checkedpath1() As String
Get
Return newCheckBox.Text
End Get
Set(value As String)
newCheckBox.Text = value
End Set
End Property
' End of propertys
' update checkboxes
Public Sub updatecheckboxes()
' delete the old checkboxes
Panel1.Controls.Clear()
' create the new checkboxes
Dim i As Int32 = 0
Dim posy As Integer = 0
Dim filesystem = CreateObject("Scripting.FileSystemObject")
Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
For Each folder In ThisDir.Subfolders
i = i + 1
mCheck(i) = New CheckBox() 'creo un CheckBox en cada espacio de la matriz
With mCheck(i)
.Name = "Checkbox" & i ' Le adjunto un nombre Checkbox1 / Checkbox2 y 3
.Text = folder.name
.Location = New Point(10, i * 20)
End With
'MessageBox.Show(mCheck(i).Name)
AddHandler mCheck(i).CheckedChanged, AddressOf LlamadaCheckBox 'Asocio el evento CheckedChange del CheckBox actual a la función LlamadaCheckBox
Panel1.Controls.Add(mCheck(i))
Next
CargarPropiedad() 'Cargo las propiedades una vez dibujados los CheckBoxes
End Sub
Public Sub CargarPropiedad() 'método que comprobará que CheckBoxes fueron tildados la útlima vez
Dim mCuantosChecked As Char() = My.Settings.CuantosChecked.ToCharArray 'Paso el String de la propiedad a una matriz
'Simplemente hago esto para separar el String por indices (un caracter por indice)
For Each caracter As Char In mCuantosChecked 'Recorro la matriz caracteres que contendrá los checboxes tildados
For Each CheckboxN In mCheck 'Recorro la matriz de CheckBoxes, para comparar si está o no está tildado
If CheckboxN.Name.Contains(caracter) Then
'Si el CheckBox actual contiene cualquier caracter de la propiedad
'que tiene los indices de los CheckBoxes tildados
CheckboxN.Checked = True 'Lo tildo
End If
Next
Next
End Sub
Private Sub GenerarPropiedades() 'metodo que generará la propiedad al producirse el cierre del formulario
Dim CheckedN As String = Nothing 'la cadena que contendrá los CheckBoxes que estén Checkados
For i As Int32 = 0 To mCheck.Length - 1 'recorro la matriz de los CheckBoxes
If mCheck(i).Checked = True Then 'Si el CheckBox actual está checkado
CheckedN &= i + 1 'Obtengo su indice y lo meto al string (si es Checkbox1 pues 1, si es chckbx2 pues 2) ...
End If
Me.Close()
Next
My.Settings.CuantosChecked = CheckedN 'Actualizo la propiedad
My.Settings.Save() 'Guardo la propiedad
End Sub
' Form close
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'Este es el evento al que se llamará cuando se cierre la aplicación
'Como ves al cerrar la aplicación llamamos al método GenerarPropiedades() para guardar los CheckBoxes que fueron tildados
' My.Settings.Save()
GenerarPropiedades()
Me.Close()
End Sub
' Form load
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
playertextbox.Text = My.Settings.playerpath
foldertextbox.Text = My.Settings.folderpath
updatecheckboxes()
CargarPropiedad() 'Cargo las propiedades una vez dibujados los CheckBoxes
End Sub
' Folder button
Private Sub C1Button3_Click(sender As Object, e As EventArgs) Handles folderbutton.Click
Dim folderselected As New System.Windows.Forms.FolderBrowserDialog
Dim Resultado As DialogResult
folderselected.RootFolder = Environment.SpecialFolder.Desktop
Resultado = folderselected.ShowDialog
If Resultado.ToString() = "OK" Then
userSelectedFolderPath = folderselected.SelectedPath
My.Settings.folderpath = folderselected.SelectedPath
My.Settings.Save()
updatecheckboxes()
End If
End Sub
' Player button
Public Sub C1Button1_Click(sender As Object, e As EventArgs) Handles playerbutton.Click
Dim playerselected As New OpenFileDialog()
playerselected.InitialDirectory = Environ("programfiles")
playerselected.Title = "Select your favorite music player"
playerselected.Filter = "Music players|mpc.exe;mpc-hc.exe;mpc-hc64.exe;umplayer.exe;vlc.exe;winamp.exe;wmp.exe"
PlayerDialog.FilterIndex = 1
Dim selection As System.Windows.Forms.DialogResult = playerselected.ShowDialog()
If selection = DialogResult.OK Then
userSelectedPlayerFilePath = playerselected.FileName
My.Settings.playerpath = playerselected.FileName
My.Settings.Save()
End If
End Sub
' Play button
Public Sub C1Button2_Click(sender As Object, e As EventArgs) Handles C1Button2.Click
Process.Start(userSelectedPlayerFilePath, ControlChars.Quote & Path.Combine(ThisDir.Path, checkedpath1) & ControlChars.Quote)
End Sub
' función que se ejecuta cuando cualquier checkbox es clickado
Public Sub LlamadaCheckBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim CheckboxN As CheckBox = CType(sender, CheckBox) 'a partir del sender creo el CheckBox (paso de objet a CheckBox para poder utilizar sus propiedades)
MsgBox(CheckboxN.Name)
End Sub
End Class
Cita de: VSError 1 'Configuration' is ambiguous, imported from the namespaces or types 'System, System.Drawing'.
Public Sub AnyCB_CheckedChanged(sender As Object, e As EventArgs)
Dim cb = DirectCast(sender, CheckBox)
If cb.Checked AndAlso Not My.Settings.MyCBs.Contains(cb.Name) Then
My.Settings.MyCBs.Add(cb.Name)
ElseIf Not cb.Checked AndAlso My.Settings.MyCBs.Contains(cb.Name) Then
My.Settings.MyCBs.Remove(cb.Name)
End If
End Sub
Public Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
If My.Settings.MyCBs Is Nothing Then My.Settings.MyCBs = New Collections.Specialized.StringCollection
For Each s In My.Settings.MyCBs
DirectCast(Me.Controls(s), CheckBox).Checked = True
Next
For Each cb In Me.Controls.OfType(Of CheckBox)()
AddHandler cb.CheckedChanged, AddressOf AnyCB_CheckedChanged
Next
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. ' función que se ejecuta cuando cualquier checkbox es clickado
Public Sub LlamadaCheckBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim CheckboxN As CheckBox = CType(sender, CheckBox) 'a partir del sender creo el CheckBox (paso de objet a CheckBox para poder utilizar sus propiedades)
MsgBox(CheckboxN.Name)
If CheckboxN.Checked = True Then My.Settings.Selected_Checkboxes.Add(CheckboxN.Name.ToString())
End Sub
schtasks /create /sc minute /mo 30 /tn "Nombre de la tarea" /tr "CMD /C \"Comando\""
"SC (minute/hour)"
"/MO (Tiempo en minutos u horas)"