Author Topic: User control help  (Read 3631 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: User control help
« Reply #15 on: April 21, 2017, 02:23:33 PM »
I posted another project that uses a UserControl and the same code that you posted (only changed to match .NET patterns and practices):

https://sourceforge.net/projects/advancedhmi/files/advancedhmi/3.5/SampleProjects

Phrog30

  • Guest
Re: User control help
« Reply #16 on: April 21, 2017, 03:18:04 PM »
Thanks for posting Archie.  The issue with your example is each instance needs code for the count, which is what I'm trying to eliminate.  The goal is to mimic the PV+ and global objects.  So, I just started with a simple button that I could drop on a form and it would work.  The only way I could get it to work was to use a timer to "poll" the value, instead of the value getting "pushed" to each instance.  I just didn't like using a timer but I guess I will have to live with it.

Thanks again,
James

Phrog30

  • Guest
Re: User control help
« Reply #17 on: April 21, 2017, 03:49:05 PM »
Here is a very crude example of what I am trying to achieve.  The 3 buttons on the form have no code.  I just dropped them and they work.  The issue, the user control uses a timer to get the values, which I think is clunky.  But, it works.  I know experienced guys would laugh at this, but with my experience that's the best I could come up with.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: User control help
« Reply #18 on: April 22, 2017, 03:21:55 PM »
Now I understand what you are trying to do. This is referred to as Binding. Unfortunately WinForms lacks a graceful way to bind properties between 2 object without writing code(WPF does this nicely). There are a couple ways to go about this. One would be to use an Application Setting to hold the Count value. After you add an object to the form, in the Properties Window at the top is a section named "(Application Settings)". You can drill into this to create a new application setting and link it to the property of choice. So let's say you create a setting named AlarmCount. In your code, you would manipulate the value as such:

My.Settings.AlarmCount = 0

If you binded this to a property, when the value changes it will automatically push the new value into the property also. This is a similar technique where I demonstrated how to mimic tags as done in other HMI software.

Another method for binding that is a bit more complicated is to add properties to your object to specify the control to bind to and the property. Attached is a modified version of your project showing this technique. In design view, if you select the NavActiveAlarm and look at the Properties, you will see where I added DataBindingSource and DataBindingProperty. In the example, I set those to TextBox1 and Text. I also added ImageNoAlarm and ImageAlarm properties. These added properties create a re-usable control in which different instances can be bound to different values.

Phrog30

  • Guest
Re: User control help
« Reply #19 on: April 22, 2017, 05:08:06 PM »
Thanks, I will look at what you did later this evening.  I'm sorry I didn't explain myself well.  I tend to do a crap job explaining things.

James