How can I get each event in the EventHandlerList

G

Guest

Hi,

I'm using a listview control and want to track the mouse events in the
column header of the listview control. After inhereting the ColumnHeader i
can get the events in an EventHandlerList. But i don't know how to get each
EventHandler of the list.
I want to override the MouseMove event to disable the change of the mouse
cursor when the mouse moves over the divider of the column header.

How can i do this?

Thanx,
Georg
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Georg,

First of all ColumnHeader doesn't have MouseMove event. It does have Events
as long as it inherits this property from the Component class.

Secon of all even if it had that event you cannot get the event handlers.
Events property holds list of event handlers for each event; WindowsForms
uses that patter in order to oprimize the memory usage. However each event
is registered under some key, which you don't know thus, you cannot use that
list for anything, but your own events.
Anyways, If ColumnHeader had that event following the design pattern used
throughout WindowsForms there would be protected virtual OnMouseMove method,
which you'd be able to override, thus overriding the event handling.
 
G

Guest

Hi Stoitcho,

Thank you for your informations. I didn't find any information about the
OnMouseMove methods, but i tried to override this method again. But i got a
compiler error: no suitable method found to override. Is there any other
possibility to get the mouse move event?

Thanx,

Georg
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Georg,

No, there is not because I said Column header doesn't have that event
(that's why it has no OmMouseMove method).
See ColumnHeader is a component, not a control. In most of the cases
controls provide those interactivity events. It is possible that components
may have them too but it is verry unlikely. In this particular case with
ColumnHeader it doesn't. Look at the control that uses those headers. there
you will find the event, I believe

--

HTH
Stoitcho Goutsev (100) [C# MVP]


Georg Winkelhofer said:
Hi Stoitcho,

Thank you for your informations. I didn't find any information about the
OnMouseMove methods, but i tried to override this method again. But i got
a
compiler error: no suitable method found to override. Is there any other
possibility to get the mouse move event?

Thanx,

Georg
 
G

Guest

Hi Stoitcho,

Thank you again for your explanations. Sorry for my misunderstandings of
components and controls.
Now i have to explain a little bit more of my project and what i've already
tested:
The width of the columns in the ListView is fixed and the user is not
allowed to resize the column width neither with a mouse drag nor with a
double click. I've got a tip from Claes Bergefall to catch these events.
But the mouse cursor changes to "ve_sizeb.cur". If you see this cursor you
think you can resize the column width.
Now i wanted to catch the mouse move event before the mouse cursor changes
to "ve_sizeb.cur". My first guess was to use the mouse move event of the
ListView. But there is no mouse move event when you move the mouse over the
column header.

Here is my MouseMove event:
protected override void OnMouseMove(MouseEventArgs e)
{
// store the mouse position in the HitTestInfo structure
HDHITTESTINFO mPoint = new HDHITTESTINFO();
mPoint.pt.X = e.X;
mPoint.pt.Y = e.Y;

// get the position of the mouse in the listview header.
// The header control includes all columns.
// Get a handle to the header control.
IntPtr hc;
hc = SendMessage(this.Handle, new IntPtr(LVM_GETHEADER), new IntPtr(0),
new IntPtr(0));
hc = SendMessage(hc, new IntPtr(HDM_HITTEST), new IntPtr(0), ref mPoint);
if (mPoint.flags != HHT_ONDIVIDER)
base.OnMouseMove (e);
}

There is never a flag with HHT_ONDIVIDER, all flags i get are HHT_BELOW.
There is no y-position of the mouse smaller than 18 (the height of the
ColumnHeader). Now i think there is a control catching the mouse move event
in the area of the column headers.
Is there any way to prevent the mouse cursor to change to the resizign cursor?

Thank you,
Georg
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Georg,

listview column header is a separate window. That's why you don't receive
messages (events) for it. Native ListView doesn't notify for mouse moves
over the header thus .NET cotntrol doesn't have events as well.
I can see that this window has CLASSWND of SysHeader32 so it can be
subclassed in order to intercept those messages, however this is not good
idea since it is not documented, thus subject to change. Beside this, IMHO,
there is no way to process those messages.
 
G

Guest

Hi Stoitcho,

thank you again for your help. It's time for me to give up looking for a
solution to my problem. I've to live with the change of the mouse cursor, but
I#ve learned a lot new things about controls and components in .NET.

Thanx,

Georg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top