Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
AnswerRe: Window Body From Handle Pin
MarkB77716-Jul-09 19:59
MarkB77716-Jul-09 19:59 
QuestionForm events taking precedence over control events and forwarding events? Pin
Megidolaon16-Jul-09 12:43
Megidolaon16-Jul-09 12:43 
QuestionRe: Form events taking precedence over control events and forwarding events? Pin
DaveyM6916-Jul-09 13:55
professionalDaveyM6916-Jul-09 13:55 
AnswerRe: Form events taking precedence over control events and forwarding events? Pin
Luc Pattyn16-Jul-09 13:57
sitebuilderLuc Pattyn16-Jul-09 13:57 
JokeRe: Form events taking precedence over control events and forwarding events? Pin
DaveyM6916-Jul-09 14:09
professionalDaveyM6916-Jul-09 14:09 
AnswerRe: bizar mouse event question Pin
Luc Pattyn16-Jul-09 13:55
sitebuilderLuc Pattyn16-Jul-09 13:55 
AnswerRe: Form events taking precedence over control events and forwarding events? Pin
Super Lloyd16-Jul-09 14:05
Super Lloyd16-Jul-09 14:05 
GeneralRe: Form events taking precedence over control events and forwarding events? [modified] Pin
Megidolaon17-Jul-09 5:00
Megidolaon17-Jul-09 5:00 
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 corner and when you select something right and above of the current box, it's also at the upper right corner of the selection form.
Or will that happen automatically once the mouse coordinates are relative to the client area?

Again, thanks a lot in advance.

modified on Friday, July 17, 2009 1:44 PM

QuestionDifferent settings for development vs. production Pin
jaminblount16-Jul-09 11:51
jaminblount16-Jul-09 11:51 
AnswerRe: Different settings for development vs. production Pin
Pete O'Hanlon16-Jul-09 12:25
mvePete O'Hanlon16-Jul-09 12:25 
QuestionInterface Ibindinglist : Specified argument was out of the range error Pin
baranils16-Jul-09 11:33
baranils16-Jul-09 11:33 
AnswerRe: Interface Ibindinglist : Specified argument was out of the range error Pin
baranils17-Jul-09 21:41
baranils17-Jul-09 21:41 
QuestionDatagrid row select help Pin
Member 640383816-Jul-09 10:21
Member 640383816-Jul-09 10:21 
Question64 bit connection strings Pin
Natza Mitzi16-Jul-09 8:55
Natza Mitzi16-Jul-09 8:55 
AnswerRe: 64 bit connection strings Pin
Paladin200016-Jul-09 10:14
Paladin200016-Jul-09 10:14 
GeneralRe: 64 bit connection strings Pin
Natza Mitzi16-Jul-09 20:36
Natza Mitzi16-Jul-09 20:36 
QuestionStop the CONSOLE at the end of the debut Pin
rodbiser16-Jul-09 8:28
rodbiser16-Jul-09 8:28 
AnswerRe: Stop the CONSOLE at the end of the debut Pin
N a v a n e e t h16-Jul-09 8:45
N a v a n e e t h16-Jul-09 8:45 
AnswerRe: Stop the CONSOLE at the end of the debut Pin
Natza Mitzi16-Jul-09 8:51
Natza Mitzi16-Jul-09 8:51 
AnswerRe: Stop the CONSOLE at the end of the debut Pin
mypicturefaded16-Jul-09 8:59
mypicturefaded16-Jul-09 8:59 
AnswerRe: Stop the CONSOLE at the end of the debut Pin
Luc Pattyn16-Jul-09 9:21
sitebuilderLuc Pattyn16-Jul-09 9:21 
GeneralRe: Stop the CONSOLE at the end of the debut Pin
rodbiser18-Aug-09 10:15
rodbiser18-Aug-09 10:15 
AnswerRe: Stop the CONSOLE at the end of the debut Pin
Alan N16-Jul-09 9:48
Alan N16-Jul-09 9:48 
QuestionTell When A Control Is Added In Design Mode Pin
Kevin Marois16-Jul-09 7:43
professionalKevin Marois16-Jul-09 7:43 
AnswerRe: Tell When A Control Is Added In Design Mode Pin
N a v a n e e t h16-Jul-09 8:54
N a v a n e e t h16-Jul-09 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.