I would like to be able to check whether the user clicked the Drop-Down Button of the ComboBox in the MouseClick event handler.
I could not find the size and coordinates of the bordering rectangle of the Drop-Down Button. I am using WinForms.
The task is to check whether the Drop-Down List dropped down (opened, made the items visible) as a result of a programmatic statement: comboBox1.DroppedDown = true; or as the result of the user pressing the Drop-Down Button. Is there any other better way to ascertain this?
According to your last edit, @dr.null comment might solve your requirement. But still you want to make sure that user clicked on the arrow part of the drop down, the following code will do the job.
Notice that the position of the dropdown button part will return as the position in the screen.
private void comboBox1_MouseClick(object sender, MouseEventArgs e)
{
const int COMBOBOX_DROPDOWN_BUTTON_ACC_ITEM_INDEX = 2;
var comboBox = ((ComboBox)sender);
IAccessible accessibilityObjectOfComboBox = comboBox.AccessibilityObject;
accessibilityObjectOfComboBox.accLocation(
out int x,
out int y,
out int width,
out int height,
COMBOBOX_DROPDOWN_BUTTON_ACC_ITEM_INDEX);
var button = new Rectangle(x, y, width, height);
var clickedPoint = new Rectangle(new Point(MousePosition.X, MousePosition.Y), new Size(1, 1));
var IHit = button.IntersectsWith(clickedPoint);
if (IHit)
MessageBox.Show("Happy to be helpful");
}