Question

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?

Was it helpful?

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

OTHER TIPS

I was working on a similar situation. We wanted to make the text area behave the same as the button on the right. (IE the user clicks and gets the drop down box)

davidsbro is similar to what I ended up doing, but we wanted it to close if they clicked again, so the value became dropDown.DroppedDown = !dropDown.DroppedDown;.

The issue with this is that if the user clicks the right button of the drop down box, the dialog box opens, then calls the onClick event.

I solved this situation by tracking the original state via the onmouseover event. If the value has changed, we have to assume that the button on the select box handled the click already.

private bool cbDropDownState = false;
private void dropDown_MouseEnter(object sender, EventArgs e)
{
    cbDropDownState  = dropDown.DroppedDown;
}

private void dropDown_Click(object sender, EventArgs e)
{
    if (dropDown.DroppedDown == cbDropDownState )
        dropDown.DroppedDown = !dropDown.DroppedDown;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top