Esempio n. 1
0
        /// <summary>
        /// Draw string accordingly to formatting
        /// </summary>
        /// <param name="g"></param>
        /// <param name="start"></param>
        /// <param name="frmt"></param>
        /// <param name="text"></param>
        protected virtual void DrawStringByFormat(Graphics g, ref Point start,
                                                  ToolTipStringFormatter frmt, string text)
        {
            Font  newFont = (Font)frmt;
            Color clr     = (Color)frmt;

            SizeF size = g.MeasureString(text, newFont, 0, m_format);

            g.DrawString(text, newFont, new SolidBrush(clr), start);
            start.X += ( int )(size.Width + 0.5);
        }
Esempio n. 2
0
            public void   CopyFrom(ToolTipStringFormatter obj)
            {
                if (obj == this)
                {
                    return;
                }

                family = obj.family;
                style  = obj.style;
                size   = obj.size;
                color  = obj.color;
            }
Esempio n. 3
0
 /// <summary>
 /// Function detect formatting and accordingly to it change formatting
 /// class states
 /// </summary>
 /// <param name="frmt">formatting class</param>
 /// <param name="id">string Identificator of formatter</param>
 protected virtual void DetectFormatting(ref ToolTipStringFormatter frmt, string id)
 {
     if (string.Compare(id, "b", true) == 0) // bold
     {
         frmt.style |= FontStyle.Bold;
     }
     else if (string.Compare(id, "i", true) == 0) // italic
     {
         frmt.style |= FontStyle.Italic;
     }
     else if (string.Compare(id, "u", true) == 0) // underline
     {
         frmt.style |= FontStyle.Underline;
     }
     else // try to detect is it a color name
     {
         try
         {
             Color clr = Color.FromName(id);
             frmt.color = clr;
         }
         catch {}
     }
 }
Esempio n. 4
0
            public void CopyFrom( ToolTipStringFormatter obj )
            {
                if( obj == this ) return;

                family = obj.family;
                style  = obj.style;
                size   = obj.size;
                color  = obj.color;
            }
Esempio n. 5
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 );
        }
Esempio n. 6
0
 /// <summary>
 /// Measure size of tooltip string accorfing to formatting
 /// </summary>
 /// <param name="g"></param>
 /// <param name="frmt"></param>
 /// <param name="txt"></param>
 /// <returns></returns>
 protected virtual Size MeasureStringByFormat( Graphics g, ToolTipStringFormatter frmt, string txt )
 {
     SizeF size = g.MeasureString( txt, (Font)frmt, 0, m_format );
       return new Size( (int)( size.Width + 0.5 ), (int)( size.Height + 0.5 ) );
 }
Esempio n. 7
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();
        }
Esempio n. 8
0
        /// <summary>
        /// Draw string accordingly to formatting
        /// </summary>
        /// <param name="g"></param>
        /// <param name="start"></param>
        /// <param name="frmt"></param>
        /// <param name="text"></param>
        protected virtual void DrawStringByFormat( Graphics g, ref Point start, 
      ToolTipStringFormatter frmt, string text )
        {
            Font  newFont = (Font)frmt;
              Color clr = (Color)frmt;

              SizeF size = g.MeasureString( text, newFont, 0, m_format );
              g.DrawString( text, newFont, new SolidBrush( clr ), start );
              start.X += ( int )( size.Width + 0.5 );
        }
Esempio n. 9
0
 /// <summary>
 /// Function detect formatting and accordingly to it change formatting 
 /// class states
 /// </summary>
 /// <param name="frmt">formatting class</param>
 /// <param name="id">string Identificator of formatter</param>
 protected virtual void DetectFormatting( ref ToolTipStringFormatter frmt, string id )
 {
     if( string.Compare( id, "b", true ) == 0 ) // bold
       {
     frmt.style |= FontStyle.Bold;
       }
       else if( string.Compare( id, "i", true ) == 0 ) // italic
       {
     frmt.style |= FontStyle.Italic;
       }
       else if( string.Compare( id, "u", true ) == 0 ) // underline
       {
     frmt.style |= FontStyle.Underline;
       }
       else // try to detect is it a color name
       {
     try
     {
       Color clr = Color.FromName( id );
       frmt.color = clr;
     }
     catch{}
       }
 }
Esempio n. 10
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();
        }
Esempio n. 11
0
        /// <summary>
        /// Measure size of tooltip string accorfing to formatting
        /// </summary>
        /// <param name="g"></param>
        /// <param name="frmt"></param>
        /// <param name="txt"></param>
        /// <returns></returns>
        protected virtual Size MeasureStringByFormat(Graphics g, ToolTipStringFormatter frmt, string txt)
        {
            SizeF size = g.MeasureString(txt, (Font)frmt, 0, m_format);

            return(new Size((int)(size.Width + 0.5), (int)(size.Height + 0.5)));
        }
Esempio n. 12
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));
        }