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. Left click works right does not

Left click works right does not

Scheduled Pinned Locked Moved C#
question
10 Posts 4 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.
  • E Offline
    E Offline
    electriac
    wrote on last edited by
    #1

    I do not understand why the right button does not work??

    namespace mouseclick
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
    listBox1.Items.Add("aaaaaaaaaaaa");
    listBox1.Items.Add("aaaaaaaaaaaa");
    listBox1.Items.Add("aaaaaaaaaaaa");
    }

        void listBox1\_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MessageBox.Show("Left Button"); // Works
            }
            if (e.Button == MouseButtons.Right)
            {
                MessageBox.Show("Right Button"); // Does not work  
            }
        }  
    }
    

    }

    L B R 4 Replies Last reply
    0
    • E electriac

      I do not understand why the right button does not work??

      namespace mouseclick
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
      listBox1.Items.Add("aaaaaaaaaaaa");
      listBox1.Items.Add("aaaaaaaaaaaa");
      listBox1.Items.Add("aaaaaaaaaaaa");
      }

          void listBox1\_MouseClick(object sender, MouseEventArgs e)
          {
              if (e.Button == MouseButtons.Left)
              {
                  MessageBox.Show("Left Button"); // Works
              }
              if (e.Button == MouseButtons.Right)
              {
                  MessageBox.Show("Right Button"); // Does not work  
              }
          }  
      }
      

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Are you right-clicking on an item, or the listbox?

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      E 2 Replies Last reply
      0
      • L Lost User

        Are you right-clicking on an item, or the listbox?

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        E Offline
        E Offline
        electriac
        wrote on last edited by
        #3

        Clicking on an item. Left clicking item works. Right clicking item does not.

        1 Reply Last reply
        0
        • L Lost User

          Are you right-clicking on an item, or the listbox?

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          E Offline
          E Offline
          electriac
          wrote on last edited by
          #4

          Tried same code on both Vis2008 and Vis2010 Express with the same result.

          1 Reply Last reply
          0
          • E electriac

            I do not understand why the right button does not work??

            namespace mouseclick
            {
            public partial class Form1 : Form
            {
            public Form1()
            {
            InitializeComponent();
            listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
            listBox1.Items.Add("aaaaaaaaaaaa");
            listBox1.Items.Add("aaaaaaaaaaaa");
            listBox1.Items.Add("aaaaaaaaaaaa");
            }

                void listBox1\_MouseClick(object sender, MouseEventArgs e)
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        MessageBox.Show("Left Button"); // Works
                    }
                    if (e.Button == MouseButtons.Right)
                    {
                        MessageBox.Show("Right Button"); // Does not work  
                    }
                }  
            }
            

            }

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            The ListBox does not return a right click event; see the table on this MSDN page[^].

            Use the best guess

            E 2 Replies Last reply
            0
            • L Lost User

              The ListBox does not return a right click event; see the table on this MSDN page[^].

              Use the best guess

              E Offline
              E Offline
              electriac
              wrote on last edited by
              #6

              Thanks I guess I will have to write a custom listBox from scratch.

              1 Reply Last reply
              0
              • L Lost User

                The ListBox does not return a right click event; see the table on this MSDN page[^].

                Use the best guess

                E Offline
                E Offline
                electriac
                wrote on last edited by
                #7

                I see from your posted link that a listView does have a right.mouse.button.click. I guess that's my best solution.

                L 1 Reply Last reply
                0
                • E electriac

                  I see from your posted link that a listView does have a right.mouse.button.click. I guess that's my best solution.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Quite possibly; it all depends on what you are trying to do.

                  Use the best guess

                  1 Reply Last reply
                  0
                  • E electriac

                    I do not understand why the right button does not work??

                    namespace mouseclick
                    {
                    public partial class Form1 : Form
                    {
                    public Form1()
                    {
                    InitializeComponent();
                    listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
                    listBox1.Items.Add("aaaaaaaaaaaa");
                    listBox1.Items.Add("aaaaaaaaaaaa");
                    listBox1.Items.Add("aaaaaaaaaaaa");
                    }

                        void listBox1\_MouseClick(object sender, MouseEventArgs e)
                        {
                            if (e.Button == MouseButtons.Left)
                            {
                                MessageBox.Show("Left Button"); // Works
                            }
                            if (e.Button == MouseButtons.Right)
                            {
                                MessageBox.Show("Right Button"); // Does not work  
                            }
                        }  
                    }
                    

                    }

                    B Offline
                    B Offline
                    Bernhard Hiller
                    wrote on last edited by
                    #9

                    Perhaps the MouseDown and MouseUp events could help.

                    1 Reply Last reply
                    0
                    • E electriac

                      I do not understand why the right button does not work??

                      namespace mouseclick
                      {
                      public partial class Form1 : Form
                      {
                      public Form1()
                      {
                      InitializeComponent();
                      listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
                      listBox1.Items.Add("aaaaaaaaaaaa");
                      listBox1.Items.Add("aaaaaaaaaaaa");
                      listBox1.Items.Add("aaaaaaaaaaaa");
                      }

                          void listBox1\_MouseClick(object sender, MouseEventArgs e)
                          {
                              if (e.Button == MouseButtons.Left)
                              {
                                  MessageBox.Show("Left Button"); // Works
                              }
                              if (e.Button == MouseButtons.Right)
                              {
                                  MessageBox.Show("Right Button"); // Does not work  
                              }
                          }  
                      }
                      

                      }

                      R Offline
                      R Offline
                      raeeschaudhary
                      wrote on last edited by
                      #10

                      better use else if in second condition if (e.Button == MouseButtons.Left) { MessageBox.Show("Left Button"); } else if (e.Button == MouseButtons.Right) { MessageBox.Show("Right Button"); }

                      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