Thread: PictureBox

  1. #1
    Registered User
    Join Date
    Nov 2008



    The thing I want to achive is having, lets say, 10 picture boxes displayed on a panel. When I click on one picture box, the image will change so... If I create a for-loop that creates the boxes and initializes the position of the boxes, how do I manage the click event for each box?

    I know that I can drag them out in design mode and then just click on each picture box to get code for it but lets say that i should have 100 boxes.... There must be a easy solution to this knowledge problem of mine.


  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer
    What framework are you using?

    Some have methods to do this (ie .NET's Control.GetChildAtPoint() or MFC's ON_COMMAND_RANGE() )

    In pure WIN32 I would process the main window/dialogs click events (WM_LBUTTONDOWN, etc).

    Create a loop that checks if the point clicked is within each pictureboxes client area (look at GetClientRect(), PtInRect() ), processing as required.

    Make sure to return the correct value or call the default handler if required (ie don't interfer with any clicks that are not in the pictureboxes).

    Also check if the mouse click point is in client or screen coods (eg ScreenToCLient() may be required).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Dec 2006
    Scranton, Pa
    Not certain if this will help, but I'd do it quick n' dirty. Make your picture window an owner drawn button, with each click have it updated to whatever picture you have sequenced (load_from_file: picture001, picture002, et cetera). I'm working off the premise that you're using pure win32 & images are of the same size.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stop PictureBox from redrawing?
    By h3ro in forum C# Programming
    Replies: 0
    Last Post: 09-06-2009, 10:09 AM
  2. Replies: 0
    Last Post: 07-13-2009, 02:32 PM
  3. Visual Studio - Access PictureBox outside Form1 class?
    By andreasleon in forum C# Programming
    Replies: 1
    Last Post: 06-08-2009, 01:55 PM
  4. picturebox and openfiledialog
    By BraneMxm in forum C# Programming
    Replies: 1
    Last Post: 06-15-2007, 10:32 AM
  5. Random generation of a picturebox control....
    By chadsxe in forum C++ Programming
    Replies: 11
    Last Post: 08-16-2005, 09:46 AM