简体   繁体   中英

ToolStrip StatusLabel DoubleClick Event Doesn't Raise

I'm having trouble with subscribing to the DoubleClick event for a dynamically created ToolStripStatusLabel .

In my code I create a series of ToolStripStatusLabel items inside a StatusStrip , and subscribe to its DoubleClick event, but it looks like it never rises

private void InitStatusBar()
{
    foreach (CardReader cardReader in appConfig.CardReadersList)
    {
        System.Windows.Forms.ToolStripStatusLabel cardReaderStatusLabel = new ToolStripStatusLabel();
        cardReaderStatusLabel.Name = cardReader.Description;
        cardReaderStatusLabel.Tag = cardReader;
        cardReaderStatusLabel.Text = cardReader.Description.ToUpper();
        cardReaderStatusLabel.Image = cardReader.DeviceInfo.GetIconImage();
        cardReaderStatusLabel.DoubleClick += new System.EventHandler(this.cardReaderStatusLabel_DoubleClick);
        this.statusStripBottom.Items.Add(cardReaderStatusLabel);
        this.statusStripBottom.Refresh();
    }
}

private void cardReaderStatusLabel_DoubleClick(object sender, EventArgs e)
{
    ToolStripStatusLabel clickedToolStripLabel = (ToolStripStatusLabel)sender;
    CardReader taggedCardReader = (CardReader)clickedToolStripLabel.Tag;
    MessageBox.Show("Lector: " + taggedCardReader.Description + Environment.NewLine + "Status: " + taggedCardReader.DeviceInfo.CardReaderStatusString);

}

The StatusStrip is correctly initialized (the status labels are added and shown in the status strip) but when I double click on them, nothing happens :(

Is there something I'm missing?

Thanks :)

You should set DoubleClickEnabled property for those items to true , then you can handle DoubleClick event for your ToolStripItem .

ToolStripItem handles double click in its own internal method HandleMouseUp . In the method it checks DoubleClickEnabled property and based on the ticks between the mouse up and last click, decide if it should raise double click event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM