예제 #1
0
        /// <summary>Constructor.</summary>
        public LabelEx()
        {
            _parsed        = EggsML.Parse("");
            DoubleBuffered = true;
            SetStyle(ControlStyles.FixedHeight, false);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            // Set default properties
            TabStop         = false;
            AutoSize        = true;
            LinkColor       = SystemColors.HotTrack;
            LinkActiveColor = Color.Red;
        }
예제 #2
0
        /// <summary>Override; see base.</summary>
        protected override void OnTextChanged(EventArgs e)
        {
            // If a link has focus, trigger the LinkLostFocus event.
            // OnPaint will trigger the LinkGotFocus event as appropriate
            _keyboardFocusOnLink = null;

            _cachedPreferredSizes.Clear();
            _cachedRendering = null;
            base.OnTextChanged(e);
            _mnemonic = '\0';
            TabStop   = false;
            var origText = base.Text;

            try
            {
                _parsed    = EggsML.Parse(origText);
                ParseError = null;

                // We know there are no mnemonics or links in the exception message, so only do this if there was no parse error
                extractMnemonicEtc(_parsed);
            }
            catch (EggsMLParseException epe)
            {
                ParseError = epe;
                var msg = "";
                int ind = 0;
                if (epe.FirstIndex != null)
                {
                    ind  = epe.FirstIndex.Value;
                    msg += EggsML.Escape(origText.Substring(0, ind));
                    msg += "<Red>={0}=".Fmt(EggsML.Escape(origText.Substring(ind, 1)));
                    ind++;
                }
                msg += EggsML.Escape(origText.Substring(ind, epe.Index - ind));
                ind  = epe.Index;
                if (epe.Length > 0)
                {
                    msg += "<Red>={0}=".Fmt(EggsML.Escape(origText.Substring(ind, epe.Length)));
                    ind += epe.Length;
                }
                msg    += "<Red>= ← (" + EggsML.Escape(epe.Message) + ")=";
                msg    += EggsML.Escape(origText.Substring(ind));
                _parsed = EggsML.Parse(msg);
            }
            autosize();
            Invalidate();
        }