Very strange stuff..
-
Ok, I have been messing around with dynamic loading of controls now all day and have a cool example that works, but I am getting some strange results on one area. I am trying to add a way to get messages into the control that I am loading, but I digress. Here is an example of what I have: 1) I have a control that I use as a base (Called CtlBase.BaseControl) and it is defined as such:
Public MustInherit Class BaseControl
Inherits System.Windows.Forms.UserControlPublic Event MessageExit(ByVal OutputMessage As String) Public MustOverride WriteOnly Property MessageEntry(ByVal InputMessage As String) Protected Sub SendEvent(ByVal EventMessage As String) RaiseEvent MessageExit(EventMessage) End Sub
End Class
I have another project that inherits from this base control declared as such:
Public Class Ctl1
Inherits CtlBase.BaseControlPrivate Sub cmdSendEvent\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSendEvent.Click SendEvent(txtSendMessage.Text) End Sub Public Overrides WriteOnly Property MessageEntry(ByVal InputMessage As String) Set(ByVal Value) txtRecvdmessage.Text = Value End Set End Property
End Class
Now, I have another project that is loading the Ctrl1 dynamicaly, tieing up the event that the control exsposes (that is working fine) and trying to assign data to the WriteOnly property that the control exsposes. This app looks like such:
Imports System.Reflection
Public Class Form1
Inherits System.Windows.Forms.FormDim c As Control Dim m As CtlBase.BaseControl Private Sub cmdLoad1\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdLoad1.Click Dim myObj As Object Dim myAssem As System.Reflection.Assembly myAssem = myAssem.LoadFrom("..\\..\\ControlLib\\bin\\ControlLib.dll") myObj = myAssem.CreateInstance("ControlLib.Ctl1") c = CType(myObj, CtlBase.BaseControl) c.Dock = DockStyle.Fill m = DirectCast(c, CtlBase.BaseControl) AddHandler m.MessageExit, AddressOf Ctl\_Click\_Handler pnlMainPanel.Controls.Add(c) End Sub Private Sub Ctl\_Click\_Handler(ByVal Message As String) MessageBox.Show(Message & " : Was received.") End Sub Private Sub cmdCommand\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCommand.Click **m.MessageEnt**
-
Ok, I have been messing around with dynamic loading of controls now all day and have a cool example that works, but I am getting some strange results on one area. I am trying to add a way to get messages into the control that I am loading, but I digress. Here is an example of what I have: 1) I have a control that I use as a base (Called CtlBase.BaseControl) and it is defined as such:
Public MustInherit Class BaseControl
Inherits System.Windows.Forms.UserControlPublic Event MessageExit(ByVal OutputMessage As String) Public MustOverride WriteOnly Property MessageEntry(ByVal InputMessage As String) Protected Sub SendEvent(ByVal EventMessage As String) RaiseEvent MessageExit(EventMessage) End Sub
End Class
I have another project that inherits from this base control declared as such:
Public Class Ctl1
Inherits CtlBase.BaseControlPrivate Sub cmdSendEvent\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSendEvent.Click SendEvent(txtSendMessage.Text) End Sub Public Overrides WriteOnly Property MessageEntry(ByVal InputMessage As String) Set(ByVal Value) txtRecvdmessage.Text = Value End Set End Property
End Class
Now, I have another project that is loading the Ctrl1 dynamicaly, tieing up the event that the control exsposes (that is working fine) and trying to assign data to the WriteOnly property that the control exsposes. This app looks like such:
Imports System.Reflection
Public Class Form1
Inherits System.Windows.Forms.FormDim c As Control Dim m As CtlBase.BaseControl Private Sub cmdLoad1\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdLoad1.Click Dim myObj As Object Dim myAssem As System.Reflection.Assembly myAssem = myAssem.LoadFrom("..\\..\\ControlLib\\bin\\ControlLib.dll") myObj = myAssem.CreateInstance("ControlLib.Ctl1") c = CType(myObj, CtlBase.BaseControl) c.Dock = DockStyle.Fill m = DirectCast(c, CtlBase.BaseControl) AddHandler m.MessageExit, AddressOf Ctl\_Click\_Handler pnlMainPanel.Controls.Add(c) End Sub Private Sub Ctl\_Click\_Handler(ByVal Message As String) MessageBox.Show(Message & " : Was received.") End Sub Private Sub cmdCommand\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCommand.Click **m.MessageEnt**
Change the declaration of the
MessageEntry
property to:Public MustOverride WriteOnly Property MessageEntry As String
Then, in
Ctl
:Public Overrides WriteOnly Property MessageEntry() As String
Set(ByVal Value As String)
txtRecvdmessage.Text = Value
End Set
End PropertyThen, you will be able to use:
m.MessageEntry = txtCommand.Text
Your original declaration was declaring a write-only
String
property which expected a single parameter of typeString
in addition to the value. -
Change the declaration of the
MessageEntry
property to:Public MustOverride WriteOnly Property MessageEntry As String
Then, in
Ctl
:Public Overrides WriteOnly Property MessageEntry() As String
Set(ByVal Value As String)
txtRecvdmessage.Text = Value
End Set
End PropertyThen, you will be able to use:
m.MessageEntry = txtCommand.Text
Your original declaration was declaring a write-only
String
property which expected a single parameter of typeString
in addition to the value.Cool...I'll give it a try when I get back to the office (attic :) ) Thanks...