' System.Design.dll の参照が必要
Option Infer On
Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.Serialization
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents Button1 As Button
Private WithEvents FlowLayoutPanel1 As FlowLayoutPanel
Private WithEvents TextBox1 As TextBox
Private WithEvents PropertyGrid1 As PropertyGrid
Public Sub New()
Me.InitializeComponent()
End Sub
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.FlowLayoutPanel1 = New System.Windows.Forms.FlowLayoutPanel()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.PropertyGrid1 = New System.Windows.Forms.PropertyGrid()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(5, 348)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'FlowLayoutPanel1
'
Me.FlowLayoutPanel1.Location = New System.Drawing.Point(5, 62)
Me.FlowLayoutPanel1.Name = "FlowLayoutPanel1"
Me.FlowLayoutPanel1.Size = New System.Drawing.Size(116, 280)
Me.FlowLayoutPanel1.TabIndex = 2
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(5, 14)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(100, 19)
Me.TextBox1.TabIndex = 3
'
'PropertyGrid1
'
Me.PropertyGrid1.Location = New System.Drawing.Point(127, 14)
Me.PropertyGrid1.Name = "PropertyGrid1"
Me.PropertyGrid1.SelectedObject = Me.TextBox1
Me.PropertyGrid1.Size = New System.Drawing.Size(287, 328)
Me.PropertyGrid1.TabIndex = 4
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(427, 383)
Me.Controls.Add(Me.PropertyGrid1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.FlowLayoutPanel1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim container As New ServiceContainer()
Dim manager As New DesignerserializationManager(container)
Dim service As New CodeDomComponentSerializationService(manager)
Dim store = service.CreateStore()
service.Serialize(store, Me.TextBox1)
store.Close()
Dim collection = service.Deserialize(store)
Dim textBox2 = DirectCast(collection(0), TextBox)
Me.FlowLayoutPanel1.Controls.Add(textBox2)
End Sub
End Class