This document contains code snippets in Visual Basic for two exercises. The first exercise code handles moving and changing the color of a text box when different option buttons are clicked. The second exercise code handles changing the background and foreground color of a label using color pickers, storing the selected colors in variables, and switching between background and foreground colors.
1 of 4
Download to read offline
More Related Content
clase visual basic
1. 1 VISUAL BASIC
11 de julio de 2016
EJERCICIO APLICATIVO N? 5
Private Sub Form_Load()
txtCaja.Top = 0
End Sub
Private Sub optArriba_Click()
txtCaja.Top = 0
End Sub
Private Sub optAbajo_Click()
txtCaja.Top = frmColores0.ScaleHeight - txtCaja.Height
End Sub
Private Sub optAzul_Click()
txtCaja.BackColor = vbBlue
End Sub
Private Sub optRojo_Click()
txtCaja.BackColor = vbRed
End Sub
Private Sub optVerde_Click()
txtCaja.BackColor = vbGreen
End Sub
2. 2 VISUAL BASIC
11 de julio de 2016
Private Sub optAmarillo_Click()
txtCaja.BackColor = vbYellow
End Sub
EJERCICIO APLICATIVO N? 6
Option Explicit
Public Brojo, Bverde, Bazul As Integer
Public Frojo, Fverde, Fazul As Integer
Private Sub cmdSalir_Click()
End
End Sub
Private Sub Form_Load()
Brojo = 0
Bverde = 0
Bazul = 0
Frojo = 255
Fverde = 255
Fazul = 255
lblCuadro.BackColor = RGB(Brojo, Bverde, Bazul)
3. 3 VISUAL BASIC
11 de julio de 2016
lblCuadro.ForeColor = RGB(Frojo, Fverde, Fazul)
End Sub
Private Sub hsbColor_Change(Index As Integer)
If optColor(0).Value = True Then
lblCuadro.BackColor = RGB(hsbColor(0).Value,
hsbColor(1).Value, _
hsbColor(2).Value)
Dim i As Integer
For i = 0 To 2
txtColor(i).Text = hsbColor(i).Value
Next i
Else
lblCuadro.ForeColor = RGB(hsbColor(0).Value,
hsbColor(1).Value, _
hsbColor(2).Value)
For i = 0 To 2
txtColor(i).Text = hsbColor(i).Value
Next i
End If
End Sub
Private Sub optColor_Click(Index As Integer)
If Index = 0 Then 'Se pasa a cambiar el fondo
Frojo = hsbColor(0).Value
Fverde = hsbColor(1).Value
Fazul = hsbColor(2).Value
hsbColor(0).Value = Brojo
hsbColor(1).Value = Bverde
hsbColor(2).Value = Bazul
Else 'Se pasa a cambiar el texto
Brojo = hsbColor(0).Value
Bverde = hsbColor(1).Value
Bazul = hsbColor(2).Value
hsbColor(0).Value = Frojo
hsbColor(1).Value = Fverde
hsbColor(2).Value = Fazul
End If
End Sub
4. 4 VISUAL BASIC
11 de julio de 2016
EJERCICIO APLICATIVO N? 7
End if
End sub