Author Topic: Adding Existing Controls as Members of New Control  (Read 1846 times)

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Adding Existing Controls as Members of New Control
« on: October 18, 2024, 07:37:42 PM »
Howdy all!

Say I have a brand new AdvancedHMI project. I have a MainForm.

From here, I go to the AdvancedHMIControls section of the solution, and I make a new directory. Inside of that directory, I make a new User Control. Inside of that new User Control, I add a PilotLight3Color.

That PilotLight3Color has a ComComponent (settable via GUI or tt) that automatically gets inherited from whatever is available when placed by GUI. That ComComponent is also automatically created if I use the GUI to add a new PilotLight3Color to my new UserControl. How can I make that automatically generated ComComponent be the same object as something I pass in via the GUI?

Say that my UserControl instead has five PilotLight3Colors - how can I make "ComComponent" a member that is both accessible from the GUI interface, but also "overrides" all member versions of the ComComponent. Better than that, how can I make a Control that combines multiple AdvancedHMI controls that all require a PLCAddress and/or PLCAddressItem?

Thank you all for your time! I hope this makes any kind of sense. Please let me know if you need any clarification about what I'm asking!

« Last Edit: October 18, 2024, 07:44:56 PM by bobbh95 »

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Adding Existing Controls as Members of New Control
« Reply #1 on: October 18, 2024, 08:37:35 PM »
As an example:

New user control, with both a SevenSegment2 and also a PilotLight3Color. I want both of these (the SevenSegment2 and the PilotLight3Color) to be both settable via the GUI/code, but also to automatically override the defaults, if/how possible.

Thank you all!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Adding Existing Controls as Members of New Control
« Reply #2 on: October 22, 2024, 03:39:19 PM »
If I understand correctly, you can create properties in the User Control that expose the properties of the contained components.
[/code]
    Public Property PilotLightComComponent As MfgControl.AdvancedHMI.Drivers.IComComponent
        Get
            Return PilotLight3Color1.ComComponent
        End Get
        Set(value As IComComponent)
            PilotLight3Color1.ComComponent = value
        End Set
    End Property
Code: [Select]

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Adding Existing Controls as Members of New Control
« Reply #3 on: October 22, 2024, 07:33:04 PM »
Hey Archie, thanks for responding once again!

I can see that that's possible - but is there a way to override multiple controls simultaneously, and also automatically?

When I am creating a UserControl, and I insert a PilotLight3Color, for example, it automatically creates a ComComponent for me. It then automatically routes all of the individual "sub-controls" to the automatically generated ComComponent.

This is similar to how you can graphically add a PilotLight3Color to the Design window of a WinForm, and it will automatically route to the ComComponent (if already available) in the Form. I would like to be able to make a new component that contains multiple PilotLight3Color (simply as an example) and have them all point to the same tag.

I can upload an example here shortly.
« Last Edit: October 22, 2024, 07:48:43 PM by bobbh95 »

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Adding Existing Controls as Members of New Control
« Reply #4 on: October 22, 2024, 07:40:53 PM »
For example:

Say I put both this PilotLight3Color and this ChartByLogging control into a new user control. As soon as I add either of them via the GUI, the EthernetIPforCLXcom1 component is automatically created in the Control Design window. How can I go about making the PilotLight3Color and the ChartByLogging automatically look at and subscribe to the ComComponent that is already created in the parent window?



Would I do something to the effect of:

Code: [Select]
    Private m_ComComponent As MfgControl.AdvancedHMI.Drivers.IComComponenet
    Public Property ComComponent As MfgControl.AdvancedHMI.Drivers.IComComponent
        Get
            Return m_ComComponent
        End Get
        Set(value As IComComponent)
            PilotLight3Color1.ComComponent = value
            ChartByLogging1.ComComponent = value
            ' ... until necessary for all sub-controls
            m_ComComponent = value
        End Set
    End Property

and then that would just be the end of the story? Would that automatically set all of the ComComponents for all the sub-controls inside of the UserControl?

Thanks again!



Edit:= Do I need to delete the automatically generated EthernetIPforCLXcom1 inside of the UserControl? If so, how do I refer to the one that I'm pointing to? Do I use reflection? Or do I pass it in as an argument to the class?
« Last Edit: October 22, 2024, 07:54:06 PM by bobbh95 »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Adding Existing Controls as Members of New Control
« Reply #5 on: October 22, 2024, 09:08:40 PM »
Maybe also check the following topic to see if it might help you any:

  https://www.advancedhmi.com/forum/index.php?topic=2132.0

« Last Edit: October 23, 2024, 05:59:50 PM by Godra »

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Adding Existing Controls as Members of New Control
« Reply #6 on: October 25, 2024, 09:22:05 PM »
Hey Godra!

Thanks for chiming in~ I always love seeing anything you say, it's always on point.

I get what you're saying in the other thread about it being... not necessarily necessary. I think in this case it is, though. That said, I also see the two examples you provided.

Am I to understand that the basic idea is to make the constructor create a bunch of Friend WithEvent objects to represent all of the sub-components of the NewControl, as well as assigning all of the appropriate default properties to all of the said components? Also adding those objects to the Controls collection of the NewControl, and setting up all of the Public Property (in the format of your examples) to make them viewable in the Properties pane of the Design Window?

If so, you're top tier. I love that you've not only given me everything I need to solve this problem, but you haven't given me the solution directly. Edit: <- To be perfectly clear, THIS IS NOT SARCASM, I AM BEING PERFECTLY HONEST HERE, PLEASE DON'T TAKE THIS WRONGLY

I'll be back.

Edit 2: I've also already (short term) solved this problem by doing a mix of what you prescribed initially in the other thread and what I was trying to do. I made a control with the layout I wanted, then in the MainForm assigned all of the necessary values (including the ComComponent values) and then added them to the necessary Controls collection.

Sometimes I have to make a form with 300+ similar controls though, and going through and manually assigning all of the tag values for 1k+ LEDs is... painful.

(Right now I have something to the effect of

Code: [Select]
For Each tag in TagList
    control.SimpleLED1.PLCAddress = tag_base & tag_ending1
    control.SimpleLED2.PLCAddress = tag_base & tag_ending2
    control.SevenSegment21.PLCAddress = tag_base & whimsical_ending
« Last Edit: October 25, 2024, 09:53:20 PM by bobbh95 »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Adding Existing Controls as Members of New Control
« Reply #7 on: October 26, 2024, 01:39:40 AM »
I doubt that anyone is going to provide any direct solution for you, mainly because of the fact that you are trying to create a custom control.

Since you are the only person who knows your setup and your code then it's only you who can solve this.
Just make sure to test your solution thoroughly before you deploy it.

If you can stick with using the GroupBox that might just produce the least headache.