Tooltip drawing help (won't size correctly)-VBForums
Results 1 to 2 of 2

Thread: Tooltip drawing help (won't size correctly)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    348

    Tooltip drawing help (won't size correctly)

    I'm pretty terrible at creating custom controls. However, I have a few that work well enough for my current project. My latest attempt is at a tooltip. I can't seem to change the size of the blue filled area.

    The blue rectangle is only ever one size, no matter what code I use. It looks to stay at the bounds, but even the bounds cut off my text.

    With a normal tooltip and the same text it appears just fine. However, the custom drawing is to coincide with the rest program.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    
    namespace FCI_EZ_File
    {
        class FCIToolTip : ToolTip
        {
    
            public FCIToolTip()
            {
                this.OwnerDraw = true;
                this.Draw += new DrawToolTipEventHandler(FCIToolTip_Draw);
            }
    
            private void FCIToolTip_Draw(object sender, DrawToolTipEventArgs e)
            {
                Graphics g = e.Graphics;
                SizeF measureString = g.MeasureString(e.ToolTipText, e.Font);
                //g.FillRectangle(Brushes.Aqua, e.Bounds.X, e.Bounds.Y, measureString.Width+50, measureString.Height+50);
                g.FillRectangle(Brushes.Aqua, 0, 0, 50, 600); //this causes the width to be 400ish as well...
                g.DrawLine(Pens.Black, new Point(e.Bounds.X, e.Bounds.Y), new Point(e.Bounds.X + (int)(measureString.Width + 15), e.Bounds.Y));
                g.DrawLine(Pens.Black, new Point(e.Bounds.X + (int)(measureString.Width + 15), e.Bounds.Y), new Point(e.Bounds.X + (int)(measureString.Width + 15), e.Bounds.Y + (int)(measureString.Height + 15)));
                g.DrawLine(Pens.Black, new Point(e.Bounds.X + (int)(measureString.Width + 15), e.Bounds.Y + (int)(measureString.Height + 15)), new Point(e.Bounds.X, e.Bounds.Y + (int)(measureString.Height + 15)));
                g.DrawLine(Pens.Black, new Point(e.Bounds.X, e.Bounds.Y + (int)(measureString.Height + 15)), new Point(e.Bounds.X, e.Bounds.Y));
                g.DrawString(e.ToolTipText, new Font(e.Font, FontStyle.Bold), Brushes.Black,
                    new PointF(e.Bounds.X+7, e.Bounds.Y+7));
            }
    
        }
    }
    How can I make it so that the tooltip resizes correctly based on whatever text is there?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    348

    Re: Tooltip drawing help (won't size correctly)

    I have figured that if I just draw the text starting at the bounds (instead of padding it some), it fits into my drawn rectangle just barely. Can you not actually define the size of the drawn rectangle in a tooltip then?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.