Click here to Skip to main content
15,891,204 members
Home / Discussions / C#
   

C#

 
AnswerRe: Change color of ten or more PictureBoxes Pin
Henry Minute27-Aug-09 1:05
Henry Minute27-Aug-09 1:05 
AnswerRe: Change color of ten or more PictureBoxes Pin
Lyon Sun27-Aug-09 1:50
Lyon Sun27-Aug-09 1:50 
GeneralRe: Change color of ten or more PictureBoxes Pin
Henry Minute27-Aug-09 2:14
Henry Minute27-Aug-09 2:14 
GeneralRe: Change color of ten or more PictureBoxes Pin
Lyon Sun27-Aug-09 2:38
Lyon Sun27-Aug-09 2:38 
GeneralRe: Change color of ten or more PictureBoxes Pin
Henry Minute27-Aug-09 3:00
Henry Minute27-Aug-09 3:00 
GeneralRe: Change color of ten or more PictureBoxes Pin
Lyon Sun27-Aug-09 3:53
Lyon Sun27-Aug-09 3:53 
QuestionRe: Change color of ten or more PictureBoxes Pin
Lyon Sun27-Aug-09 20:34
Lyon Sun27-Aug-09 20:34 
AnswerRe: Change color of ten or more PictureBoxes Pin
Henry Minute28-Aug-09 2:45
Henry Minute28-Aug-09 2:45 
I'm afraid that Option 2 would not help in the circumstances as you now describe them, since it was simply a more complicated way to do the same as Option 1.

The only way to do what you want, in the way that you want to do it, that I can think of, is to slightly modify the code I have already given you. Basically what you need to do is to handle the MouseMove event of the control hosting your PictureBoxes. Each time the event fires it should iterate over all the PictureBoxes and test if the cursor location is within the PB pb1.Bounds.Contains(e.Location), or similar and if so, add it to a list and break out of the iteration. Therefore instead of the firstBox and secondBox you will need a collection, I would suggest List<PictureBox>. Don't forget to Clear() it on MouseDown and to add the first and second boxes to it. then in your ChangeColour iterate over the collection and do your recolouring stuff on each PB in it.

The problem with doing things in the way that you want is that if the user moves the mouse very, very quickly, one of the PBs could get missed.

[Edit]
An alternative to my suggested MouseMove approach, would be to calculate a path from the MouseDown point to the MouseUp point and then test for a PB at intervals along that path. The interval would depend on the size of the PBs.
[/Edit]

[Edit * 2]
You could of course combine the two approaches. Have a class level GraphicsPath instance, on MouseDown create a new GraphicsPath e.g. myClassLevelGP = new GraphicsPath(). Make a note of the MouseDown point. myClassLevelStartPoint = e.Location;. Then in the MouseMove handler.
myClassLevelGP.AddLine(myClassLevelStartPoint, e.Location);
myClassLevelStartPoint = e.Location;

Then in the MouseUp handler put the same two lines of code.

What you will end up with is a GraphicsPath containing lots and lots of tiny lines, tracking the path the mouse has taken.
Then in the ColorChange method you will have to iterate over the points contained in the path (look up GraphicsPath.PathPoints and GraphicsPath.PathData for suitability), and for each point iterate over the PBs and pb.Bounds.Contains(point) as mentioned above.

That's a lot of points * a lot of PBs and could take some time, not to mention the problems from fast mousing mentioned above.

You might be better off by rethinking your approach. For example, allowing users to Ctrl-Click on the PBs they want to recolour adding them to the list. They would of course have to click a button or something to trigger the recolouring and any click without Ctrl should clear the list.
[/Edit * 2]

I hope that at least part of my ramblings is of use. Smile | :)

Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”

AnswerRe: Change color of ten or more PictureBoxes Pin
Lyon Sun28-Aug-09 9:27
Lyon Sun28-Aug-09 9:27 
Questiongrid view Pin
ankitjain111026-Aug-09 23:47
ankitjain111026-Aug-09 23:47 
AnswerRe: grid view Pin
Vimalsoft(Pty) Ltd26-Aug-09 23:57
professionalVimalsoft(Pty) Ltd26-Aug-09 23:57 
GeneralRe: grid view Pin
ankitjain111027-Aug-09 0:10
ankitjain111027-Aug-09 0:10 
GeneralRe: grid view Pin
Vimalsoft(Pty) Ltd27-Aug-09 0:13
professionalVimalsoft(Pty) Ltd27-Aug-09 0:13 
QuestionAdding values to datatable Pin
myinstincts26-Aug-09 23:14
myinstincts26-Aug-09 23:14 
AnswerRe: Adding values to datatable Pin
Vimalsoft(Pty) Ltd26-Aug-09 23:25
professionalVimalsoft(Pty) Ltd26-Aug-09 23:25 
AnswerRe: Adding values to datatable Pin
kKamel26-Aug-09 23:26
kKamel26-Aug-09 23:26 
GeneralRe: Adding values to datatable [modified] Pin
myinstincts26-Aug-09 23:39
myinstincts26-Aug-09 23:39 
GeneralRe: Adding values to datatable Pin
kKamel27-Aug-09 0:40
kKamel27-Aug-09 0:40 
QuestionHardware Acceleration on a PictureBox / Non-Apparent Image in Screenshot Pin
Trapper-Hell26-Aug-09 23:09
Trapper-Hell26-Aug-09 23:09 
AnswerRe: Hardware Acceleration on a PictureBox / Non-Apparent Image in Screenshot Pin
stancrm26-Aug-09 23:57
stancrm26-Aug-09 23:57 
GeneralRe: Hardware Acceleration on a PictureBox / Non-Apparent Image in Screenshot Pin
Trapper-Hell27-Aug-09 1:08
Trapper-Hell27-Aug-09 1:08 
Questionmake available C# namespace in ATL projects. Pin
SRKSHOME26-Aug-09 22:54
SRKSHOME26-Aug-09 22:54 
QuestionHow to Display Images in the Body of the Emails in C# Pin
ChandrakanthGaddam26-Aug-09 22:53
ChandrakanthGaddam26-Aug-09 22:53 
AnswerRe: How to Display Images in the Body of the Emails in C# Pin
stancrm26-Aug-09 23:01
stancrm26-Aug-09 23:01 
AnswerRe: How to Display Images in the Body of the Emails in C# Pin
Hristo-Bojilov26-Aug-09 23:09
Hristo-Bojilov26-Aug-09 23:09 

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.