Search code examples
c#visual-studio-2008comboboxtouchscreennumericupdown

ComboBox show dropdown menu on text selection


I want to show the list of items in a combo box when the user selects the text. I have a touch screen application and it's very difficult to hit the dropdown arrow so I figure I'd show the menu when the text is selected which is often what gets touched. I'm using VS 2008. and suggestions for a touch friendly numeric up down solution in VS2008?


Solution

  • You could use the ComboBox.Click event handler and the ComboBox.DroppedDown property and do something like this:

    private void ComboBox1_Click(System.Object sender, System.EventArgs e)
    {
        ComboBox1.DroppedDown = true;
    }
    

    You could also use the same event handler for a numericUpDown and use the mouseposition as well as the position and height of the NumericUpDown to get whether or not the click was above or below the halfway-line of the control by doing something like this (not sure if my math here is perfect, but it worked when I tested it):

    if ((MousePosition.Y - this.PointToScreen(NumericUpDown1.Location).Y < NumericUpDown1.Height / 2)) 
    {
        NumericUpDown1.Value += 1;
    }
    else 
    {
        NumericUpDown1.Value -= 1;
    }
    

    HTH