AdvancedHMI Software
General Category => Support Questions => Topic started by: Phrog30 on May 11, 2017, 09:28:15 AM
-
Is there a way to call a form in the AHMI application from the AHMIcontrols application? Will I have to create the form in the controls application to make this work?
James
-
Can you give an example of what you want to do? Are you trying to do something like open a form from clicking on a BasicLabel?
-
I've created a custom message box that I want to use, it's used to display security rights. It will be called on a custom button, on click event if the user doesn't have rights it will call this form. I took your basic button and added security to it.
-
You can add a property to point to a form:
Private m_FormToOpen as Form
Public Property FormToOpen as Form
Get
Return m_FormToOpen
End Get
Set (value as Form)
m_FormToOpen=value
End Set
End Property
then in the Click event handler:
If m_FormToOpen isnot Nothing then
m_FormToOpen.Show
End If
-
You can add a property to point to a form:
Private m_FormToOpen as Form
Public Property FormToOpen as Form
Get
Return m_FormToOpen
End Get
Set (value as Form)
m_FormToOpen=value
End Set
End Property
then in the Click event handler:
If m_FormToOpen isnot Nothing then
m_FormToOpen.Show
End If
I tried this code and it only allows me to call the form the object is in. I used your code for the list (code from form change button), it didn't return anything. This form that I want to call will always be the same, it will not change. Another part of this is that I need to pass a value to this form when called. Basically just what I'm doing now with a messagebox:
MessageBox.Show("You must login as """ & securityText & """ to access...", "Insufficient Rights", MessageBoxButtons.OK, MessageBoxIcon.Stop)
But, with a custom form.
-
The attached project shows how the custom button that exists in a separate class library can open a form that exists in the man application.
-
Yours is doing the same as mine, it only allows to select the form the button is on. In your example only form1 is available. If I create a form2 and place a button on it, then my only choice is form2. Plus, like I said there is no reason to select a form, it's always the same. Additionally, if this did work how would I pass a variable to the form I want to open? If that's not possible then all of this really doesn't matter.
James
-
You cannot select a form in the designer. You have to set the property in code as I had shown in the example. It is a limitation of the VS designer.
-
Ok, I guess I missed that. Having to write code, even simple code, defeats the purpose of using the components. Is there any way to pass this form as a global variable?
-
If the form never changes, you can embed it into the control itself. Why not put the form in the same project of the control?
-
I can, but it uses resources from AHMI application. I'm trying to eliminate doing things double. I was able to create a variable form and load it, but when I tried to load again I got "Cannot access a disposed object in instance VB.net". I assume I have to create a new instance each time? This is not that important, just something on my todo list. I will fumble through it. Thanks for the help Archie.
James
-
You could consolidate your resources in a shared class library as explained here:
http://geekswithblogs.net/MarkPearl/archive/2011/03/02/centralizing-a-resource-file-among-multiple-projects-in-one-solution.aspx
Then add a reference to that class library in both projects.
-
I will definitely look into that. Thanks.