2 Replies - 1077 Views - Last Post: 19 February 2011 - 10:52 AM Rate Topic: -----

#1 Vympel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-February 11

Many MouseClick events on one picture box

Posted 19 February 2011 - 10:39 AM

Ok, this is my problem. I have one picturebox on my form (it is docked), and in that picturebox I have drawn 12 images using this code:
for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    grf.DrawImage(images2D[j, i], Xpos * 6 * i + 10, Ypos * 6 * j + 10, 50, 50);
                }
            }


Positioning of images is random and different every time. And this works like a charm. What I want is to be able to click on individual images and change only that (clicked) image. Can this be done the way I imagined it?
I am fairily new to C# and programming, but Im not a total beginner.

Is This A Good Question/Topic? 0
  • +

Replies To: Many MouseClick events on one picture box

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Many MouseClick events on one picture box

Posted 19 February 2011 - 10:52 AM

The mouse click event has a set of arguments associated with it. The x,y location of the event is part of these arguments. See the example here Control.MouseClick Event. See also MouseEventArgs Class

This post has been edited by n8wxs: 19 February 2011 - 10:53 AM

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,371
  • Joined: 02-June 10

Re: Many MouseClick events on one picture box

Posted 19 February 2011 - 10:52 AM

No. You've drawn bits of a bitmap, but you have no objects that you can refer to, get events from, and so on.

Consider this: Use a Panel instead of a PictureBox. You're not using the picturebox as it was designed anyway.

On your panel place multiple pictureboxes. That way you can get the .Click event from each picturebox. You can place the pictureboxes randomly, and use the .Image property of the picturebox to set the image.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1