I am trying to add a mouseup/down event to a listview.

Using ApplicationEx I can capture the mouse event, and determine the X
and Y values of the mouse location. All good so far...

I now want to Invoke the mouse event for the listview. It is defined as:

public void ListView_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e) {}

I can do the invoke by:

Parent.Invoke ( new MouseEventHandler ( Parent.ListView_MouseUp ) );

where Parent is set when instantiating the class.

However this is not sufficient for my needs. I want to be able to add a
System.Windows.Forms.MouseEventArgs when I do the invoke.

I can store the mouse co-ordinates in some global variable and get it
from the parent form, but I was hoping that I could do it a cleaner way
using the ListView_MouseDown procedure above.

Should I marshal the MouseEventArgs?

Guidance is gratefully accepted.

Re: Invoke by ctacke/>

ctacke/>
Mon Jul 04 14:43:21 CDT 2005

CF 1.0's ability to Invoke is limited. I suggest having an internal
variable that you store your mouse args to, then when you call Invoke read
them back. Kind of ugly, yes, but there aren't really any better options.

-Chris


"William Bates" <WilliamBates@NOSPAM.com.au> wrote in message
news:%230iTqaMgFHA.1148@TK2MSFTNGP12.phx.gbl...
>I am trying to add a mouseup/down event to a listview.
>
> Using ApplicationEx I can capture the mouse event, and determine the X and
> Y values of the mouse location. All good so far...
>
> I now want to Invoke the mouse event for the listview. It is defined as:
>
> public void ListView_MouseDown(object sender,
> System.Windows.Forms.MouseEventArgs e) {}
>
> I can do the invoke by:
>
> Parent.Invoke ( new MouseEventHandler ( Parent.ListView_MouseUp ) );
>
> where Parent is set when instantiating the class.
>
> However this is not sufficient for my needs. I want to be able to add a
> System.Windows.Forms.MouseEventArgs when I do the invoke.
>
> I can store the mouse co-ordinates in some global variable and get it from
> the parent form, but I was hoping that I could do it a cleaner way using
> the ListView_MouseDown procedure above.
>
> Should I marshal the MouseEventArgs?
>
> Guidance is gratefully accepted.
>



Re: Invoke by Daniel

Daniel
Tue Jul 05 04:43:16 CDT 2005

Using a global (better, class level) variable to store the arguments is the
only way (CF 1.0 Invoke only accepts EventHandler).

If you want to process all the events and not just the last one use a Queue.
With your current approach, since the mouse events will fire faster than the
control.invoke call, your global variable would be updated before it had a
chance to be read.

For an example of the Queue approach (plus more) see this:
http://www.danielmoth.com/Blog/2004/10/invoke-cf-and-full-fx.html

Note that CF 2.0 brings parity with the desktop removing all control.invoke
limitations.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"William Bates" <WilliamBates@NOSPAM.com.au> wrote in message
news:%230iTqaMgFHA.1148@TK2MSFTNGP12.phx.gbl...
>I am trying to add a mouseup/down event to a listview.
>
> Using ApplicationEx I can capture the mouse event, and determine the X and
> Y values of the mouse location. All good so far...
>
> I now want to Invoke the mouse event for the listview. It is defined as:
>
> public void ListView_MouseDown(object sender,
> System.Windows.Forms.MouseEventArgs e) {}
>
> I can do the invoke by:
>
> Parent.Invoke ( new MouseEventHandler ( Parent.ListView_MouseUp ) );
>
> where Parent is set when instantiating the class.
>
> However this is not sufficient for my needs. I want to be able to add a
> System.Windows.Forms.MouseEventArgs when I do the invoke.
>
> I can store the mouse co-ordinates in some global variable and get it from
> the parent form, but I was hoping that I could do it a cleaner way using
> the ListView_MouseDown procedure above.
>
> Should I marshal the MouseEventArgs?
>
> Guidance is gratefully accepted.
>