Eduardo Morcillo: Gracias por explicarme cómo hacer el
editor de tipos en Visual Basic .Net. Llevaba un buen
tiempo buscando la manera y de no ser por ti, así
estuviera todavía: Buscando.
Ya logré hacer que se muestre el editor y funciona casi a
la perfección, el casi es que no logro hacer que recuerde
su valor. Por ejemplo, la estructura tiene dos
propiedades que son Entero y Cadena cuyos valores
iniciales son 0 y "", si le asigno valores de 33 y "Mi
Nombre" respectivamente en la ventana de propiedades, y
después cierro la solución, al abrir nuevamente la
solución, los valores son 0 y "".
Por último, una pregunta: ¿Tomaste un curso con
Microsoft, trabajas(te) para ellos o dónde conseguiste
toda esa información que tienes sobre VB Net?
Te dejo el código de lo que estoy haciendo por si es que
puedes ayudarme otra vez.
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Design
CONTROLX
Public Class ControlX
Inherits System.Windows.Forms.UserControl
Private p As New Prueba("Vacío", 88)
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form
Designer.
InitializeComponent()
'Add any initialization after the
InitializeComponent() call
End Sub
'UserControl overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
'
'ControlX
'
Me.BackColor = System.Drawing.Color.FromArgb(CType
(192, Byte), CType(0, Byte), CType(0, Byte))
Me.Font = New System.Drawing.Font("Trebuchet MS",
9.75!, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "ControlX"
Me.Size = New System.Drawing.Size(200, 200)
End Sub
#End Region
Public Property MiPrueba() As Prueba
Get
Return p
End Get
Set(ByVal Valor As Prueba)
p = Valor
End Set
End Property
End Class
ESTRUCTURA
<TypeConverter(GetType(ExpandableObjectConverter)), Editor
(GetType(MiEditor), GetType(UITypeEditor))> _
Public Structure Prueba
Private MiTexto As String
Private MiEntero As Integer
#Region " Constructor y propiedades"
Public Sub New(ByVal t As String, ByVal i As Integer)
MiTexto = t
MiEntero = i
End Sub
Public Property Texto() As String
Get
Return MiTexto
End Get
Set(ByVal Valor As String)
MiTexto = Valor
End Set
End Property
Public Property Entero() As Integer
Get
Return MiEntero
End Get
Set(ByVal Valor As Integer)
MiEntero = Valor
End Set
End Property
#End Region
End Structure
FORMULARIO
Public Class Form1
Inherits System.Windows.Forms.Form
Private MiPrueba As Prueba
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form
Designer.
InitializeComponent()
'Add any initialization after the
InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component
list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnAceptar As
System.Windows.Forms.Button
Friend WithEvents btnCancelar As
System.Windows.Forms.Button
Friend WithEvents txtTexto As
System.Windows.Forms.TextBox
Friend WithEvents txtEntero As
System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.txtTexto = New System.Windows.Forms.TextBox
Me.btnAceptar = New System.Windows.Forms.Button
Me.btnCancelar = New System.Windows.Forms.Button
Me.txtEntero = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'txtTexto
'
Me.txtTexto.Location = New System.Drawing.Point
(64, 40)
Me.txtTexto.Name = "txtTexto"
Me.txtTexto.Size = New System.Drawing.Size(144,
20)
Me.txtTexto.TabIndex = 0
Me.txtTexto.Text = "Texto"
'
'btnAceptar
'
Me.btnAceptar.BackColor =
System.Drawing.Color.Lime
Me.btnAceptar.DialogResult =
System.Windows.Forms.DialogResult.OK
Me.btnAceptar.Location = New System.Drawing.Point
(24, 192)
Me.btnAceptar.Name = "btnAceptar"
Me.btnAceptar.TabIndex = 1
Me.btnAceptar.Text = "Aceptar"
'
'btnCancelar
'
Me.btnCancelar.BackColor =
System.Drawing.Color.Red
Me.btnCancelar.DialogResult =
System.Windows.Forms.DialogResult.Cancel
Me.btnCancelar.ForeColor =
System.Drawing.Color.White
Me.btnCancelar.Location = New System.Drawing.Point
(144, 192)
Me.btnCancelar.Name = "btnCancelar"
Me.btnCancelar.TabIndex = 2
Me.btnCancelar.Text = "Cancelar"
'
'txtEntero
'
Me.txtEntero.Location = New System.Drawing.Point
(64, 96)
Me.txtEntero.Name = "txtEntero"
Me.txtEntero.TabIndex = 3
Me.txtEntero.Text = "0"
'
'Form1
'
Me.AcceptButton = Me.btnAceptar
Me.AutoScaleBaseSize = New System.Drawing.Size(5,
13)
Me.CancelButton = Me.btnCancelar
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.txtEntero)
Me.Controls.Add(Me.btnCancelar)
Me.Controls.Add(Me.btnAceptar)
Me.Controls.Add(Me.txtTexto)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Public Property Probar() As Prueba
Get
MiPrueba = New Prueba(Me.txtTexto.Text,
Me.txtEntero.Text)
Return MiPrueba
End Get
Set(ByVal Valor As Prueba)
MiPrueba = Valor
End Set
End Property
Private Sub Cerrar(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnAceptar.Click,
btnCancelar.Click
MiPrueba.Texto = Me.txtTexto.Text
MiPrueba.Entero = Convert.ToInt32
(Me.txtEntero.Text)
Me.Close()
End Sub
End Class
Imports System.Windows.Forms.Design
Public Class MiEditor
Inherits System.Drawing.Design.UITypeEditor
Dim f As New Form1
Public Overloads Overrides Function GetEditStyle
(ByVal context As
System.ComponentModel.ITypeDescriptorContext) As
System.Drawing.Design.UITypeEditorEditStyle
Return
System.Drawing.Design.UITypeEditorEditStyle.Modal
End Function
Public Overloads Overrides Function EditValue(ByVal
context As System.ComponentModel.ITypeDescriptorContext,
ByVal provider As System.IServiceProvider, ByVal valor As
Object) As Object
Dim MiEditor As IWindowsFormsEditorService
MiEditor = CType(provider.GetService(GetType
(IWindowsFormsEditorService)), IWindowsFormsEditorService)
f.txtTexto.Text = CType(valor, Prueba).Texto
f.txtEntero.Text = CType(valor, Prueba).Entero
MiEditor.ShowDialog(f)
If f.DialogResult = Windows.Forms.DialogResult.OK
Then
Return f.Probar
Else
Return valor
End If
End Function
End Class
Leer las respuestas