double click on combobox

  • Thread starter Thread starter Wajih-ur-Rehman
  • Start date Start date
W

Wajih-ur-Rehman

I am developing a C# app. I want to do something when someone double clicks
on a combo box. But this event never fires. Any suggestions? Thanx!
 
You can capture the double click by keeping track of the time between
clicks. Here's an example using the MouseDown event. Note that you could
use the Click event just as easily.

using System;
using System.Drawing;
using System.Windows.Forms;

class DoubleClickCombo : Form
{
ComboBox box = new ComboBox();

// Keeps track of the time of the last click
DateTime LastClick = DateTime.Now;

public DoubleClickCombo()
{
// Combo box
box.Location = new Point(5, 5);
box.Parent = this;
box.MouseDown += new MouseEventHandler(box_MouseDown);
}

private void box_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
TimeSpan Current = DateTime.Now - LastClick;
TimeSpan DblClickSpan =
TimeSpan.FromMilliseconds(SystemInformation.DoubleClickTime);

if (Current.TotalMilliseconds <= DblClickSpan.TotalMilliseconds)
{
// Code to handle double click goes here
}

LastClick = DateTime.Now;
}
}
}

--------------------
 
Thanx a lot james, it worked :) Just for my own understanding, why doesnt
this work for a combo box
private void combobox_DoubleClick(object sender, System.EventArgs e)

Regards

Wajih
 
Back
Top