D
David
I have a custom control that I'm working on. Everything was going swimmingly
until I needed its containing control to subscribe to an event. The problem
has to do with a separate event being raised unexpectedly. This is some code
in the control:
////////////////////////////////////////////////////////////////////////////////
public delegate void SelectionChangedHandler(object o, SelectionChangedArgs
e);
public class SelectionChangedArgs : EventArgs
{
private DefCharacter character;
public DefCharacter Character { get { return character; } }
public SelectionChangedArgs(ref DefCharacter character)
{
this.character = character;
}
}
public event SelectionChangedHandler SelectionChanged;
void RosterEditor_MouseDown(object sender, MouseEventArgs e)
{
// code omitted
// raise my SelectionChanged event
SelectionChanged(this, new SelectionChangedArgs(ref character));
}
////////////////////////////////////////////////////////////////////////////////
I have handlers for the SelectionChanged event in the parent and
parent-parent controls. The problem is that if I raise that event in
MouseDown, the MouseMove event is raised afterward, which leads to an
erroneous drag-and-drop. I have no idea why it gets raised, but only that it
doesn't happen if I comment the SelectionChanged line.
Do I just have to accept the fact that MouseMove will be raised and find
some way around it? Any advice would be appreciated.
until I needed its containing control to subscribe to an event. The problem
has to do with a separate event being raised unexpectedly. This is some code
in the control:
////////////////////////////////////////////////////////////////////////////////
public delegate void SelectionChangedHandler(object o, SelectionChangedArgs
e);
public class SelectionChangedArgs : EventArgs
{
private DefCharacter character;
public DefCharacter Character { get { return character; } }
public SelectionChangedArgs(ref DefCharacter character)
{
this.character = character;
}
}
public event SelectionChangedHandler SelectionChanged;
void RosterEditor_MouseDown(object sender, MouseEventArgs e)
{
// code omitted
// raise my SelectionChanged event
SelectionChanged(this, new SelectionChangedArgs(ref character));
}
////////////////////////////////////////////////////////////////////////////////
I have handlers for the SelectionChanged event in the parent and
parent-parent controls. The problem is that if I raise that event in
MouseDown, the MouseMove event is raised afterward, which leads to an
erroneous drag-and-drop. I have no idea why it gets raised, but only that it
doesn't happen if I comment the SelectionChanged line.
Do I just have to accept the fact that MouseMove will be raised and find
some way around it? Any advice would be appreciated.