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. MouseEventArgs and Screen Position

MouseEventArgs and Screen Position

Scheduled Pinned Locked Moved C#
databasequestion
3 Posts 2 Posters 1 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.
  • E Offline
    E Offline
    Expert Coming
    wrote on last edited by
    #1

    I have a form with a DataGridView on it. I have an event handler for the MouseUp event. I am trying to make a context menu popup on a right mouse click only, and appear right under the mouse. Here is what I have so far:

    private void PlayList_CellClick(object sender, MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Right)
    {
    Point loc = this.PointToScreen(new Point(e.X, e.Y));

            int index = PlayList.HitTest(e.X, e.Y).RowIndex;
    
            PlayListMenu.Show(loc.X, loc.Y);
        }
    }
    

    It almost works, the context menu just doesn't popup in the right place. Any ideas?

    The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

    E S 2 Replies Last reply
    0
    • E Expert Coming

      I have a form with a DataGridView on it. I have an event handler for the MouseUp event. I am trying to make a context menu popup on a right mouse click only, and appear right under the mouse. Here is what I have so far:

      private void PlayList_CellClick(object sender, MouseEventArgs e)
      {
      if(e.Button == MouseButtons.Right)
      {
      Point loc = this.PointToScreen(new Point(e.X, e.Y));

              int index = PlayList.HitTest(e.X, e.Y).RowIndex;
      
              PlayListMenu.Show(loc.X, loc.Y);
          }
      }
      

      It almost works, the context menu just doesn't popup in the right place. Any ideas?

      The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

      E Offline
      E Offline
      Expert Coming
      wrote on last edited by
      #2

      I got it to work like this:

      private void PlayList_CellClick(object sender, DataGridViewCellMouseEventArgs e)
      {
      if(e.Button == MouseButtons.Right)
      {
      Point loc = new Point(e.X, e.Y + PlayList.ColumnHeadersHeight + (PlayList.Rows[0].Height * e.RowIndex));

              PlayListMenu.Show(PlayList, loc);
          }
      }
      

      Is there a better way? Know of the right way?

      The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

      1 Reply Last reply
      0
      • E Expert Coming

        I have a form with a DataGridView on it. I have an event handler for the MouseUp event. I am trying to make a context menu popup on a right mouse click only, and appear right under the mouse. Here is what I have so far:

        private void PlayList_CellClick(object sender, MouseEventArgs e)
        {
        if(e.Button == MouseButtons.Right)
        {
        Point loc = this.PointToScreen(new Point(e.X, e.Y));

                int index = PlayList.HitTest(e.X, e.Y).RowIndex;
        
                PlayListMenu.Show(loc.X, loc.Y);
            }
        }
        

        It almost works, the context menu just doesn't popup in the right place. Any ideas?

        The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

        S Offline
        S Offline
        Shree
        wrote on last edited by
        #3

        You have achieved what you wanted to do for now. The function Control.PointToScreen() and the corresponding counterpart will be helpful at other times.

        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