Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. A question about object sender

A question about object sender

Scheduled Pinned Locked Moved C#
questiondata-structures
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 939369
    wrote on last edited by
    #1

    I use a PictureBox array in my project; public PictureBox[] illustration; illustration = new PictureBox[10]; ... myInkPicture[IntSelectPage].illustration[i] = new System.Windows.Forms.PictureBox(); ... myInkPicture[IntSelectPage].illustration[i].MouseDown += new System.Windows.Forms.MouseEventHandler(myInkPicture[IntSelectPage].illustration_MouseDown); the ten PictureBoxes use the same MouseDown event handler, public void illustration_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { pictureBox1.Capture = true; startMoveLocation = new Point(e.X, e.Y); } I want the pictureBox1 to be the illustration[i], How can I typecast the object sender to be the illustration[i] PictureBox...??

    K 1 Reply Last reply
    0
    • U User 939369

      I use a PictureBox array in my project; public PictureBox[] illustration; illustration = new PictureBox[10]; ... myInkPicture[IntSelectPage].illustration[i] = new System.Windows.Forms.PictureBox(); ... myInkPicture[IntSelectPage].illustration[i].MouseDown += new System.Windows.Forms.MouseEventHandler(myInkPicture[IntSelectPage].illustration_MouseDown); the ten PictureBoxes use the same MouseDown event handler, public void illustration_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { pictureBox1.Capture = true; startMoveLocation = new Point(e.X, e.Y); } I want the pictureBox1 to be the illustration[i], How can I typecast the object sender to be the illustration[i] PictureBox...??

      K Offline
      K Offline
      Karl 2000
      wrote on last edited by
      #2

      Hi, In your mouse down event handler sender is the object that caused the event. In this case it will be whatever picturebox the mouse went down over. I believe that by casting sender to a picturebox you will have the picturebox that the mouse went down on aka illustration[i]. Do this with ((PictureBox)sender).Capture = true; Karl

      U 1 Reply Last reply
      0
      • K Karl 2000

        Hi, In your mouse down event handler sender is the object that caused the event. In this case it will be whatever picturebox the mouse went down over. I believe that by casting sender to a picturebox you will have the picturebox that the mouse went down on aka illustration[i]. Do this with ((PictureBox)sender).Capture = true; Karl

        U Offline
        U Offline
        User 939369
        wrote on last edited by
        #3

        I have tried and it really works !! Thank you very much :-D

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups