Why are change notifications received before mouse events? 
Author Message
 Why are change notifications received before mouse events?

Hi,

For both list boxes and numeric up down controls (and I suspect other
controls as well), when a mouse click results in either selection of an item
(list box) or a change to a spinner value (numeric up down), the
notification of value change is ALWAYS received BEFORE the mouse up/mouse
down message.

Obviously it should be possible to disregard the value change notifications
(especially in the case of numeric up down controls where you would
certainly rather wait until the spinner is released before processing the
new value!!) without having to resort to processing WM_LBUTTONUP and
WM_LBUTTONDOWM messages (something else that is not possible in C# without
unusual effort), but the order in which the notifications are sent makes
this impossible.

Please note that this IS NOT THE SAME AS IN C++.

THIS IS COMPLETELY IDIOTIC - CAN A MS ENGINEER POSSIBLY EXPLAIN THE LOGIC OF
THIS SEQUENCE ???



Sun, 31 Oct 2004 07:26:23 GMT  
 Why are change notifications received before mouse events?

There are always better solutions.

The Windows.Forms class are designed so their object definition can be changed by deriving your own class and overriding protected "On<event>" functions.

The following example demonstrates overriding their functions to create a ListBox to fire the SelectedValueChanged only after MouseDown -> MouseUp completion.

The following is a simple example:

<code>
    public   class MyListBox : ListBox {

         bool        bMouseUp = false;
         public      MyListBox () {
            string[]    items = new string[]{
               "Item1",
               "Item2",
               "Item3",
            };

            for ( int a = 0; a < items.Length; a++ ) {
               this.Items.Add ( items[a] );
            }
         }

         protected   override void OnMouseDown ( MouseEventArgs mouseArgs ) {
            bMouseUp = false;
            Console.WriteLine ( "\nMouseDown override" );
            base.OnMouseDown ( mouseArgs );
         }

         protected   override void OnMouseUp ( MouseEventArgs mouseArgs ) {
            bMouseUp = true;
            Console.WriteLine ( "MouseUp override" );

            base.OnMouseUp ( mouseArgs );

            //force fire the SelectedValueChanged
            OnSelectedValueChanged ( null );
         }

         protected   override void OnSelectedValueChanged ( EventArgs args ) {
            Console.WriteLine ( "SelectedValueChanged override" );

            //fire only OnMouseUp
            if ( bMouseUp == true ) {
               bMouseUp = false;
               base.OnSelectedValueChanged ( args );
            }
         }
      }
</code>

Regards,
- Richard

Quote:

> Hi,

> For both list boxes and numeric up down controls (and I suspect other
> controls as well), when a mouse click results in either selection of an item
> (list box) or a change to a spinner value (numeric up down), the
> notification of value change is ALWAYS received BEFORE the mouse up/mouse
> down message.

> Obviously it should be possible to disregard the value change notifications
> (especially in the case of numeric up down controls where you would
> certainly rather wait until the spinner is released before processing the
> new value!!) without having to resort to processing WM_LBUTTONUP and
> WM_LBUTTONDOWM messages (something else that is not possible in C# without
> unusual effort), but the order in which the notifications are sent makes
> this impossible.

> Please note that this IS NOT THE SAME AS IN C++.

> THIS IS COMPLETELY IDIOTIC - CAN A MS ENGINEER POSSIBLY EXPLAIN THE LOGIC OF
> THIS SEQUENCE ???



Sun, 31 Oct 2004 13:16:38 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Why Mouse Mouse event with every Click event

2. Receiving event notifications

3. Why am I getting Mouse Move Event with every Mouse Click event?

4. NotifyIcon handler not receiving mouse events

5. No Event Notification From A Thread, Why?

6. Custom control not receiving key events -- why?

7. Why WaitForMultipleObjects just can receive event once?

8. Receiving events from User Manager when changes are made

9. Receiving events from User Manager when changes are made

10. why number of mouse events is less than it shoud be

11. why number of mouse events is less that it shoud be

12. how do a parent window receive the child control notification

 

 
Powered by phpBB® Forum Software