Author Topic: Form visible  (Read 843 times)

blaisbb

  • Newbie
  • *
  • Posts: 6
    • View Profile
Form visible
« on: February 28, 2019, 12:48:45 PM »
Can I have a form becoming visible toggle a bit in PLC?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form visible
« Reply #1 on: February 28, 2019, 02:08:17 PM »
A couple ways to go about this. My preferred method is using the MainMenu style application and put a DataSubscriber on the MainMenu form. In the DataChanged event handler, show the appropriate form. This is an example from a project I did where the PLC had an integer to set for which form to show:
Code: [Select]
    Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles ScreenSelectDataSubscriber.DataChanged
        Try
            If e.ErrorId = 0 AndAlso e.Values.Count > 0 Then
                Select Case e.Values(0)
                    Case 1 : RecipeQueButton.PerformClick()
                    Case 2 : MixTableButton.PerformClick()
                    Case 3 : HopperInitializeButton.PerformClick()
                    Case 4 : BarcodeButton.PerformClick()
                    Case 5 : WeighUpButton.PerformClick()
                    Case 10 : OptionalMaterialButton.PerformClick()

                End Select
            End If
        Catch ex As Exception
        End Try
    End Sub

You can do something similar in the form you want to hide or show, but you will not be able to pause the updating when the form is hidden which means you will have excess communications to update a hidden form.

blaisbb

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Form visible
« Reply #2 on: February 28, 2019, 02:41:24 PM »
I was thinking of creating an InvisibleButton on the form and then using the forms Load Event to InvisibleButton_Click.
That does not seem to work however.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form visible
« Reply #3 on: February 28, 2019, 03:23:15 PM »
Add a DataSubscriber to the form
Set PLCAddressValue to a Boolean address
Double click the DataSubscriber to get back to code
Enter this code:
Code: [Select]
Me.Visible=e.Values(0)

blaisbb

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Form visible
« Reply #4 on: March 01, 2019, 01:38:43 PM »
I ended up replacing the FormChangeButtons on the MainMenu with AvancedHMI.BasicButton and toggle the PLC bits by assigning them in the properties as usual. I then made the necessary forms visible in the code as BasicButton_Click and showing or hiding the forms as necessary. I did however have to hide the MainButton under a new BasicButton I created for the MainForm. When I deleted The MainButton, the forms would not show properly.
Thanks