viernes, 7 de julio de 2017

Control personalizado


Aquí les dejo mi experimento en la creación de una clase o control personalizado, a medida para un fin x. El código esta en la granja.


' gambas class file

Export

Inherits UserControl

Public Const _Properties As String = "*,Texto,Seleccion,Hombre=True"
Public Const _DefaultEvent As String = "Eleccion"
Public Const _DefaultSize As String = "36,4"

Event Eleccion

Property Seleccion As Boolean
Property Texto As String
Property Hombre As Boolean

Private $Seleccion As Boolean
Private $Texto As String
Private $Hombre As Boolean

Private $hFondo As DrawingArea
Private $TextLabel As TextLabel
Private $CheckBox As CheckBox
Private $Persona As PictureBox

Public Sub _new()

$hFondo = New DrawingArea(Me) As "Fondo"
$hFondo.Background = &HFFEFBF
$hFondo.Arrangement = Arrange.Horizontal

$CheckBox = New CheckBox($hFondo) As "Check"
$CheckBox.Width = 20
$CheckBox.AutoResize = True
$CheckBox.Background = &HD2DFC3

$TextLabel = New TextLabel($hFondo) As "TexLabel"
$TextLabel.Alignment = Align.Center
$TextLabel.Expand = True
$TextLabel.Background = &HFFEFBF

$Persona = New PictureBox($hFondo) As "Persona"
Hombre_Write(True)
$Persona.Width = 40
$Persona.Stretch = True
$Persona.AutoResize = True

End

Public Sub Fondo_Enter()

$hFondo.Background = &H00FFFF

End

Public Sub Fondo_Leave()

$hFondo.Background = &HFFEFBF

End


Public Sub TexLabel_Enter()

$TextLabel.Tooltip = Me.Name

End

Public Sub TexLabel_MouseUp()

$CheckBox.Value = Not $CheckBox.Value

End

Public Sub Persona_MouseUp()

$CheckBox.Value = Not $CheckBox.Value

End


Public Sub Check_Click()

$Seleccion = $CheckBox.Value
Raise Eleccion

End

Private Function Seleccion_Read() As Boolean

Return $Seleccion

End

Private Sub Seleccion_Write(Value As Boolean)

$Seleccion = Value

End

Private Function Texto_Read() As String

$Texto = $TextLabel.Text
Return $Texto

End

Private Sub Texto_Write(Value As String)

$Texto = Value
$TextLabel.Text = $Texto

End

Private Function Hombre_Read() As Boolean

Return $Hombre

End

Private Sub Hombre_Write(Value As Boolean)

$Hombre = Value

If $Hombre Then
$Persona.Picture = Picture.Load("hombre.png")
Else
$Persona.Picture = Picture.Load("mujer.png")
Endif

End


No hay comentarios.:

Publicar un comentario