Exemplo n.º 1
0
        private void ShowActionDialog()
        {
            if (actionChangeDialog != null)
            {
                //if we are reentering, that means the user hit the button twice
                //let's dismiss the dialog in that case.

                actionChangeDialog.Dismiss();
                return;
            }

            try
            {
                using (var black = new BlackBackground())
                using (var picker = new ActionChangeDialog(currentState))
                {
                    actionChangeDialog = picker;
                    button.State = ButtonState.Red;
                    SetNotifyIcon();

                    black.Show();
                    var result = picker.ShowDialog(black);
                    black.Close();
                    if (closing) return;

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        StopTracking();
                        currentState = picker.NewState;
                        startInfo = picker.ExtraInfo;
                        StartTracking();

                    }
                }

                button.State = ButtonState.Green;

                SetNotifyIcon();
            }
            finally
            {
                actionChangeDialog = null;
            }
        }
Exemplo n.º 2
0
        void button_ButtonPress(object sender, EventArgs e)
        {
            if (closing) return;

            Action action = () =>
            {
                if (alreadyShowing) return;
                alreadyShowing = true;
                try
                {
                    using (var picker = new ActionChangeDialog(currentState))
                    {

                        button.State = ButtonState.Red;
                        notifyIcon1.Icon = icons.icoRed;

                        var result = picker.ShowDialog(this);
                        if (closing) return;

                        if (result == System.Windows.Forms.DialogResult.OK)
                        {
                            StopTracking();
                            currentState = picker.NewState;
                            startInfo = picker.ExtraInfo;
                            StartTracking();

                        }
                    }

                    notifyIcon1.Icon = icons.icoGreen;
                    button.State = ButtonState.Green;

                    UpdateIcon();
                }
                finally
                {
                    alreadyShowing = false;
                }

            };

            if (this.InvokeRequired)
            {
                this.BeginInvoke(action);
            }
            else
            {
                action();
            }
        }