Пример #1
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            ignoreFocusChange = true;

            if (e.KeyCode == Keys.Return && Focused)
            {
                var args = new CancelEventArgs();
                ValueEntered?.Invoke(this, args);
                if (!args.Cancel)
                {
                    ForeColor = SystemColors.ControlText;
                    focusControl.Focus();       //because Microsoft forgot to put in Unfocus() smh
                    suggestionsDropDown.Hide(); //because OnLostFocus won't get called
                    e.SuppressKeyPress = true;
                }
                else
                {
                    ForeColor = Color.Red;
                }
            }
            else
            {
                base.OnKeyDown(e);
            }

            ignoreFocusChange = false;
        }
Пример #2
0
        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);

            if (ignoreFocusChange)
            {
                return;
            }

            Form parentForm = this.FindForm();

            if (parentForm != null && parentForm.ContainsFocus) //another Control inside the parent form got focused, we can be very sure that this was intentional
            {
                var args = new CancelEventArgs();
                ValueEntered?.Invoke(this, args);
                if (args.Cancel)
                {
                    ForeColor = Color.Red; //mark the value red to indicate it's invalid
                }
                else
                {
                    ForeColor = SystemColors.ControlText;
                }
            }

            suggestionsDropDown.Hide();
        }
Пример #3
0
        static void Main(string[] args)
        {
            var busControl = ConfigureBus();
            var run        = true;

            busControl.Start();
            Console.WriteLine("Enter message (or ctrl+c to exit)");
            try
            {
                while (run)
                {
                    Console.Write("> ");
                    var value = Console.ReadLine();
                    if (!string.IsNullOrEmpty(value))
                    {
                        busControl.Publish(ValueEntered.Create(value));
                        Console.WriteLine($"published {value}");
                    }
                }
            }
            finally
            {
                busControl.Stop();
            }
        }
Пример #4
0
        //--------------------------------------------------------------------------------------------------

        void _OnSourceUpdated(object sender, DataTransferEventArgs eventArgs)
        {
            if (eventArgs.TargetObject == ValueEditBox)
            {
                IsInKeyboardMode = false;
                ValueEntered?.Invoke(this, Value);
            }
        }
Пример #5
0
        private void SuggestionsDropDown_ItemSelected(object sender, EventArgs e)
        {
            Text = suggestionsDropDown.SelectedSuggestion;

            var args = new CancelEventArgs();

            ValueEntered?.Invoke(this, args);
            if (args.Cancel)
            {
                ForeColor = Color.Red; //mark the value red to indicate it's invalid
            }
            else
            {
                ForeColor = SystemColors.ControlText;
            }

            ignoreFocusChange = true;
            focusControl.Focus();       //because Microsoft forgot to put in Unfocus() smh
            suggestionsDropDown.Hide(); //because OnLostFocus won't get called
            ignoreFocusChange = false;
        }
Пример #6
0
 public void Add(ValueEntered val)
 {
     messages.Add(val);
 }