Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Very strange stuff..

Very strange stuff..

Scheduled Pinned Locked Moved Visual Basic
tutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ray Cassick
    wrote on last edited by
    #1

    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.UserControl

    Public 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.BaseControl

    Private 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.Form

    Dim 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**
    
    Richard DeemingR 1 Reply Last reply
    0
    • R Ray Cassick

      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.UserControl

      Public 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.BaseControl

      Private 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.Form

      Dim 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**
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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 Property

      Then, 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 type String in addition to the value.

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      R 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        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 Property

        Then, 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 type String in addition to the value.

        R Offline
        R Offline
        Ray Cassick
        wrote on last edited by
        #3

        Cool...I'll give it a try when I get back to the office (attic :) ) Thanks...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups