Thanks. But now that I think of it, I probably don't need it anymore. What I'm trying to do for about 3 months now is implementing an Excel like selection for a collection of PictureBoxes that are arranged in a grid, similar to cells in Excel. I don't want to select independent boxes with ctrl, just selecting a region while the mouse button is held down. I asked about this many times here and on msdn, but I either got ignored or code that didn't work at all. The latest code I got from msdn also doesn't work, but gave me an idea. I'm trying to use a half transparent form to draw the selection rectangle and use the MouseEnter and MouseLeave events of PictureBoxes to fire the Form's events (passing the MouseArgs) to change the selection form's size and location and store the coordinates of the PictureBoxes in a collection (which will be used after selection is finished). It looks like this: http://i28.tinypic.com/einihz.jpg[^] The cursor is above box 16 and the selection form is in the upper left corner outside the form. I searched, but couldn't find a working way to get the mouse coordinates not for the whole screen, but only for the form, so that the selection form will displayed correctly. I use this code for the Main Form's MouseDown event:
private void OnFormMouseDown(object sender, MouseEventArgs e)
{
select = true;
selectform = new F_selection();
selectform.Size = new Size(4, 4);
selectform.Location = new Point(e.X, e.Y);
selectstart = new Point(e.X, e.Y);
selectform.Show();
}
And this code for the MouseMove event
private void OnFormMouseMove(object sender, MouseEventArgs e)
{
int width = 0;
int height = 0;
if (select)
{
width = selectstart.X - e.Location.X;
if (width < 0)
{
width *= -1;
}
height = selectstart.Y - e.Location.Y;
if (height < 0)
{
height *= -1;
}
selectform.Location = new Point(e.X, e.Y);
selectform.Size = new Size(width, height);
}
}
Is there a better way to retrieve a number's value, independent from its algebraic sign thn checking if it's < 0 and multiplying with -1? I think in mathematics it was | x |. (damn smileys) And would you know how to make it look like the mouse cursor is always at the far edge of the selection form, i.e. if you select something below and left of the current box, it's at the lower left corne