开发者

Open only one form in event

When a particular event appears, I want to open a new Form (using ShowDialog), and while this dialog is open, I want to ignore / dequeue all incoming similar events raised.

It's possible? How?

My event method in which I try to manage is like :

void barcode_Scanned(object sender, string value)
{
    if(value.StartsWith("d")
    {
        // ShowDialog
    }
}

Scenario:

  • BarCode Sca开发者_如何学Gon
  • otherForm.ShowDialog()
  • BarCode Scan -> Ignored because dialog already opened
  • BarCode Scan -> Ignored because dialog already opened
  • otherForm is closed
  • BarCode Scan
  • otherForm.ShowDialog() -> Possible because previous closed

Thanks !


You could disconnect the event upon receiving a scan and reconnect when you're ready.

void barcode_Scanned(object sender, string value)
{
    barcode.Scanned -= barcode_Scanned;

    // do work

    barcode.Scanned += barcode_Scanned;
}


You could simply use a variable or property, such that:

private bool isDialogOpen = false;

void barcode_Scanned(object sender, string value)
{    
    if(value.StartsWith("d") && !isDialogOpen)
    {
        isDialogOpen = true;
        // ShowDialog            
        isDialogOpen = false;
    }
}


If you want to stop everything else doing anything, try opening a Modal Dialog Box, that will stop you from using the other forms while that one is open if that's what you need and/or if it works?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜