Beispiel #1
0
        /// <summary>
        /// Construct an Entry instance from the given template.
        /// </summary>
        /// <param name="template"></param>
        public Entry(EntryTemplate template)
            : base(template)
        {
            this.Label = template.Label;

            if (this.Size.Width < 3 || this.Size.Height < 3)
            {
                template.HasFrameBorder = false;
            }
            this.HasFrame = template.HasFrameBorder;

            MaximumCharacters = template.CalculateMaxCharacters();

            CommitOnLostFocus = template.CommitOnLostFocus;
            ReplaceOnFirstKey = template.ReplaceOnFirstKey;

            this.CanHaveKeyboardFocus = template.CanHaveKeyboardFocus;
            this.HilightWhenMouseOver = template.HilightWhenMouseOver;

            this.VerticalAlign = template.VerticalAlign;
            this.LabelAlign    = template.LabelAlign;

            this.CurrentText          = "";
            this._waitingToCommitText = false;
            this.TextInput            = CurrentText;

            CalcMetrics(template);
        }
Beispiel #2
0
        private void CalcMetrics(EntryTemplate template)
        {
            Rectangle viewRect = this.LocalRect;

            if (template.HasFrameBorder)
            {
                viewRect = viewRect.Inflate(-1, -1);
            }

            int remaining = viewRect.Size.Width;

            int labelLength = template.Label.Length;
            int fieldLength = template.CalculateMaxCharacters();

            remaining -= fieldLength;

            if (remaining < 0)
            {
                fieldLength += remaining;
                labelLength  = 0;
            }
            else
            {
                remaining -= labelLength;

                labelLength += remaining - 1;
            }

            if (labelLength < 1)
            {
                Label       = "";
                labelLength = 0;
            }

            _labelRect = new Rectangle(viewRect.TopLeft, new Size(labelLength, viewRect.Size.Height));
            _fieldRect = new Rectangle(_labelRect.TopRight,
                                       new Size(fieldLength, viewRect.Size.Height));

            switch (VerticalAlign)
            {
            case VerticalAlignment.Top:
                _cursorY = _fieldRect.Top;
                break;

            case VerticalAlignment.Center:
                _cursorY = _fieldRect.Center.Y;
                break;

            case VerticalAlignment.Bottom:
                _cursorY = _fieldRect.Bottom - 1;
                break;
            }
        }