|
-
February 27th, 2009, 03:26 PM
#1
Custom ToolTip is wonky
I've defined a custom ToolTip draw method for one of my tool tips, and it isn't behaving properly.
I'm using C#.NET 2005, creating a Windows-based application.
The problem is, the custom ToolTip_Draw method doesn't delay or use any of the other settings defined by the toolTip. When I mouse over an image, the tooltip pops up RIGHT AWAY, generally obscuring what I'm looking at. It also stays around for quite a while, and follows the mouse around for a while.
What do I need to do to keep all the other settings the same, but just customize the tooltip when it is drawn?
Here's my code for the ToolTip_Draw method
Code:
private void cardToolTip_Draw(object sender, DrawToolTipEventArgs e)
{
Card.drawToolTipText(sender, e);
}
Here's the code called by that method:
Code:
public static void drawToolTipText(object sender, DrawToolTipEventArgs e)
{
Font drawFont = new Font("Times New Roman", 9);
drawFont = new Font(e.Font, new FontStyle());
Font drawFont_default = new Font(drawFont, new FontStyle());
Brush drawBrush = new SolidBrush(Color.Black);
StringFormat drawStrFormat = new StringFormat();
int yShiftIncrement = 15;
e.DrawBackground();
e.DrawBorder();
//split the string into rows, and draw each row seperatley
string tempString_completeText = e.ToolTipText;
tempString_completeText = tempString_completeText.Replace("<i>", "{<i>}");
tempString_completeText = tempString_completeText.Replace("</i>", "{</i>}");
string[] tooltipText_line = tempString_completeText.Split(new string[] { "\r\n", "\n" }, new StringSplitOptions());
int yShift = 5;
for (int i = 0; i <= tooltipText_line.Length - 1; i++)
{//for each row, draw the text and/or icons
if (i > 0)
yShift += yShiftIncrement;
if (tooltipText_line[i].Contains("{"))
{//if the row has an icon in it, process the information
//slpit the string into pieces, using the '{' and '}' designaters
string[] tooltipLine_piece = tooltipText_line[i].Split(new string[] { "}{", "} {", "{", "}" }, new StringSplitOptions());
//create an array of icons, one for each chunk of text
Image[] manaIcons = new Image[tooltipLine_piece.Length];
for (int j = 0; j <= tooltipLine_piece.Length - 1; j++)
manaIcons[j] = Card.getManaIcon(tooltipLine_piece[j]);
int xShift = 5;
for (int j = 0; j <= manaIcons.Length - 1; j++)
{//for each section of the string
if (manaIcons[j].Tag.ToString() == "null_mana")
{
if (tooltipLine_piece[j].Contains("<i>"))
{//if the font format changes to italic
drawFont = new Font(drawFont, FontStyle.Italic);
tooltipLine_piece[j] = tooltipLine_piece[j].Replace("<i>", "");
}
else
{//if the font format changes to NOT italic
if (tooltipLine_piece[j].Contains("</i>"))
{
drawFont = new Font(drawFont_default, new FontStyle());
tooltipLine_piece[j] = tooltipLine_piece[j].Replace("</i>", "");
}
}
//draw the string and measure it's pixel length
if (tooltipLine_piece[j].Trim() != "")
{
e.Graphics.DrawString(tooltipLine_piece[j], drawFont, drawBrush, xShift, yShift, drawStrFormat);
xShift += (int)(e.Graphics.MeasureString(tooltipLine_piece[j] + ".", drawFont)).Width;
}
}
else
{
e.Graphics.DrawImage(manaIcons[j], xShift, yShift, 12, 12);
xShift += 12;
}
}
}//end if(icon in row)
else
{//else, just draw the text
if (tooltipText_line[i].Trim() != "")
e.Graphics.DrawString(tooltipText_line[i], drawFont, drawBrush, 5, yShift, drawStrFormat);
else
yShift -= yShiftIncrement;
}
}
}
Thanks for any help/advice you can give. This bug is really getting annoying. >_<
Card Tracker is a program I started working on to keep track of my collection of Magic cards. After Wizards of the Coast 'upgraded' from Magic Online 2.0 to Magic Online III, they dropped the physical card tracking add-on.
I just released a beta version, and am currently fishing for ideas, suggestions, tips, and any other feedback I can get.
Oh yah, I'm working on this solo to boot.
http://cardtracker.blogspot.com/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|