On Tue, 26 Dec 2006 12:41:01 -0500, Kevin Spencer wrote:
Quote:
Hi Terry,
>
Handle the Form's MouseDown event, or override the Form's OnMouseDown
method:
>
protected override void OnMouseDown(MouseEventArgs e)
{
if (!theListBox.Bounds.Contains(e.Location))
theListBox.Visible = false;
}
>
The Contains method olf System.Drawing.Rectangle can be used to indicate if
a point is contained inside a rectangle. The Bounds property of a Control is
the outer Rectangle defined by the edges of the Control. The Location
property of the MouseEventArgs is the Point relative to the Control which
received the MouseDown event. The Bounds property of a Control in a Form is
relative to the Form.
>
thanks a lot for the input. I am using Visual Studio 2003 (which means
..net 1.1). Perhaps this is what causes the error that e.Location doesn't
exist in the MouseEventArgs class. I fixed this by doing the following:
if (!theListBox.Bounds.Contains(new System.Drawing.Point(e.X, e.Y)))
and this works--sort of.
although I capture the MouseDown event when the click is outside of
another control on the form, it is not captured when it is within another
control. so, if the list is visible, and I click on a different control
on the form that is also visible (not obscured by the listbox), then the
MouseDown event is swallowed and executed by the control it occurred
within. Any way to avoid this other than making all the other controls
invisible?