/// <summary>
        /// Measure one line of tooltip text calcuating formatting
        /// </summary>
        /// <param name="g"></param>
        /// <param name="txt"></param>
        /// <returns></returns>
        protected virtual Size MeasureToolTipString( Graphics g, string txt )
        {
            Size sizeText;
              int maxHeight = 0;
              int totalWidht = 0;

              string  tempString = txt;
              Stack   stack = new Stack();

              ToolTipStringFormatter frmtString = new ToolTipStringFormatter( this );

              stack.Push( frmtString.Clone() );

              do
              {
            Match   mt = m_regex.Match( tempString );

            if( mt.Success == true )
            {
              string pretext  = mt.Groups[1].Value;
              string formatId = mt.Groups[2].Value;
              string text     = mt.Groups[3].Value;

              tempString = tempString.Remove( 0, mt.Groups[0].Value.Length );
              frmtString.CopyFrom( (ToolTipStringFormatter)stack.Peek() );

              sizeText = MeasureStringByFormat( g, frmtString, pretext );
              maxHeight = Math.Max( maxHeight, sizeText.Height );
              totalWidht += sizeText.Width;

              DetectFormatting( ref frmtString, formatId );

              if( IsStringWithFormat( text ) )
              {
            stack.Push( frmtString.Clone() );
            tempString = text + "</stack>" + tempString;
            continue;
              }
              else
              {
            int pos = text.IndexOf( "</stack>" );
            int left = pos + "</stack>".Length;

            if( pos != -1 )
            {
              tempString = text.Substring( left, text.Length - left ) + tempString;
              text = text.Substring( 0, pos );
            }

            sizeText = MeasureStringByFormat( g, frmtString, text );
            maxHeight = Math.Max( maxHeight, sizeText.Height );
            totalWidht += sizeText.Width;

            if( pos != -1 ) stack.Pop();
              }
            }
            else
            {
              int pos = 0;

              while( -1 != ( pos = tempString.IndexOf( "</stack>" ) ) )
              {
            int left = pos + "</stack>".Length;
            string text = tempString.Substring( 0, pos );

            tempString = tempString.Substring( left, tempString.Length - left );

            sizeText = MeasureStringByFormat( g, (ToolTipStringFormatter)stack.Peek(), text );
            maxHeight = Math.Max( maxHeight, sizeText.Height );
            totalWidht += sizeText.Width;

            stack.Pop();
              }

              sizeText = MeasureStringByFormat( g, (ToolTipStringFormatter)stack.Peek(), tempString );
              maxHeight = Math.Max( maxHeight, sizeText.Height );
              totalWidht += sizeText.Width;
              tempString = "";
            }

            if( tempString.Length == 0 ) break;
              }
              while( true );

              stack.Clear();

              return new Size( totalWidht, maxHeight );
        }
Example #2
0
        /// <summary>
        /// Draw one line of tooltip text with formatting
        /// </summary>
        /// <param name="g"></param>
        /// <param name="pntStart"></param>
        /// <param name="txt"></param>
        protected virtual void DrawToolTipString(Graphics g, Point pntStart, string txt)
        {
            string tempString = txt;
            Stack  stack      = new Stack();

            ToolTipStringFormatter frmtString = new ToolTipStringFormatter(this);

            stack.Push(frmtString.Clone());

            do
            {
                Match mt = m_regex.Match(tempString);

                if (mt.Success == true)
                {
                    string pretext  = mt.Groups[1].Value;
                    string formatId = mt.Groups[2].Value;
                    string text     = mt.Groups[3].Value;

                    tempString = tempString.Remove(0, mt.Groups[0].Value.Length);
                    frmtString.CopyFrom((ToolTipStringFormatter)stack.Peek());

                    DrawStringByFormat(g, ref pntStart, frmtString, pretext);
                    DetectFormatting(ref frmtString, formatId);

                    if (IsStringWithFormat(text))
                    {
                        stack.Push(frmtString.Clone());
                        tempString = text + "</stack>" + tempString;
                        continue;
                    }
                    else
                    {
                        int pos  = text.IndexOf("</stack>");
                        int left = pos + "</stack>".Length;

                        if (pos != -1)
                        {
                            tempString = text.Substring(left, text.Length - left) + tempString;
                            text       = text.Substring(0, pos);
                        }

                        DrawStringByFormat(g, ref pntStart, frmtString, text);

                        if (pos != -1)
                        {
                            stack.Pop();
                        }
                    }
                }
                else
                {
                    int pos = 0;

                    while (-1 != (pos = tempString.IndexOf("</stack>")))
                    {
                        int    left = pos + "</stack>".Length;
                        string text = tempString.Substring(0, pos);

                        tempString = tempString.Substring(left, tempString.Length - left);

                        DrawStringByFormat(g, ref pntStart, (ToolTipStringFormatter)stack.Peek(), text);
                        stack.Pop();
                    }

                    DrawStringByFormat(g, ref pntStart, (ToolTipStringFormatter)stack.Peek(), tempString);
                    tempString = "";
                }

                if (tempString.Length == 0)
                {
                    break;
                }
            }while(true);

            stack.Clear();
        }
        /// <summary>
        /// Draw one line of tooltip text with formatting
        /// </summary>
        /// <param name="g"></param>
        /// <param name="pntStart"></param>
        /// <param name="txt"></param>
        protected virtual void DrawToolTipString( Graphics g, Point pntStart, string txt )
        {
            string  tempString = txt;
              Stack   stack = new Stack();

              ToolTipStringFormatter frmtString = new ToolTipStringFormatter( this );

              stack.Push( frmtString.Clone() );

              do
              {
            Match   mt = m_regex.Match( tempString );

            if( mt.Success == true )
            {
              string pretext  = mt.Groups[1].Value;
              string formatId = mt.Groups[2].Value;
              string text     = mt.Groups[3].Value;

              tempString = tempString.Remove( 0, mt.Groups[0].Value.Length );
              frmtString.CopyFrom( (ToolTipStringFormatter)stack.Peek() );

              DrawStringByFormat( g, ref pntStart, frmtString, pretext );
              DetectFormatting( ref frmtString, formatId );

              if( IsStringWithFormat( text ) )
              {
            stack.Push( frmtString.Clone() );
            tempString = text + "</stack>" + tempString;
            continue;
              }
              else
              {
            int pos = text.IndexOf( "</stack>" );
            int left = pos + "</stack>".Length;

            if( pos != -1 )
            {
              tempString = text.Substring( left, text.Length - left ) + tempString;
              text = text.Substring( 0, pos );
            }

            DrawStringByFormat( g, ref pntStart, frmtString, text );

            if( pos != -1 ) stack.Pop();
              }
            }
            else
            {
              int pos = 0;

              while( -1 != ( pos = tempString.IndexOf( "</stack>" ) ) )
              {
            int left = pos + "</stack>".Length;
            string text = tempString.Substring( 0, pos );

            tempString = tempString.Substring( left, tempString.Length - left );

            DrawStringByFormat( g, ref pntStart, (ToolTipStringFormatter)stack.Peek(), text );
            stack.Pop();
              }

              DrawStringByFormat( g, ref pntStart, (ToolTipStringFormatter)stack.Peek(), tempString );
              tempString = "";
            }

            if( tempString.Length == 0 ) break;
              }
              while( true );

              stack.Clear();
        }
Example #4
0
        /// <summary>
        /// Measure one line of tooltip text calcuating formatting
        /// </summary>
        /// <param name="g"></param>
        /// <param name="txt"></param>
        /// <returns></returns>
        protected virtual Size MeasureToolTipString(Graphics g, string txt)
        {
            Size sizeText;
            int  maxHeight  = 0;
            int  totalWidht = 0;

            string tempString = txt;
            Stack  stack      = new Stack();

            ToolTipStringFormatter frmtString = new ToolTipStringFormatter(this);

            stack.Push(frmtString.Clone());

            do
            {
                Match mt = m_regex.Match(tempString);

                if (mt.Success == true)
                {
                    string pretext  = mt.Groups[1].Value;
                    string formatId = mt.Groups[2].Value;
                    string text     = mt.Groups[3].Value;

                    tempString = tempString.Remove(0, mt.Groups[0].Value.Length);
                    frmtString.CopyFrom((ToolTipStringFormatter)stack.Peek());

                    sizeText    = MeasureStringByFormat(g, frmtString, pretext);
                    maxHeight   = Math.Max(maxHeight, sizeText.Height);
                    totalWidht += sizeText.Width;

                    DetectFormatting(ref frmtString, formatId);

                    if (IsStringWithFormat(text))
                    {
                        stack.Push(frmtString.Clone());
                        tempString = text + "</stack>" + tempString;
                        continue;
                    }
                    else
                    {
                        int pos  = text.IndexOf("</stack>");
                        int left = pos + "</stack>".Length;

                        if (pos != -1)
                        {
                            tempString = text.Substring(left, text.Length - left) + tempString;
                            text       = text.Substring(0, pos);
                        }

                        sizeText    = MeasureStringByFormat(g, frmtString, text);
                        maxHeight   = Math.Max(maxHeight, sizeText.Height);
                        totalWidht += sizeText.Width;

                        if (pos != -1)
                        {
                            stack.Pop();
                        }
                    }
                }
                else
                {
                    int pos = 0;

                    while (-1 != (pos = tempString.IndexOf("</stack>")))
                    {
                        int    left = pos + "</stack>".Length;
                        string text = tempString.Substring(0, pos);

                        tempString = tempString.Substring(left, tempString.Length - left);

                        sizeText    = MeasureStringByFormat(g, (ToolTipStringFormatter)stack.Peek(), text);
                        maxHeight   = Math.Max(maxHeight, sizeText.Height);
                        totalWidht += sizeText.Width;

                        stack.Pop();
                    }

                    sizeText    = MeasureStringByFormat(g, (ToolTipStringFormatter)stack.Peek(), tempString);
                    maxHeight   = Math.Max(maxHeight, sizeText.Height);
                    totalWidht += sizeText.Width;
                    tempString  = "";
                }

                if (tempString.Length == 0)
                {
                    break;
                }
            }while(true);

            stack.Clear();

            return(new Size(totalWidht, maxHeight));
        }