Sunteți pe pagina 1din 30

VISUAL BASIC .

NET

1. Crear un formulario de promedio de notas N1, N2 usando funciones.

Objeto Propiedades Valor


Label1 Text Nota 1
Label2 Text Nota 2
TextBox1 Name txtN1
TextBox2 Name txtN2
Button1 Name btnAceptar
Text Aceptar
Button2 Name btnNuevo
Text Nuevo
Button3 Name btnCerrar
Text Cerrar

Programación de los Controles


Public Class frmPromedio
Function Promedio_Nota(ByVal x, ByVal y)
Promedio_Nota = (x + y) / 2
End Function
Private Sub btnAceptar_Click()
Dim N1 As Integer = CInt(TxtN1.Text)
Dim N2 As Integer = CInt(TxtN2.Text)
MsgBox(Promedio_Nota(N1, N2))
Me.BackColor = Color.Pink
btnNuevo.Focus()
End Sub

Private Sub btnNuevo_Click()


TxtN1.Text = ""
TxtN2.Text = ""
TxtN1.Focus()
End Sub
Private Sub txtN1_KeyPress()
If e.KeyChar = Chr(13) Then
txtN2.Focus()
End If
End Sub

Private Sub txtN2_KeyPress()


If e.KeyChar = Chr(13) Then
btnAceptar.Focus()
End If
End Sub

Private Sub btnCerrar_Click()


End
End Sub

End Class

2. Crear un formulario de Saludo

Objeto Propiedades Valor


Label1 Text Ingrese su Nombre
Label2 Name lblSaludo
Text
AutoSize False
BorderStyle Fixed3D
TextAlign MiddleCenter
TextBox1 Name txtNombre
Button1 Name btnSaludo
Button2 Name btnCerrar
Programación de los Controles
Public Class frmSaludo
Private Sub btnCerrar_Click()
End
End Sub
Private Sub btnSaludo_Click()
Dim Nombre As String
Nombre = txtNombre.Text
lblSaludo.Text = "Hola: " & Chr(10) & Chr(13) & Nombre _
& Chr(10) & Chr(13) _
& Chr(10) & Chr(13) _
& "Bienvenido a Visual Basic 2005"
End Sub

Private Sub txtNombre_KeyPress()


If e.KeyChar = Chr(13) Then
btnSaludo.Focus()
End If
End Sub

End Class

3. Crear un formulario de Notas

Objeto Propiedades Valor


Label1 Text Alumno
Label2 Text Nota Nº 01
Label3 Text Nota Nº 02
Label4 Text Nota Nº 03
Label5 Text Nota Nº 04
Label6 Text Puntos
Label7 Text Promedio
Label8 Name lblPuntos
Text
BorderStyle Fixed3D
Label9 Name lblPromedio
Text
BorderStyle Fixed3D
TextBox1 Name txtNombre
TextBox2 Name txtNota1
TextBox3 Name txtNota2
TextBox4 Name txtNota3
TextBox5 Name txtNota4
Button1 Name btnCalcular
Text &Calcular
Button2 Name btnNuevo
Text &Nuevo
Button3 Name btnCerrar
Text &Cerrar

Programación de los Controles


Public Class frmAlumno_Notas

Private Sub btnCerrar_Click()


Close()
End Sub

Private Sub btnNuevo_Click()


txtNombre.Text = ""
txtNota1.Text = ""
txtNota2.Text = ""
txtNota3.Text = ""
txtNota4.Text = ""
lblPuntos.Text = ""
lblPromedio.Text = ""
txtNombre.Focus()
End Sub

Private Sub btnCalcular_Click()


Dim N1, N2, N3, N4, Puntos, Promedio As Single
'Verifica si ingreso el nombre del alumno
If txtNombre.Text = "" Then
'MsgBox("Ingrese Nombre del Alumno", _
'MsgBoxStyle.Information + MessageBoxButtons.OK, _
'"Por Favor")
'*** Otra forma de Msgbox ***********************
MessageBox.Show("Ingrese el Nombre del Alumno", _
"Por Favor", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
txtNombre.Focus()
Exit Sub
End If
If txtNota1.Text.Trim = "" Or _
Single.Parse(txtNota1.Text.Trim) < 0 Or _
Single.Parse(txtNota1.Text.Trim) > 20 Then
MessageBox.Show("Ingrese la Nota Nº 01", "Entre 0 y 20", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtNota1.Focus()
Exit Sub
End If
If txtNota2.Text.Trim = "" _
Or Single.Parse(txtNota2.Text.Trim) < 0 _
Or Single.Parse(txtNota2.Text.Trim) > 20 Then
MessageBox.Show("Ingrese la Nota Nº 02", "Entre 0 y 20", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtNota2.Focus()
Exit Sub
End If
If txtNota3.Text.Trim = "" _
Or Single.Parse(txtNota3.Text.Trim) < 0 _
Or Single.Parse(txtNota3.Text.Trim) > 20 Then
MessageBox.Show("Ingrese la Nota Nº 03", "Entre 0 y 20", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtNota3.Focus()
Exit Sub
End If
N1 = Single.Parse(txtNota1.Text)
N2 = Single.Parse(txtNota2.Text)
N3 = Single.Parse(txtNota3.Text)
N4 = Single.Parse(txtNota4.Text)
Puntos = N1 + N2 + N3 + N4
Promedio = Puntos / 4
lblPuntos.Text = Puntos.ToString
lblPromedio.Text = Promedio.ToString
If Promedio >= 10.5 Then
lblPromedio.ForeColor = Color.Blue
Else
lblPromedio.ForeColor = Color.Red
End If

End Sub
End Class

4. Crear un formulario para calcular el Importe de una Factura con su Igv (19%)
Objeto Propiedades Valor
Label1 Text Nombre del Cliente
Label2 Text Monto de la Factura
Label3 Text Importe
Label4 Text Igv (19%)
Label5 Name lblImporte
Text
BorderStyle Fixed3D
Label6 Name lblIgv
Text
BorderStyle Fixed3D
TextBox1 Name txtCliente
TextBox2 Name txtMonto
Button1 Name btnCalcular
Text &Calcular
Button2 Name btnNuevo
Text &Nuevo
Button3 Name btnSalir
Text &Salir
Programación de los Controles
Public Class frmMonto_Factura

Private Sub btnNuevo_Click()


txtCliente.Text = ""
txtMonto.Text = ""
lblImporte.Text = ""
lblIgv.Text = ""
txtCliente.Focus()
End Sub

Private Sub btnSalir_Click()


Close()
End Sub

Private Sub btnCalcular_Click()


Dim Monto, Importe, Igv As Single
Monto = Single.Parse(txtMonto.Text)
Importe = Monto / 1.19
Igv = Monto - Importe
lblImporte.Text = Importe.ToString("###,##0.00")
lblIgv.Text = Igv.ToString("###,##0.00")
End Sub
End Class
5. Construir una aplicación que permita averiguar la paridad, si es primo y si es capicúa

Objeto Propiedades Valor


Label1 Text Ingrese Numero
Label2 Text Mensaje
Label3 Name lblMensaje
Text
BorderStyle Fixed3D
RadioButton1 Name rbParidad
Text Paridad
RadioButton2 Name rbPrimo
Text Primo
RadioButton3 Name rbCapicua
Text Capicúa
TextBox1 Name txtNumero
Button1 Name btnComprobar
Text &Comprobar
Button2 Name btnNuevo
Text &Nuevo
Button3 Name btnSalir
Text &Salir
Programación de los Controles
Public Class frmNumeros
Private Sub btnSalir_Click()
Close()
End Sub

Private Sub btnNuevo_Click()


txtNumero.Text = ""
lblMensaje.Text = ""
rbParidad.Checked = True
txtNumero.Focus()
End Sub
Private Sub btnComprobar_Click()
Dim Numero, TEMP, J, T, SW As Integer
Numero = Integer.Parse(txtNumero.Text)
If rbParidad.Checked = True Then
If Numero Mod 2 = 0 Then
lblMensaje.Text = "Es un numero par"
Else
lblMensaje.Text = "Es un numero impar"
End If
End If
If rbPrimo.Checked = True Then
SW = 0
For J = 2 To Numero - 1
If Numero Mod J = 0 Then SW = 1
Next
If SW = 0 Then
lblMensaje.Text = "Es un numero primo"
Else
lblMensaje.Text = "No es un numero primo"
End If
End If
If rbCapicua.Checked = True Then
TEMP = Numero
T = 0
Do While TEMP > 0
T = T * 10 + TEMP Mod 10
TEMP = TEMP \ 10
Loop
If Numero = T Then
lblMensaje.Text = "Es un numero capicúa"
Else
lblMensaje.Text = "No es un numero capicúa"
End If
End If
End Sub
End Class
6. Construya una aplicación para realizar el registro de datos utilizando botones de opción,
casillas de verificación y listas simples.

Objeto Propiedades Valor


GroupBox1 Text Información
GroupBox2 Text Turno
Label1 Text Nombre
Label2 Text Edad
Label3 Text Nombre
Label4 Text Edad
Label5 Text Turno
Label6 Text Casado
TextBox1 Name txtNombre
NumericUpDonw1 Name UpEdad
RadioButton1 Name rbMañana
Text Mañana
RadioButton2 Name rbTarde
Text Tarde
RadioButton3 Name rbNoche
Text Noche
CheckBox1 Name ckCasado
Text Casado
ListBox1 Name lbNombre
ListBox2 Name lbEdad
ListBox3 Name lbTurno
ListBox4 Name lbCasado
Button1 Name btnAgregar
Text &Agregar
Button2 Name btnQuitar
Text &Quitar
Button3 Name btnLimpiar
Text &Limpiar
Button4 Name btnSalir
Text &Salir
Programación de los Controles
Public Class frmRegistro_Datos
Sub Seleccionar(ByVal Elemento As Integer)
lbNombre.SelectedIndex = elemento
lbTurno.SelectedIndex = elemento
lbEdad.SelectedIndex = elemento
lbCasado.SelectedIndex = elemento
End Sub
Sub Quitar(ByVal Elemento As Integer)
lbNombre.Items.RemoveAt(Elemento)
lbTurno.Items.RemoveAt(Elemento)
lbEdad.Items.RemoveAt(Elemento)
lbCasado.Items.RemoveAt(Elemento)
End Sub

Private Sub btnAgregar_Click()


Dim Nombre, Casado, Turno As String
Dim Edad As Byte
If txtNombre.Text.Trim = "" Then
MessageBox.Show("Ingrese el Nombre", "Por Favor")
txtNombre.Focus()
End If
If Not rbMañana.Checked And Not rbTarde.Checked _
And Not rbNoche.Checked Then
MessageBox.Show("Seleccione el Turno", "Por Favor")
Exit Sub
End If
Nombre = txtNombre.Text.ToUpper
Edad = upEdad.Value
Casado = "No"
If ckCasado.Checked Then Casado = "Si"
If rbMañana.Checked Then Turno = "Mañana"
If rbTarde.Checked Then Turno = "Tarde"
If rbNoche.Checked Then Turno = "Noche"
lbNombre.Items.Add(Nombre)
lbEdad.Items.Add(Edad.ToString)
lbTurno.Items.Add(Turno)
lbCasado.Items.Add(Casado)
txtNombre.Clear()
upEdad.Value = 18
ckCasado.Checked = False
rbMañana.Checked = False
rbTarde.Checked = False
rbNoche.Checked = False
txtNombre.Focus()
End Sub
Private Sub btnQuitar_Click()
If lbNombre.SelectedIndex < 0 Then
MessageBox.Show("Seleccione un elemento", "Para Quitar", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Quitar(lbNombre.SelectedIndex)
End If
End Sub

Private Sub btnLimpiar_Click()


lbNombre.Items.Clear()
lbTurno.Items.Clear()
lbEdad.Items.Clear()
lbCasado.Items.Clear()
End Sub

Private Sub btnSalir_Click()


Close()
End Sub

Private Sub lbNombre_SelectedIndexChanged()


Seleccionar(lbNombre.SelectedIndex)
End Sub

Private Sub lbEdad_SelectedIndexChanged()


Seleccionar(lbEdad.SelectedIndex)
End Sub

Private Sub lbTurno_SelectedIndexChanged()


Seleccionar(lbTurno.SelectedIndex)
End Sub

Private Sub lbCasado_SelectedIndexChanged()


Seleccionar(lbCasado.SelectedIndex)
End Sub
End Class
7. Construir un programa que genere números, letras mayúsculas, letras minúsculas o
caracteres especiales en una lista y luego pasarlos a otra lista

Objeto Propiedades Valor


CheckedListBox1 Name cklbLista
ListBox1 Name lbLista
Button1 Name btnNumeros
Text Numeros
Button2 Name btnMayusculas
Text Mayusculas
Button3 Name btnMinusculas
Text Minusculas
Button4 Name btnEspeciales
Text Especiales
Button5 Name btnPasar
Text &Pasar
Button6 Name btnSalir
Text &Salir

Programación de los Controles


Public Class frmLista_Caracteres
Dim X As Byte 'Declara variables globales
Dim Sw As Boolean 'al inicio de la clase

Private Sub btnNumeros_Click()


cklbLista.Items.Clear()
lbLista.Items.Clear()
For X = 48 To 57
cklbLista.Items.Add(Chr(X))
Next
End Sub
Private Sub btnMayusculas_Click()
cklbLista.Items.Clear()
lbLista.Items.Clear()
For X = 65 To 92
cklbLista.Items.Add(Chr(X))
Next
End Sub

Private Sub btnMinusculas_Click()


cklbLista.Items.Clear()
lbLista.Items.Clear()
For X = 97 To 122
cklbLista.Items.Add(Chr(X))
Next
End Sub

Private Sub btnEspeciales_Click()


cklbLista.Items.Clear()
lbLista.Items.Clear()
cklbLista.Items.Add(Chr(225))
cklbLista.Items.Add(Chr(233))
cklbLista.Items.Add(Chr(237))
cklbLista.Items.Add(Chr(243))
cklbLista.Items.Add(Chr(250))
cklbLista.Items.Add(Chr(241))
cklbLista.Items.Add(Chr(209))
End Sub

Private Sub btnPasar_Click()


Sw = Not Sw
If Sw Then
btnPasar.Text = "Pasar &No Marcados"
Else
btnPasar.Text = "Pasar &Marcados"
End If
lbLista.Items.Clear()
For I As Byte = 0 To cklbLista.Items.Count - 1
If cklbLista.GetItemChecked(I) = Sw Then
lbLista.Items.Add(cklbLista.Items(I))
End If
Next
End Sub

Private Sub btnSalir_Click()


Close()
End Sub
End Class
8. Construir una aplicación que permita realizar la cotización de una PC utilizando botones
de opción, casillas, listas (simple y combinada), cajas de texto y botones de comando.

Objeto Propiedades Valor


GroupBox1 Text Mainboard
GroupBox2 Text Microprocesador
GroupBox3 Text Disco Duro
GroupBox4 Text Importes Totales
Label1 Text Memoria RAM
Label2 Text MONITORES
Label3 Text Importe Bruto
Label4 Text I.G.V. (18%)
Label5 Text Importe Neto
RadioButton1 Text Intel 865 GLCL C/S/V/R
RadioButton2 Text Intel D915 GN C/S
RadioButton3 Text Intel D915 GAV C/S/V
RadioButton4 Text Intel Cel. 2.8 Ghz 256K Bus 533
RadioButton5 Text Intel Pentium 2.8 Ghz 1MB(K) B533
RadioButton6 Text Intel Pentium 3.0 Ghz Am(K) B800
RadioButton7 Text H.D. Seagate 80 GB 7200 rpm
RadioButton8 Text H.D. Seagate 120 GB 7200 rpm (SATA)
RadioButton9 Text H.D. Seagate 160 GB Serial ATA 150
CheckBox1 Text Mouse Logitec Optico USB
CheckBox2 Text Teclado Multimedia español
CheckBox3 Text LG Combo 52x32x52 DVD 16X Negro
CheckBox4 Text HP 1510 Multifuncional Conexión Cámara Digital
ListBox1 Items Samsung 15" 591S 1024x768
Samsung 15" LCD 540 N
Samsung 17" 794MB Negro
Samsung 17" LCD 740N 1280x1024
ComboBox1 Items 512 MB DDR2
1024 MB DDR2
2048 MB DDR2
3072 MB DDR2
DropDownStyle DropDownList
Button1 Name btnAceptar
Text &Aceptar
Button2 Name btnNuevo
Text &Nuevo
Button3 Name btnCancelar
Text &Cancelar

Programación de los Controles


Public Class Cotiza_PCs

Private Sub btnNuevo_Click()


TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = ""
ComboBox1.SelectedIndex = -1
ListBox1.SelectedIndex = -1
RadioButton1.Checked = True
RadioButton4.Checked = True
RadioButton7.Checked = True
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
End Sub

Private Sub btnCancelar_Click()


Close()
End Sub

Private Sub btnAceptar_Click()


Dim MA, MI, HD, MR, MT, RA, TE, DVD, HP As Single
Dim BRUTO, IGV, NETO As Single
'***MAinboard***
If RadioButton1.Checked Then MA = 134
If RadioButton2.Checked Then MA = 134
If RadioButton3.Checked Then MA = 134

'***Microprocesador***
If RadioButton4.Checked Then MI = 200
If RadioButton5.Checked Then MI = 250
If RadioButton6.Checked Then MI = 280

'***Disco Duro***
If RadioButton7.Checked Then HD = 40
If RadioButton8.Checked Then HD = 60
If RadioButton9.Checked Then HD = 100

Select Case ComboBox1.SelectedIndex '***Memoria***


Case 0 : MR = 30
Case 1 : MR = 80
Case 2 : MR = 100
Case 3 : MR = 150
End Select

Select Case ListBox1.SelectedIndex '***Monitor***


Case 0 : MT = 30
Case 1 : MT = 80
Case 2 : MT = 100
Case 3 : MT = 150
End Select

'***Accesorios***
If CheckBox1.Checked Then RA = 10
If CheckBox2.Checked Then TE = 15
If CheckBox3.Checked Then DVD = 60
If CheckBox4.Checked Then HP = 350

'***Importes***
BRUTO = MA + MI + HD + MR + MT + RA + TE + DVD + HP
IGV = 0.19 * BRUTO
NETO = BRUTO + IGV

'***Mostrar los Importes***


TextBox1.Text = BRUTO.ToString("#,#00.00")
TextBox2.Text = IGV.ToString("#,#00.00")
TextBox3.Text = NETO.ToString("#,#00.00")

End Sub
End Class
9. Construir una aplicaron para convertir grados centígrados a grados Fahrenheit y
viceversa

Objeto Propiedades Valor


GroupBox1 Text Tipo de Conversión
RadioButton1 Name rbCelFar
Text Centigrados a Farenheit
RadioButton2 Name rbFarCel
Text Farenheit a Centigrados
TextBox1 Name txtGrados
Label1 Name lblDe
Text Grados ºC
Label2 Name lblA
Text Grados ºF
Label3 Name lblResultado
Text
Button1 Name btnConvierte
Text >>
Button1 Name btnCerrar
Text &Cerrar
Programación de los Controles
Public Class frmConversion_Grados

Private Sub btnCerrar_Click()


Close()
End Sub

Private Sub btnConvierte_Click()


Dim Grados, R As Single
Grados = Integer.Parse(txtGrados.Text)
If rbCelFar.Checked = True Then
R = (Grados * 9 / 5) + 32
Else
R = (Grados - 32) * 5 / 9
End If
lblResultado.Text = R.ToString("#,##0.00")
End Sub

Private Sub rbCelFar_Click()


lblDe.Text = "Grados ºC"
lblA.Text = "Grados ºF"
txtGrados.Text = ""
txtGrados.Focus()
End Sub

Private Sub rbFarCel_Click()


lblDe.Text = "Grados ºF"
lblA.Text = "Grados ºC"
txtGrados.Text = ""
txtGrados.Focus()
End Sub

End Class

10. Construir un formulario de Menús utilizando el control MenuStrip


NOTA: Para acceder al contenido de una opción de menú a través de la tecla ALT y la
letra subrayada, deberá escribir el símbolo & delante de la letra. Para crear una barra
separadora en su menú, dar clic derecho sobre la opción de menú que desea separar y luego
escoger Insertar – Separador. Si desea agregar una tecla de acceso rápido utilice la
propiedad ShortcutKeys de la opción de menú e indicar la tecla con la que deseas acceder.
Creación de un Menu Contextual
Un menú contextual es un menú emergente (flotante) que se muestra sobre un formulario,
independiente de la barra de menús. Para mostrar un menú contextual el usuario debe
pulsar el botón derecho del ratón sobre el formulario
Para crear un menú contextual, realiza lo siguiente:
1. Selecciona el control ContextMenuStrip de la caja de
herramientas y colócala en el formulario.
2. Se mostrara el modelo de diseño para tu menú contextual.

3. Posteriormente asigna el menú contextual para el formulario, en su propiedad


ContextMenuStrip.

11. Construir un formulario para obtener Raíces (cuadradas y cúbicas) y Funciones


Trigonométricas (seno, coseno, tangente).
Objeto Propiedades Valor
TextBox1 Name txtDesde
TextBox2 Name txtHasta
Label1 Text Desde
Label2 Text Hasta
Label3 Name lblRango
Text
AutoSize False
BorderStyle Fixed3D
GroupBox1 Text Raíces
GroupBox2 Text Funciones Trigonométricas
Label4 Text Raíz Cuadrada
Label5 Text Raíz Cúbica
Label6 Text Seno
Label7 Text Coseno
Label7 Text Tangente
ListBox1 Name lbRaizCuad
ListBox2 Name lbRaizCub
ListBox3 Name lbSeno
ListBox4 Name lbCoseno
ListBox5 Name lbTang
Button1 Name btnAceptar
Text Aceptar
Button2 Name btnNuevo
Text Nuevo
Button3 Name btnCerrar
Text &Cerrar
Programación de los Controles
Public Class frmLista_Funciones

Private Sub btnAceptar_Click()


Dim I, J, K As Integer
Const PI = 3.1416
I = Integer.Parse(txtDesde.Text)
J = Integer.Parse(txtHasta.Text)
lblRango.Visible = True
lblRango.Text = "Desde: " + Str(I) + " Hasta: " + Str(J)
For K = I To J
lbRaizCuad.Items.Add(Str(K) + " " + Str(Math.Sqrt(K)))
lbRaizCub.Items.Add(Str(K) + " " + Str(K ^ (1 / 3)))
lbSeno.Items.Add(Str(K) + " " + Str(Math.Sin(K * PI / 180)))
lbCoseno.Items.Add(Str(K) + " " + Str(Math.Cos(K * PI / 180)))
lbTang.Items.Add(Str(K) + " " + Str(Math.Tan(K * PI / 180)))
Next
txtDesde.Clear()
txtHasta.Clear()
txtDesde.Focus()
End Sub

Private Sub btnNuevo_Click()


lbRaizCuad.Items.Clear()
lbRaizCub.Items.Clear()
lbSeno.Items.Clear()
lbCoseno.Items.Clear()
lbTang.Items.Clear()
lblRango.Text = ""
lblRango.Visible = False
txtDesde.Focus()
End Sub

Private Sub btnCerrar_Click()


Close()
End Sub

Private Sub txtDesde_KeyPress()


If Asc(e.KeyChar) = 13 Then
txtHasta.Focus()
End If
End Sub

Private Sub txtHasta_KeyPress()


If Asc(e.KeyChar) = 13 Then
btnAceptar.Focus()
End If
End Sub

End Class

12. Construir un programa que permita llenar el control TreeView y que muestre el
elemento seleccionado. Los elementos que se llenan son los códigos de aulas que existen en
cada turno y especialidad

Objeto Propiedades Valor


GroupBox1 Text Información Seleccionada
Label1 Text Nivel
Label2 Text Ruta
Label3 Text Aula
Label4 Name lblNivel
Text
BorderStyle Fixed3D
Label5 Name lblRuta
Text
BorderStyle Fixed3D
Label6 Name lblAula
Text
BorderStyle Fixed3D
TreeView1 Name tvElementos
Button1 Name btnVer
Text &Ver
Button2 Name btnCerrar
Text &Cerrar
Programación de los Controles
Public Class frmTreeView

Private Sub btnVer_Click()


tvElementos.Nodes.Clear()
Dim Padre As TreeNode
Dim Hijo As TreeNode
'**** TURNO MAÑANA ****
Padre = New TreeNode("Mañana")
tvElementos.Nodes.Add(Padre)
'ElemEntos del Turno Mañana
Hijo = Padre.Nodes.Add("Computación")
Hijo.Nodes.Add("CI0513M2")
Hijo.Nodes.Add("CI0515M1")
Hijo.Nodes.Add("CI0511M3")
Hijo = Padre.Nodes.Add("Idiomas")
Hijo.Nodes.Add("ID0511M1")
Hijo.Nodes.Add("ID0513M4")

'**** TURNO TARDE ****


Padre = New TreeNode("Tarde")
tvElementos.Nodes.Add(Padre)
'ElemEntos del Turno Tarde
Hijo = Padre.Nodes.Add("Medicina")
Hijo.Nodes.Add("ME0511T1")
Hijo.Nodes.Add("ME0516T1")
Hijo.Nodes.Add("ME0511T2")
Hijo = Padre.Nodes.Add("Idiomas")
Hijo.Nodes.Add("ID0521T1")
Hijo.Nodes.Add("ID0513T1")
Hijo = Padre.Nodes.Add("Computación")
Hijo.Nodes.Add("CI0514T2")
Hijo.Nodes.Add("CI0515T1")
Hijo.Nodes.Add("CI0516T1")
'**** TURNO NOCHE ****
Padre = New TreeNode("Noche")
tvElementos.Nodes.Add(Padre)
'ElemEntos del Turno Noche
Hijo = Padre.Nodes.Add("Computación")
Hijo.Nodes.Add("CI0513N2")
Hijo.Nodes.Add("CI0515N1")
Hijo.Nodes.Add("CI0511N3")
Hijo = Padre.Nodes.Add("Enfermeria")
Hijo.Nodes.Add("EN0511N1")
Hijo.Nodes.Add("EN0513N4")
Hijo.Nodes.Add("EN0511N2")
End Sub

Private Sub tvElementos_AfterSelect()


lblAula.Text = tvElementos.SelectedNode.Text
lblRuta.Text = tvElementos.SelectedNode.FullPath
lblNivel.Text = tvElementos.SelectedNode.Level
End Sub
Private Sub btnCerrar_Click()
Close()
End Sub
End Class
13. Construir un programa que permita agregar los códigos de aulas en un control ListBox
y luego visualizarlas en dos controles TreeView. En el 1er. TreeView se visualizan
separadas solo por especialidad y en el 2do. Se visualizan separadas por la especialidad y
turno al que pertenece cada aula.

Objeto Propiedades Valor


Label1 Text Especialidad
Label2 Text Ciclo
Label3 Text Grupo
ComboBox1 Name cboEspecialidad
DropDownStyle DropDownList
Ítems Computación, Idiomas, Enfermería
ComboBox2 Name cboCiclo
DropDownStyle DropDownList
Ítems I, II, III, IV, V, VI
ComboBox3 Name cboGrupo
DropDownStyle DropDownList
Ítems 01, 02, 03, 04
GroupBox1 Text Turno
RadioButton1 Name rbMañana
Text Mañana
RadioButton2 Name rbTarde
Text Tarde
RadioButton3 Name rbNoche
Text Noche
Label4 Text Aulas
ListBox1 Name lbAulas
TreeView1 Name tvAulasEsp
TreeView2 Name tvAulasEspTur
Button1 Name btnAgregar
Text &Agregar
Button2 Name btnLlenar1
Text Llenar Nº 1
Button3 Name btnLlenar2
Text Llenar Nº 2
Button4 Name btnCerrar
Text Cerrar
Programación de los Controles
Public Class frmTreeView_Matricula
Private Sub btnAgregar_Click()
If cboEspecialidad.Text = String.Empty Then
MessageBox.Show("Seleccione la Especialidad")
cboEspecialidad.Focus()
Exit Sub
End If
If cboCiclo.Text = String.Empty Then
MessageBox.Show("Seleccione el Ciclo")
cboCiclo.Focus()
Exit Sub
End If
If cbogrupo.Text = String.Empty Then
MessageBox.Show("Seleccione el Grupo")
cbogrupo.Focus()
Exit Sub
End If
If rbMañana.Checked = False And _
rbTarde.Checked = False And _
rbNoche.Checked = False Then
MessageBox.Show("Seleccione el Turno")
Exit Sub
End If
Dim Esp, Cic, Gru, Tur, Aula As String
Select Case cboEspecialidad.SelectedIndex
Case 0 : Esp = "CI"
Case 1 : Esp = "ID"
Case 2 : Esp = "EN"
End Select
Cic = Format(cboCiclo.SelectedIndex + 1, "00")
Gru = Convert.ToString(cbogrupo.SelectedIndex + 1)
If rbMañana.Checked = True Then Tur = "M"
If rbTarde.Checked = True Then Tur = "T"
If rbNoche.Checked = True Then Tur = "N"
Aula = Esp & Tur & Cic & Gru
'Busca la nueva aula
Dim X As Integer
For X = 0 To lbAulas.Items.Count - 1
lbAulas.SelectedIndex = X
If lbAulas.Text = Aula Then
MessageBox.Show("El Aula: " & Aula _
& " ya existe", "Verifique")
Exit Sub
End If
Next
lbAulas.Items.Add(Aula)
End Sub

Private Sub btnLlenar1_Click()


Dim X As Integer
Dim Especialidad As String
tvAulasEsp.Nodes.Clear()
'Agrega los elementos para el TreeView Nº 01 donde
'se separan las aulas solo por Especialidad
tvAulasEsp.Nodes.Add("Computación")
tvAulasEsp.Nodes.Add("Idiomas")
tvAulasEsp.Nodes.Add("Enfermería")
'Llena las aulas
For X = 0 To lbAulas.Items.Count - 1
lbAulas.SelectedIndex = X
Especialidad = lbAulas.Text.Substring(0, 2)
Select Case Especialidad
Case "CI" : tvAulasEsp.Nodes(0).Nodes.Insert(1, 1,
lbAulas.Text)
Case "ID" : tvAulasEsp.Nodes(1).Nodes.Insert(1, 1,
lbAulas.Text)
Case "EN" : tvAulasEsp.Nodes(2).Nodes.Insert(1, 1,
lbAulas.Text)
End Select
Next

End Sub

Private Sub btnLlenar2_Click()


Dim X As Integer, Especialidad, Turno As String
tvAulasEspTur.Nodes.Clear()
'Agrega los elementos para el TreeView Nº 01 donde
'se separan las aulas por Especialidad y Turno
Dim Padre As TreeNode
'**** COMPUTACION ****
Padre = New TreeNode("Computación")
tvAulasEspTur.Nodes.Add(Padre)
Padre.Nodes.Add("Mañana")
Padre.Nodes.Add("Tarde")
Padre.Nodes.Add("Noche")
'**** IDIOMAS ****
Padre = New TreeNode("Idiomas")
tvAulasEspTur.Nodes.Add(Padre)
Padre.Nodes.Add("Mañana")
Padre.Nodes.Add("Tarde")
Padre.Nodes.Add("Noche")
'**** ENFERMERIA ****
Padre = New TreeNode("Enfermería")
tvAulasEspTur.Nodes.Add(Padre)
Padre.Nodes.Add("Mañana")
Padre.Nodes.Add("Tarde")
Padre.Nodes.Add("Noche")
'Llena las aulas
For X = 0 To lbAulas.Items.Count - 1
lbAulas.SelectedIndex = X
Especialidad = lbAulas.Text.Substring(0, 2)
Turno = lbAulas.Text.Substring(2, 1)
Select Case Especialidad
Case "CI" : Select Case Turno
Case "M" :
tvAulasEspTur.Nodes(0).Nodes(0).Nodes.Insert(1, 1, lbAulas.Text)
Case "T" :
tvAulasEspTur.Nodes(0).Nodes(1).Nodes.Insert(1, 1, lbAulas.Text)
Case "N" :
tvAulasEspTur.Nodes(0).Nodes(2).Nodes.Insert(1, 1, lbAulas.Text)
End Select
Case "ID" : Select Case Turno
Case "M" :
tvAulasEspTur.Nodes(1).Nodes(0).Nodes.Insert(1, 1, lbAulas.Text)
Case "T" :
tvAulasEspTur.Nodes(1).Nodes(1).Nodes.Insert(1, 1, lbAulas.Text)
Case "N" :
tvAulasEspTur.Nodes(1).Nodes(2).Nodes.Insert(1, 1, lbAulas.Text)
End Select
Case "EN" : Select Case Turno
Case "M" :
tvAulasEspTur.Nodes(2).Nodes(0).Nodes.Insert(1, 1, lbAulas.Text)
Case "T" :
tvAulasEspTur.Nodes(2).Nodes(1).Nodes.Insert(1, 1, lbAulas.Text)
Case "N" :
tvAulasEspTur.Nodes(2).Nodes(2).Nodes.Insert(1, 1, lbAulas.Text)
End Select
End Select
Next
End Sub
Private Sub btnCerrar_Click()
Application.Exit()
End Sub

End Class

14. Construir un programa que permita llenar un control ListView y mostrar su


información en sus diferentes estilos. También permite mostrar en forma individual el
elemento seleccionado y agregar nuevos elementos. Inserte un control ImageList1 y en su
propiedad Images agregue un grafico.
Objeto Propiedades Valor
Label1 Text Vista
ComboBox1 Name cboVistas
DropDownStyle DropDownList
Ítems Iconos Grandes
Detalle
Iconos Pequeños
Lista
Títulos
Label2 Text Código
Label3 Text Nombre
Label4 Text Sueldo
ImageList1 Name ImageList1
Images <archivo . ICO>
ListView1 Name lvPersonal
LargeImageList ImageList1
SmallImageList ImageList1
Button1 Name btnNuevo
Text &Nuevo
Button2 Name btnGrabar
Text &Grabar
Button3 Name btnIgnorar
Text &Ignorar
Programación de los Controles
Public Class frmListView
Private Sub frmListView_Load()
'Asigna el formato inicial al control ListView
lvPersonal.View = View.Details
lvPersonal.GridLines = True
lvPersonal.FullRowSelect = True
lvPersonal.Columns.Add("Código", 50, HorizontalAlignment.Center)
lvPersonal.Columns.Add("Nombre", 200, HorizontalAlignment.Left)
lvPersonal.Columns.Add("Sueldo", 100, HorizontalAlignment.Right)
'Llena el Personal
Dim Personal As ListViewItem
Personal = New ListViewItem("001", 0)
Personal.SubItems.Add("Julio Dávila")
Personal.SubItems.Add("2,500.00")
lvPersonal.Items.Add(Personal)

Personal = New ListViewItem("002", 0)


Personal.SubItems.Add("Oscar Ruiz")
Personal.SubItems.Add("850.00")
lvPersonal.Items.Add(Personal)

Personal = New ListViewItem("003", 0)


Personal.SubItems.Add("Miguel Saavedra")
Personal.SubItems.Add("1,350.00")
lvPersonal.Items.Add(Personal)

cboVistas.SelectedIndex = 1

'Evita que se modifique el código


txtCodigo.ReadOnly = True

'Llama al procedimiento NoIngresar


NoIngresar()
End Sub

Sub NoIngresar()
txtNombre.ReadOnly = True
txtSueldo.ReadOnly = True
'Activa el boton Nuevo
btnNuevo.Enabled = True
'Desactiva los botones Grabar e Ignorar
btnGrabar.Enabled = False
btnIgnorar.Enabled = False
End Sub

Private Sub btnIgnorar_Click()


txtCodigo.Text = ""
txtNombre.Text = ""
txtSueldo.Text = ""
NoIngresar()
End Sub

Private Sub cboVistas_SelectedIndexChanged()


lvPersonal.View = cboVistas.SelectedIndex
End Sub
Private Sub lvPersonal_Click()
txtCodigo.Text = _
lvPersonal.SelectedItems(0).SubItems(0).Text
txtNombre.Text = _
lvPersonal.SelectedItems(0).SubItems(1).Text
txtSueldo.Text = _
lvPersonal.SelectedItems(0).SubItems(2).Text

End Sub

Private Sub btnNuevo_Click()


'Genera el código del nuevo personal
txtCodigo.Text = Format(lvPersonal.Items.Count + 1, "000")
'Permite escribir el Nombre y Sueldo
txtNombre.ReadOnly = False
txtSueldo.ReadOnly = False
txtNombre.Text = ""
txtSueldo.Text = ""
txtNombre.Focus()
'Desactiva el boton Nuevo
btnNuevo.Enabled = False
'Activa los botones Grabar e Ignorar
btnGrabar.Enabled = True
btnIgnorar.Enabled = True

End Sub

Private Sub btnGrabar_Click()


Dim Codigo, Nombre, Sueldo As String
Dim Personal As ListViewItem
'Asigna los datos ingresados a Variables
Codigo = txtCodigo.Text
Nombre = txtNombre.Text
Sueldo = txtSueldo.Text
'Agrega al control ListView los datos ingresados
Personal = New ListViewItem(Codigo, 0)
Personal.SubItems.Add(Nombre)
Personal.SubItems.Add(Sueldo)
lvPersonal.Items.Add(Personal)
'Llama al procedimiento NoIngresar
NoIngresar()
End Sub
End Class

S-ar putea să vă placă și