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. .NET (Core and Framework)
  4. Simple MouseEnter MouseLeave Events

Simple MouseEnter MouseLeave Events

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpwinformsquestion
2 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.
  • M Offline
    M Offline
    MarkMokris
    wrote on last edited by
    #1

    In a C# Windows Forms app, I have a Panel containing some Labels and Pictureboxes. I have set up delegates at the Panel level to handle MouseEnter and MouseLeave Events. I want something to happen when the user moves the mouse into the Panel and out of the Panel. However, the Panel MouseEnter and MouseLeave Events are firing when the mouse moves into and out of any of the Pictureboxes and Labels within the Panel. I don't want this behavior. I want them to fire only when the mouse moves into the Panel and out of the Panel. What am I doing wrong? Thanks, Mark

    W 1 Reply Last reply
    0
    • M MarkMokris

      In a C# Windows Forms app, I have a Panel containing some Labels and Pictureboxes. I have set up delegates at the Panel level to handle MouseEnter and MouseLeave Events. I want something to happen when the user moves the mouse into the Panel and out of the Panel. However, the Panel MouseEnter and MouseLeave Events are firing when the mouse moves into and out of any of the Pictureboxes and Labels within the Panel. I don't want this behavior. I want them to fire only when the mouse moves into the Panel and out of the Panel. What am I doing wrong? Thanks, Mark

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      I'd say you're doing nothing wrong. Because mouse moves above another control it leaves the panel, whether the control is inside or outside the panel. When mouse leaves the panel, you could check the position of the mouse, is it still inside the panel or not. The same logic can be used in MouseEnter. You can get the position from the Cursor class. Hope this helps, Mika

      The need to optimize rises from a bad design. My articles[^]

      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