Quiero pasar un control completo a otro formulario.
En este caso se trata de un Picturebox. Sé que el otro formulario se va a mostrar solamente una imagen.
Se podría haber hecho de otra forma si solo es pasar una imagen.
Ambos formularios están vacíos, los controles se crean en tiempo de ejecución.
El primer problema que me encontré fue instanciar el control en el formulario destino.
Ese control que se le pasa con una propiedad, ya tiene valores. No es nuevo.
Imaginar que no tiene por que ser un PictureBox, lo que queréis pasarle, conociendo los tipos de controle que quieres pasar.
Se instanciaría un tipo determinado.
Me gustaría saber si creéis que el código del formulario destino se puede mejorar.
Formulario origen:
Private dibujo As Picture
Private picejemplo As Picturebox
Private unformulario As FormDestino
Public Sub Form_Open()
dibujo = Picture["Gambas3.png"]
With Me
.Title = "Origen"
.Arrangement = Arrange.Vertical
.AutoResize = True
End With
picejemplo = New PictureBox(Me) As "manejador"
With picejemplo
.W = dibujo.W
.H = dibujo.H
.Picture = dibujo
End With
unformulario = New FormDestino
unformulario.objeto = picejemplo
unformulario.Show()
End
Private picejemplo As Picturebox
Private unformulario As FormDestino
Public Sub Form_Open()
dibujo = Picture["Gambas3.png"]
With Me
.Title = "Origen"
.Arrangement = Arrange.Vertical
.AutoResize = True
End With
picejemplo = New PictureBox(Me) As "manejador"
With picejemplo
.W = dibujo.W
.H = dibujo.H
.Picture = dibujo
End With
unformulario = New FormDestino
unformulario.objeto = picejemplo
unformulario.Show()
End
Formulario Destino:
Private $objeto As Object
Property objeto As Object
Public Sub Form_Open()
Dim opbox As PictureBox
With Me
.Title = "Destino"
.Arrangement = Arrange.Vertical
.AutoResize = True
End With
If Me.objeto Is PictureBox Then
opbox = New PictureBox(Me) As "manejador"
With opbox
.W = Me.objeto.w
.H = Me.objeto.h
.Picture = Me.objeto.Picture
End With
Endif
End
Private Function objeto_Read() As Object
Return $objeto
End
Private Sub objeto_Write(Value As Object)
$objeto = Value
End
Property objeto As Object
Public Sub Form_Open()
Dim opbox As PictureBox
With Me
.Title = "Destino"
.Arrangement = Arrange.Vertical
.AutoResize = True
End With
If Me.objeto Is PictureBox Then
opbox = New PictureBox(Me) As "manejador"
With opbox
.W = Me.objeto.w
.H = Me.objeto.h
.Picture = Me.objeto.Picture
End With
Endif
End
Private Function objeto_Read() As Object
Return $objeto
End
Private Sub objeto_Write(Value As Object)
$objeto = Value
End
Aquí tenéis el ejemplo.
Saludos