Eine weitere Möglichkeit wäre, du verwendest "normalen" VB bzw. C# Code und kompilierst diesen mittels Codedom zur LZ. Hier ein kl. Bsp.:
Imports System.CodeDom.Compiler
Imports System.CodeDom
'//
Private Function CreateAssemblyFromCode(ByVal Code As String) As _
System.Reflection.Assembly
Dim cdp As CodeDomProvider = New Microsoft.VisualBasic.VBCodeProvider
Dim comp As ICodeCompiler = cdp.CreateCompiler()
Dim cp As New CompilerParameters
Dim cr As CompilerResults
cp.GenerateInMemory = True
cp.GenerateExecutable = False
cp.ReferencedAssemblies.Add("System.Windows.Forms.dll")
cp.ReferencedAssemblies.Add("System.Drawing.dll")
cp.ReferencedAssemblies.Add("System.dll")
cr = comp.CompileAssemblyFromSource(cp, Code)
If cr.Errors.Count <> 0 Then
For A As Integer = 0 To cr.Errors.Count - 1
Debug.WriteLine(cr.Errors(A).ToString())
Next
Return Nothing
Else
Return cr.CompiledAssembly
End If
End Function
Public Sub ShowForm(ByVal Code As String)
Dim ASM As System.Reflection.Assembly = CreateAssemblyFromCode(Code)
Dim O As Object = ASM.CreateInstance("myForms.myForm")
Dim T As Type = O.GetType()
Dim MI As System.Reflection.MethodInfo = T.GetMethod("Show", New Type() _
{})
MI.Invoke(O, New Object() {})
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button15.Click
Dim code As String = New IO.StreamReader("C:\Temp\Form.txt").ReadToEnd
Me.ShowForm(code)
End SubCode der Form.txt:Namespace myForms
Public Class myForm
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button2 = New System.Windows.Forms.Button
Me.SuspendLayout()
Me.Button1.Location = New System.Drawing.Point(8, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(472, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Test"
Me.TextBox1.Location = New System.Drawing.Point(8, 40)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(472, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "TextBox1"
Me.Button2.Location = New System.Drawing.Point(344, 72)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(136, 24)
Me.Button2.TabIndex = 2
Me.Button2.Text = "Close"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(488, 101)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form3"
Me.Text = "Form3"
Me.ResumeLayout(False)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
Me.TextBox1.Text = "Hello World!"
End Sub
End Class
End Namespace (Dies ist aber nur ein sehr einfaches Bsp. Ob diese Technik bei komplexen Programmen/Formularen empfehlenswert ist, bezweifle ich einfach mal. Soll eher eine Inspiration sein... ) |