Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Suddenly the Form.Shown event doesn't fire anymore

Suddenly the Form.Shown event doesn't fire anymore

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
17 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CHill60C CHill60

    Do you mean it doesn't fire ever? Or only the first time the form is shown and then not fired after that

    D Offline
    D Offline
    dilkonika
    wrote on last edited by
    #3

    I mean doesn't fire ever.

    CHill60C 1 Reply Last reply
    0
    • D dilkonika

      I mean doesn't fire ever.

      CHill60C Offline
      CHill60C Offline
      CHill60
      wrote on last edited by
      #4

      Does your Shown event handler definitely have Handles MyBase.Shown after it?

      D 1 Reply Last reply
      0
      • CHill60C CHill60

        Does your Shown event handler definitely have Handles MyBase.Shown after it?

        D Offline
        D Offline
        dilkonika
        wrote on last edited by
        #5

        Of course. Was working before. I think I found that the cause of the problem is this line of code in Load event :

        Application.AddMessageFilter(filter1)

        where filter1 is a IMessageFilter. This filter prevent users clicking on a specific form's area when a condition is true. When I remove this line of code , the shown event is fired. But what has to do this with a form shown ???!!! And why on other forms ( where I have also exactly this line of code ) everything is working perfectly ?

        Richard DeemingR 1 Reply Last reply
        0
        • D dilkonika

          Of course. Was working before. I think I found that the cause of the problem is this line of code in Load event :

          Application.AddMessageFilter(filter1)

          where filter1 is a IMessageFilter. This filter prevent users clicking on a specific form's area when a condition is true. When I remove this line of code , the shown event is fired. But what has to do this with a form shown ???!!! And why on other forms ( where I have also exactly this line of code ) everything is working perfectly ?

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #6

          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

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          D 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            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

            D Offline
            D Offline
            dilkonika
            wrote on last edited by
            #7

            Imports System.Windows.Forms
            Public Delegate Sub InsideDelegate(ByRef value As Boolean)
            Public Class MyMessageFilter
            Implements IMessageFilter

            Public 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

            Richard DeemingR 1 Reply Last reply
            0
            • D dilkonika

              Imports System.Windows.Forms
              Public Delegate Sub InsideDelegate(ByRef value As Boolean)
              Public Class MyMessageFilter
              Implements IMessageFilter

              Public 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

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #8

              So either InsideEvent is Nothing, or it's setting the parameter to True, and your IMessageFilter is cancelling every message except WM_PAINT. You've declared constants for WM_LBUTTONDOWN and WM_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

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              D 2 Replies Last reply
              0
              • Richard DeemingR Richard Deeming

                So either InsideEvent is Nothing, or it's setting the parameter to True, and your IMessageFilter is cancelling every message except WM_PAINT. You've declared constants for WM_LBUTTONDOWN and WM_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

                D Offline
                D Offline
                dilkonika
                wrote on last edited by
                #9

                yes , I was thinking to test something before.

                1 Reply Last reply
                0
                • Richard DeemingR Richard Deeming

                  So either InsideEvent is Nothing, or it's setting the parameter to True, and your IMessageFilter is cancelling every message except WM_PAINT. You've declared constants for WM_LBUTTONDOWN and WM_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

                  D Offline
                  D Offline
                  dilkonika
                  wrote on last edited by
                  #10

                  Any solution ?

                  Richard DeemingR 1 Reply Last reply
                  0
                  • D dilkonika

                    Any solution ?

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #11

                    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

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    D 1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      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

                      D Offline
                      D Offline
                      dilkonika
                      wrote on last edited by
                      #12

                      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.

                      Richard DeemingR 1 Reply Last reply
                      0
                      • D dilkonika

                        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.

                        Richard DeemingR Offline
                        Richard DeemingR Offline
                        Richard Deeming
                        wrote on last edited by
                        #13

                        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, either InsideEvent is Nothing, or it's setting the parameter to True.) That prevents the form from receiving the message telling it that it has been activated, which prevents it from raising the Shown 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

                        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                        D 1 Reply Last reply
                        0
                        • Richard DeemingR Richard Deeming

                          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, either InsideEvent is Nothing, or it's setting the parameter to True.) That prevents the form from receiving the message telling it that it has been activated, which prevents it from raising the Shown 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

                          D Offline
                          D Offline
                          dilkonika
                          wrote on last edited by
                          #14

                          Private Sub filter_Inside1(ByRef value As Boolean)
                          value = condition1
                          End Sub

                          Dim 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.

                          Richard DeemingR 1 Reply Last reply
                          0
                          • D dilkonika

                            Private Sub filter_Inside1(ByRef value As Boolean)
                            value = condition1
                            End Sub

                            Dim 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.

                            Richard DeemingR Offline
                            Richard DeemingR Offline
                            Richard Deeming
                            wrote on last edited by
                            #15

                            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

                            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                            D 1 Reply Last reply
                            0
                            • Richard DeemingR Richard Deeming

                              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

                              D Offline
                              D Offline
                              dilkonika
                              wrote on last edited by
                              #16

                              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.

                              Richard DeemingR 1 Reply Last reply
                              0
                              • D dilkonika

                                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.

                                Richard DeemingR Offline
                                Richard DeemingR Offline
                                Richard Deeming
                                wrote on last edited by
                                #17

                                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:

                                1. The filter is active when the form is loaded, which means you are cancelling every message being sent to the form;
                                2. 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

                                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups