Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was thinking to include a feature in my application in which when Selects a mode from a menu, then we have to go each PictureBox on the form after a certain time. For eg: There are 5 pictureboxes (number not fixed since pictureboxes are created at runtime). When the user selects the mode, the Mouse goes to the center of each pictureBox periodically. The picture box that has focus should have a frame around it with a dark red color as shown in the screenshot clearly ( http://img508.imageshack.us/img508/1279/focus.png[^] ). The rest of the functioning is the same as for the application.
Posted

1 solution

There are a few things you need to do.

First, use the Form.Controls property gives you the list of controls on the form. You can then use the GetType method on the control to determine if the control is a picture box.

If it is, you get the location and the size and find the centre and possibly put it into a list holding a collection of Point objects.

You then have a list of locations for your mouse to go to periondically (which can be implemented by a timer). Once you have this, when your mouse goes to index 1, you set the border of the picture box to a red square.

Your done :)

I will write some quick code on the main concepts to get you started:


// list that holds the centers of all picture boxes on the form
            List<Point> picture_centers = new List<Point>();

            foreach(Control c in this.Controls)
            {
              // is this control a picture box?
              if(c.GetType() == typeof(PictureBox))
              {// yes it is!
                  // work out centre here and assign it
                  Point center = new Point();

                  // add the point to the list of pic centers
                  picture_centers.Add(center);
              }
            }

            // now you simply make a timer and in the event handler you
            // go through the list created and say...
            foreach(Point p in picture_centers)
            {
                // set cursor to location of cetner of pic
                Cursor.Position = p;

                // get the control under the cursor (it should be a picture box by design)
                // so you can put an assert here
                Control c = this.GetChildAtPoint(p);
                PictureBox pic = (PictureBox) c;
                pic.BorderStyle = ;
                // etc for more formatting options and maybe some sleep time
            }
 
Share this answer
 
Comments
Khaniya 9-Oct-10 6:42am    
Thanks man
Below is new for me

"this.GetChildAtPoint(p)"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900