how to prevent double click a user defined button in an addin?

how to prevent double click a user defined button in an addin?

liminma8458
Collaborator Collaborator
459 Views
2 Replies
Message 1 of 3

how to prevent double click a user defined button in an addin?

liminma8458
Collaborator
Collaborator

hi,

 

I create a button in the Inventor Ribbon interface through VB.NET addin, then the button to call a form (my_aaa) using such:

 

Private Sub m_button_test_OnExecute(ByVal Context As Inventor.NameValueMap) Handles m_button_test.OnExecute

      Dim my_aaa As New form_aaa
      my_aaa.Show()

End sub

 

One click to the button will create the form my_aaa. The problem is when user accidentally double-click the button, 2 forms (my_aaa) will appear. He has to close one and carry on the other. That will cause failure problem for our codes afterward. Is that possible to prevent double clicking on the botton (an Inventor's OnExecute event) or let Inventor treats double click as single click on this button.

 

Thanks in advance

 

Limin

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Accepted solutions (1)
460 Views
2 Replies
Replies (2)
Message 2 of 3

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

it is the responsibility of your code to handle the workflow, instead of Inventor. The following code snippet is for your reference:

 

' define my_aaa as global variable in your class
Dim my_aaa As form_aaa
Private Sub m_button_test_OnExecute(ByVal Context As Inventor.NameValueMap) Handles m_button_test.OnExecute
If _MainForm Is Nothing Then
my_aaa = New form_aaa()
End If 
my_aaa .Show()
End sub

 

 

I also strongly suggest you take a look at the tutorial on Best Practices for Add-In Programming and Design Patterns, which provides the nice template to manage addin button, modeless dialog etc.

 

http://au.autodesk.com/au-online/classes-on-demand/class-catalog/classes/year-2011/autodesk-inventor...

 

0 Likes
Message 3 of 3

liminma8458
Collaborator
Collaborator
Accepted solution

Hi, Liang

 

Thank you very much!

 

I found a solution by making some modification to your code, as follows:

 

' define my_aaa as global variable in your class
Dim my_aaa As form_aaa
Private Sub m_button_test_OnExecute(ByVal Context As Inventor.NameValueMap) Handles m_button_test.OnExecute
If my_aaa Is Nothing Then
my_aaa = New form_aaa()

else

my_aaa.Close()
my_aaa = New form_aaa()
End If
my_aaa.Show()
End sub

 

By doing that, one click or two click will result in one my_aaa form only.

 

Thanks Liang again. Cheers!

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes