Thursday, October 15, 2009

TImageButton's new feature



Some developers wished to display the Transparent ImageButton with additional information e.g. number of unread e-mails or SMS just like you can see on the screenshot above.

(1.) Default ImageButton's text (you can change it by Text property)
(2.) Additional text

With the new event called "Painted" you can do that with ease.
Here is the code:

private void tImageButton1_Painted(object sender, PaintEventArgs e)
{
float x = (float)(e.ClipRectangle.X + e.ClipRectangle.Width);
float y = (float)(e.ClipRectangle.Y + 4);

Font font= new Font(FontFamily.GenericSerif, 8.0F, FontStyle.Regular);
using (SolidBrush brush = new SolidBrush(Color.White))
{
string text = "(1)";

// Adjust position
SizeF textSize = e.Graphics.MeasureString(text, font);
x -= (textSize.Width + 4);

e.Graphics.DrawString(text, font, brush, x, y);
}

font.Dispose();
font = null;
}

Don't forget to use the right location:
float x = (float)(e.ClipRectangle.X + e.ClipRectangle.Width);
float y = (float)(e.ClipRectangle.Y + 4);

This event is available with the latest version of TControls: v.2.0.3.14.

Product's page:
http://beemobile4.net/?sitecateg=products&productID=5