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. Combo box events

Combo box events

Scheduled Pinned Locked Moved C#
help
6 Posts 3 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.
  • G Offline
    G Offline
    gwithey
    wrote on last edited by
    #1

    Hi i have come across a problem using combo box events

      private void comboBox1\_KeyPress(object sender, KeyPressEventArgs e)
      {
         if (Control.ModifierKeys == Keys.Delete)
         {
            imageViewer1.DeleteSelectedShape();
         }
      }
    
      private void comboBox1\_MouseDoubleClick(object sender, MouseEventArgs e)
      {
         comboBox1.Text = "hello";
      }
    

    For some reason the above code is not fired, it is probably a simple constraint i do not know about but can anyone see why this is would not fire. Thanx in advance

    L G C 3 Replies Last reply
    0
    • G gwithey

      Hi i have come across a problem using combo box events

        private void comboBox1\_KeyPress(object sender, KeyPressEventArgs e)
        {
           if (Control.ModifierKeys == Keys.Delete)
           {
              imageViewer1.DeleteSelectedShape();
           }
        }
      
        private void comboBox1\_MouseDoubleClick(object sender, MouseEventArgs e)
        {
           comboBox1.Text = "hello";
        }
      

      For some reason the above code is not fired, it is probably a simple constraint i do not know about but can anyone see why this is would not fire. Thanx in advance

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      I suggest you read the documentation on Control.ModifierKeys, your code is not OK. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      G 1 Reply Last reply
      0
      • L Luc Pattyn

        I suggest you read the documentation on Control.ModifierKeys, your code is not OK. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        G Offline
        G Offline
        gwithey
        wrote on last edited by
        #3

        Ah thanx that was a silly mistake. Modifier keys (SHIFT, CTRL, and ALT) not Del The problem is that when run it doesn't make it that far as the events are never fired

        1 Reply Last reply
        0
        • G gwithey

          Hi i have come across a problem using combo box events

            private void comboBox1\_KeyPress(object sender, KeyPressEventArgs e)
            {
               if (Control.ModifierKeys == Keys.Delete)
               {
                  imageViewer1.DeleteSelectedShape();
               }
            }
          
            private void comboBox1\_MouseDoubleClick(object sender, MouseEventArgs e)
            {
               comboBox1.Text = "hello";
            }
          

          For some reason the above code is not fired, it is probably a simple constraint i do not know about but can anyone see why this is would not fire. Thanx in advance

          G Offline
          G Offline
          gwithey
          wrote on last edited by
          #4

          Just found a solution so thought i would post it : Most controls don,t fire delete on key press so override command key pressed and check value in keypress

          // Override cmd key press
          protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
          {

               if (keyData == Keys.Delete)
          
                  OnKeyPress(new KeyPressEventArgs((Char)Keys.Delete));
          
          
          
               return base.ProcessCmdKey(ref msg, keyData);
          
            }
          
            private void Form1\_KeyPress(object sender, KeyPressEventArgs e)
            {
               if (e.KeyChar == (Char)Keys.Delete)
               {
                  imageViewer1.DeleteSelectedShape();
               }
            }
          

          Thanx for the help George

          L 1 Reply Last reply
          0
          • G gwithey

            Just found a solution so thought i would post it : Most controls don,t fire delete on key press so override command key pressed and check value in keypress

            // Override cmd key press
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {

                 if (keyData == Keys.Delete)
            
                    OnKeyPress(new KeyPressEventArgs((Char)Keys.Delete));
            
            
            
                 return base.ProcessCmdKey(ref msg, keyData);
            
              }
            
              private void Form1\_KeyPress(object sender, KeyPressEventArgs e)
              {
                 if (e.KeyChar == (Char)Keys.Delete)
                 {
                    imageViewer1.DeleteSelectedShape();
                 }
              }
            

            Thanx for the help George

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            sounds fair. Some keys are used to support editing, unless you tell the control otherwise. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            1 Reply Last reply
            0
            • G gwithey

              Hi i have come across a problem using combo box events

                private void comboBox1\_KeyPress(object sender, KeyPressEventArgs e)
                {
                   if (Control.ModifierKeys == Keys.Delete)
                   {
                      imageViewer1.DeleteSelectedShape();
                   }
                }
              
                private void comboBox1\_MouseDoubleClick(object sender, MouseEventArgs e)
                {
                   comboBox1.Text = "hello";
                }
              

              For some reason the above code is not fired, it is probably a simple constraint i do not know about but can anyone see why this is would not fire. Thanx in advance

              C Offline
              C Offline
              carlecomm
              wrote on last edited by
              #6

              try this: private void textBoxSize_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar > 47 && e.KeyChar < 58) || e.KeyChar == 8 || e.KeyChar == 13) { /*do something*/ } }

              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