Question OnClick event not triggering 2nd time button is clicked

TartanRug

Member
Joined
Sep 14, 2011
Messages
7
Programming Experience
5-10
Hi,

I'm having a strange problem with the OnClick event. In an ArcGIS application using VB.Net, I have a button set up with the following code:

AddItem("CommandAnalyseResults")

The following module segment contains the OnClick event:
Public NotInheritable Class CommandAnalyseResults
Inherits BaseTool

<more code...>

Public Overrides Sub OnClick()
If (mForm Is Nothing) Then
mForm = New FormAnalyseResults(Me, m_application)
End If

' Creates a new object if user has closed window
If mForm.IsDisposed Then
mForm = New FormAnalyseResults(Me, m_application)
End If

mForm.Show(NativeWindow.FromHandle(New IntPtr(GetHWndForCurrentApplication))) 'APB edits for parent/child form handling
End Sub
etc...

The OnClick event gets triggered no problem the first time I click on the button.

However if I then close the window the button code creates and then click on the button again, the OnClick code is not triggered.

If I click on a different button then click back on the 'problem' button a 2nd time, it does seem to trigger the code!

Any ideas what could be causing this and how to get around it?

Many thanks
Simon




 
For debugging set a breakpoint and step through and you will probably see code is "triggered" and know more about what happens and not.

Why have you removed the MyBase.OnClick call? That is generally not a good idea as you are breaking base functionality.
 
For debugging set a breakpoint and step through and you will probably see code is "triggered" and know more about what happens and not.

Why have you removed the MyBase.OnClick call? That is generally not a good idea as you are breaking base functionality.

Thanks for the reply.

I did set a breakpoint on the 'If (mForm Is Nothing) Then' line, it reaches this line the first time the button is clicked but not the 2nd time. Is there somewhere else I may be able to put the breakpoint that could be triggered before this?

Sorry I've just picked up this code from another developer so not sure why they removed the MyBase.OnClick call, I'm not an expert at this so don't want to change anything I don't have to!

Thanks
 
I'm having a strange problem with the OnClick event. In an ArcGIS application using VB.Net, I have a button set up with the following code:

AddItem("CommandAnalyseResults")
A comment also about that, which I ignored on first read. OnClick is not an event, it is the protected method that raises the Click event. When you suppress the base OnClick call you are also suppressing the Click event, so if you were to add an event handler for that event it would never be called. Which leads to the question, what is the AddItem calls place in this?
I did set a breakpoint on the 'If (mForm Is Nothing) Then' line, it reaches this line the first time the button is clicked but not the 2nd time.
Makes me wonder is UI thread is blocked, thus there is no message handling during this time, but it should be apparent if it was. OnClick is always called in response to the windows message invoked by clicking the control window.
 
A comment also about that, which I ignored on first read. OnClick is not an event, it is the protected method that raises the Click event. When you suppress the base OnClick call you are also suppressing the Click event, so if you were to add an event handler for that event it would never be called. Which leads to the question, what is the AddItem calls place in this?

Makes me wonder is UI thread is blocked, thus there is no message handling during this time, but it should be apparent if it was. OnClick is always called in response to the windows message invoked by clicking the control window.

I thought the AddItem just added the button to the toolbar? I know that the OnClick method does get called and carries out the required code first time but not the second time so it must be getting triggered somehow. The button still remains highlighted after I click it the first time, so it's highlighted when I click on it a second time. Is there a way I could trigger an event when the window (that the button opens) is closed by the user, using this event to somehow 'reset' the button and allow it to be used a second time?

Thanks again for your help.
 
Back
Top