Asked By Jeff Johnson
26-Jun-07 05:15 PM

A while back I needed a "More/Less" button which expanded or collapsed a
form, and I wanted a nice up/down arrow for it as opposed to the more common
like this:
private void MoreInfoButton_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
Font f = new Font("Marlett", MoreInfoButton.Font.Size * 1.1f);
string Arrow;
float TextWidth;
if (_expanded)
Arrow = "5";
else
Arrow = "6";
TextWidth = g.MeasureString(MoreInfoButton.Text,
MoreInfoButton.Font).Width;
g.DrawString(Arrow, f, SystemBrushes.ControlText, TextWidth - 6,
(e.ClipRectangle.Height - g.MeasureString(Arrow, f).Height) / 2);
}
There's some "fudge factor" numbers going on there which were necessary (if
I remember right) because Graphics.MeasureString() wasn't returning a 100%
correct result. However, this was written in .NET 1.1 and maybe this has
changed in 2.0.
As for the dropdown, you could simply create a ContextMenu[Strip] and
display it directly below your button when clicked.