예제 #1
0
        /// <summary>
        /// Used to register a control as a calculation object in this CalcQuick instance.
        /// </summary>
        /// <param name="c">The control to register.</param>
        /// <remarks>
        /// To reference this calculation object from another calculation in this CalcQuick
        /// object, you use the Control.Name string. The value of this calculation object is
        /// bound to the Control.Text property.
        /// </remarks>
        protected virtual void RegisterControl(Control c)
        {
            ////Subscribe once.
            if (this.NameToControlMap.Count == 0)
            {
                this.ValueSet += new QuickValueSetEventHandler(CalcQuickValueSet);
            }

            if (this.ControlModifiedFlags.ContainsKey(c) ||
                this.NameToControlMap.ContainsKey(c.Name))
            {
                throw new ArgumentException(string.Format(this.Engine.FormulaErrorStrings[this.Engine.already_registered], c.Name));
            }

            this.ControlModifiedFlags.Add(c, false);
            NameToControlMap.Add(c.Name.ToUpper(), c);

            if (c.GetType() == typeof(ComboBox))
            {
                //There we will raise the textchanged event of the combobox
                (c as ComboBox).SelectionChanged += new SelectionChangedEventHandler(CalcQuick_SelectionChanged);
            }
            else if (c.GetType() == typeof(TextBox))
            {
                //There we will raise the textchanged event of the combobox
                (c as TextBox).TextChanged += new TextChangedEventHandler(tb_TextChanged);
            }
            c.MouseLeave += new MouseEventHandler(CalcQuick_MouseLeave);
        }