TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Robb Sadler
NA
3
0
Override of inherited Panel OnMouseUp only being called once in custom control
Mar 24 2009 9:21 AM
Hello all,
I have used the Panel control to create an owner draw resizable list box. It works well, except for one sticky situation. I was getting my panels to draw and resize on the fly and then attempted to implement drag and drop. I got that working also, but wanted users to be able to select multiple items and then drag them all. There are two panels in the custom control and the user needs to be able to drag one or more items from one side to the other.
My OnMouseDown code handles the multi selection, and thus when the initial drag operation started, the click was causing the items selected to be replaced by the single item that is clicked. So I decided to move that code to the OnMouseUp and check to see if the MouseUp event is occurring over the same item in my list as the mouse down. When I override OnMouseUp however, it seems to (sometimes) get called once, and then never again. I figured I may be doing something that is hanging it, so I took all of the code out of it except base.OnMouseUp, and it still behaves the same - if I set a breakpoint, it does not stop there except sometimes on the first time I click on the resizablelistbox.
Are there times when the OnMouseUp will not be called even when OnMouseDown is called? Is there a place where these rules are documented so I can ensure that I am doing this correctly?
Thanks for any input. I can post some code, but when I looked at it, I have really pared it down to not doing much of anything so I don't know how useful it is:
private int indexofMouseDown = -1;
/// <summary>
/// Here we implement the selection handling of the listbox
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown (MouseEventArgs e)
{
base.OnMouseDown (e);
//make sure we receive key events
this.Focus ();
int ndx = IndexFromPoint (e.X, e.Y);
if (ndx != -1)
indexofMouseDown = ndx;
}
protected override void OnMouseUp (MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
base.OnMouseUp (e);
return;
}
//determine which item was clicked
int index = IndexFromPoint (e.X, e.Y);
//if ((index >= 0) && (index == indexofMouseDown))
//{
// if (m_CtrlPressed && m_AllowMultiSelect)
// {
// m_ShiftSelectIndexStart = index;
// m_ShiftSelectIndexEnd = index;
// if (m_SelectedIndices.Contains (index))
// RemoveSelectedItem (index);
// else
// AddSelectedItem (index);
// }
// else if (m_ShiftPressed && m_AllowMultiSelect)
// {
// if (m_ShiftSelectIndexStart == -1)
// m_ShiftSelectIndexStart = index;
// m_ShiftSelectIndexEnd = index;
// ClearSelectedItems ();
// for (int i = Math.Min (m_ShiftSelectIndexStart, m_ShiftSelectIndexEnd);
// i <= Math.Max (m_ShiftSelectIndexStart, m_ShiftSelectIndexEnd);
// ++i)
// AddSelectedItem (i);
// // add all of the items between the last click and this one (or this item if none were last clicked)
// }
// else
// {
// if ((!m_SelectedIndices.Contains (index)) || (m_SelectedIndices.Count != 1))
// {
// m_SelectedIndices.Clear ();
// m_SelectedItems.Clear ();
// AddSelectedItem (index);
// m_ShiftSelectIndexStart = index;
// m_ShiftSelectIndexEnd = index;
// }
// }
// OnSelectedIndexChanged (new EventArgs ());
// this.Invalidate ();
//}
base.OnMouseUp (e);
}
Like I said, most of the stuff I would have thought would cause some trouble is commented and used to be in the OnMouseDown and working just fine.
Thanks again!
Robb
Reply
Answers (
0
)
What is wrong with this one
Repositioning the window of Richtext box in c#