I have a ToolStripButton inside a ToolStrip that I want to draw a border around. This is the code I am using:
private void tsbtnSearch_Paint(object sender, PaintEventArgs e)
{
ToolStripButton btn = (ToolStripButton)sender;
ControlPaint.DrawBorder(e.Graphics, btn.Bounds,
Color.Red, 3, ButtonBorderStyle.Outset,
Color.Red, 3, ButtonBorderStyle.Outset,
Color.Red, 3, ButtonBorderStyle.Outset,
Color.Red, 3, ButtonBorderStyle.Outset);
}
The border is being drawn as shown in the image below:
What do I need to do to get the coordinates correct?
You are almost there. You can use the simpler variant of
DrawBorder
and define the rectangle of the border manually using the button widht and height:The rectangle of the border is not the bounds of the button in this case (IMO, because the
ToolStripButton
is not a flat button, but a complex objectToolStripItem
, that has more than just the button).