locked
How do I pass a Form.TabControl to an external Dll ? RRS feed

  • Question

  • Hi Guys I've been searching for ages and can't find the solution to my problem anywhere...

    I have a working VB application with a simple Form containing a menu strip, a Tab Control and a groupBox with a textBox inside. The groupBox and textBox are just used to display status information.

    Everything worked as required (That was until I tried to separate my class modules from the main application into individual dll's ) to allow cross application use of the same functions

    When my project starts, It lists all the dll's it finds in its library folder in the menu strip. I'm faking this at the moment but intend extracting a function title collection from each of the dll's, pre-selection (any suggestions on achieving this would be a Bonus!) for now the Dll's only contain one public class but may contain multiple public classes in the future!

    As It is, Clicking on the menu strip, dynamically loads the selected dll using the following code...

    Dim oAssembly As System.Reflection.Assembly = Assembly.LoadFile(szFileName)
    Dim oType As System.Type = oAssembly.GetType(oAssembly.GetExportedTypes(0).FullName)
    Dim oObject As System.Object = Activator.CreateInstance(oType)

    This all works and I can display dialog's/Message Box's directly from the dll.

    The problem is, I can't find/figure out how to give the dll access to populate a tabControl with specific controls. i.e one of my dll's displays a folder requester and uses the selected folder to populate a treeView with all the subFolders and files there-in

    In my original project displaying the treeView was easy, Using a dynamic dll has got me stumped...

    I'm using public sub new() in the dll to create the desired layout for each of the dll's, and all other functionality is Private to the dll.

    Any help/Ideas would be most appreciated.

    Alan


    Tuesday, February 4, 2020 3:09 AM

Answers

  • Thanks Xingyu

    Yeah I found those references also, not very helpful :(

    I figured it out, Although I'm sure I tried this before and it didn't work hence requirement of unsuccessfully exploring alternative options?

    All I needed to do was...

    '*** CHANGE THIS LINE *** Dim oObject As System.Object = Activator.CreateInstance(oType)

    '*** TO THIS LINE *** Dim oObject As System.Object = Activator.CreateInstance(oType, TabControl)

    then in my DLL constructor, use it as a passed parameter.

    and it worked!


    Thursday, February 6, 2020 9:09 PM

All replies

  • Hi Alan_Barclay_Uk,

    Thank you for posting here.

    According to your question, I find some references.

    1. Access windows forms controls from external DLLs in C#
    2. Pass .net Form as parameter to dll
    3. VB.NET Using Interface, Reflection, and DLL to Access Main Form Controls Properties

    Hope them could be helpul.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 5, 2020 7:31 AM
  • Thanks Xingyu

    Yeah I found those references also, not very helpful :(

    I figured it out, Although I'm sure I tried this before and it didn't work hence requirement of unsuccessfully exploring alternative options?

    All I needed to do was...

    '*** CHANGE THIS LINE *** Dim oObject As System.Object = Activator.CreateInstance(oType)

    '*** TO THIS LINE *** Dim oObject As System.Object = Activator.CreateInstance(oType, TabControl)

    then in my DLL constructor, use it as a passed parameter.

    and it worked!


    Thursday, February 6, 2020 9:09 PM