Suddenly the Form.Shown event doesn't fire anymore
-
Post the code for your
IMessageFilter
implementation.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Imports System.Windows.Forms
Public Delegate Sub InsideDelegate(ByRef value As Boolean)
Public Class MyMessageFilter
Implements IMessageFilterPublic Event Inside As InsideDelegate Private Const WM\_LBUTTONDOWN As Integer = &H201 Private Const WM\_LBUTTONUP As Integer = &H202 Private Const WM\_PAINT As Integer = &HF Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage If m.Msg = WM\_PAINT Then Return False End If Return OnInside() End Function Private Function OnInside() As Boolean Dim \_inside As Boolean = True If InsideEvent IsNot Nothing Then InsideEvent(\_inside) End If Return \_inside End Function
End Class
-
Imports System.Windows.Forms
Public Delegate Sub InsideDelegate(ByRef value As Boolean)
Public Class MyMessageFilter
Implements IMessageFilterPublic Event Inside As InsideDelegate Private Const WM\_LBUTTONDOWN As Integer = &H201 Private Const WM\_LBUTTONUP As Integer = &H202 Private Const WM\_PAINT As Integer = &HF Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage If m.Msg = WM\_PAINT Then Return False End If Return OnInside() End Function Private Function OnInside() As Boolean Dim \_inside As Boolean = True If InsideEvent IsNot Nothing Then InsideEvent(\_inside) End If Return \_inside End Function
End Class
So either
InsideEvent
isNothing
, or it's setting the parameter toTrue
, and yourIMessageFilter
is cancelling every message exceptWM_PAINT
. You've declared constants forWM_LBUTTONDOWN
andWM_LBUTTONUP
; did you intend to test for and cancel those specific messages?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
So either
InsideEvent
isNothing
, or it's setting the parameter toTrue
, and yourIMessageFilter
is cancelling every message exceptWM_PAINT
. You've declared constants forWM_LBUTTONDOWN
andWM_LBUTTONUP
; did you intend to test for and cancel those specific messages?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
So either
InsideEvent
isNothing
, or it's setting the parameter toTrue
, and yourIMessageFilter
is cancelling every message exceptWM_PAINT
. You've declared constants forWM_LBUTTONDOWN
andWM_LBUTTONUP
; did you intend to test for and cancel those specific messages?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Yes - don't cancel every message sent to your form. :doh: Most Windows Forms events are raised in response to window messages. If you cancel all messages being sent to the form, then you shouldn't be surprised when things stop working as expected.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Yes - don't cancel every message sent to your form. :doh: Most Windows Forms events are raised in response to window messages. If you cancel all messages being sent to the form, then you shouldn't be surprised when things stop working as expected.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Sorry , but the filter became active only when a condition is true. This condition became true only if the user press a button. But the user can't press a button when the form is not shown. so before the form is shown , the filter has no effect.
When you add the filter in the form's
Load
event, you prevent any further messages from being sent to the form. (As I said before, eitherInsideEvent
isNothing
, or it's setting the parameter toTrue
.) That prevents the form from receiving the message telling it that it has been activated, which prevents it from raising theShown
event. Adding a filter which prevents any window messages from being sent to your form is a very bad idea. You should not be surprised when it breaks things in interesting ways!
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
When you add the filter in the form's
Load
event, you prevent any further messages from being sent to the form. (As I said before, eitherInsideEvent
isNothing
, or it's setting the parameter toTrue
.) That prevents the form from receiving the message telling it that it has been activated, which prevents it from raising theShown
event. Adding a filter which prevents any window messages from being sent to your form is a very bad idea. You should not be surprised when it breaks things in interesting ways!
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Private Sub filter_Inside1(ByRef value As Boolean)
value = condition1
End SubDim condition1 as Boolean=false
On form's load event :
AddHandler filter1.Inside, AddressOf filter_Inside1
Application.AddMessageFilter(filter1)As you can see at the beginning the filter is not active because the value=false. And I repeat , that I have this scenario in all my forms , but only this form has the problem.
-
Private Sub filter_Inside1(ByRef value As Boolean)
value = condition1
End SubDim condition1 as Boolean=false
On form's load event :
AddHandler filter1.Inside, AddressOf filter_Inside1
Application.AddMessageFilter(filter1)As you can see at the beginning the filter is not active because the value=false. And I repeat , that I have this scenario in all my forms , but only this form has the problem.
Then there's something else going on that you haven't shown us. It's still a very bad idea to cancel all window messages for a form. Your filter should only be cancelling the specific messages that you want to block.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Then there's something else going on that you haven't shown us. It's still a very bad idea to cancel all window messages for a form. Your filter should only be cancelling the specific messages that you want to block.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
If it was something else , why the problem is resolved when I remove the line of code that add the filter to application ? And just to clarify , I doesn't cancel all messages to the entire form. The condition that enable/disable the filter become true only if some other conditions are true and if the user click with mouse in some specific area.
-
If it was something else , why the problem is resolved when I remove the line of code that add the filter to application ? And just to clarify , I doesn't cancel all messages to the entire form. The condition that enable/disable the filter become true only if some other conditions are true and if the user click with mouse in some specific area.
Since I can't see your screen, access your hard-drive, or read your mind, the only information I have available is what you have posted in this thread. Based on that information, there are two possibilities:
- The filter is active when the form is loaded, which means you are cancelling every message being sent to the form;
- The filter is not active when the form is loaded, and something else which you haven't shown us is happening on that specific form;
If removing the filter fixes the problem, then I'm inclined to think it's #1. However, since you keep insisting that the filter is not active when the form is loaded, then that only leaves #2. Finding the real cause of the problem will involve debugging your code. YOU are the only person who can do that.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer