Reputation: 2283
I need to change back-color of a ToolStripDropDownButton
when its drop-down is opened. How can I do it?
I tried to inherit a class from the ToolStripProfessionalRenderer
and then override the OnRenderDropDownButtonBackground
, but it only affects when the drop-down is closed.
Upvotes: 3
Views: 2494
Reputation: 17848
I believe you can use the following approaches:
1-st approach:
toolStripDropDownButton1.Paint += toolStripDropDownButton1_Paint;
//...
void toolStripDropDownButton1_Paint(object sender, PaintEventArgs e) {
if(toolStripDropDownButton1.Pressed) {
// TODO Paint your pressed button
e.Graphics.FillRectangle(Brushes.Green, e.ClipRectangle);
}
}
2-nd approach:
toolStrip.Renderer = new PressedRenderer();
//...
class PressedRenderer : ToolStripProfessionalRenderer {
protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e) {
if(e.Item.Pressed)
e.Graphics.Clear(Color.Green);
else base.OnRenderDropDownButtonBackground(e);
}
}
Upvotes: 5
Reputation: 1433
Is the OnDropDownOpened
event what you want?
private void toolStripDropDownButton_DropDownOpened(object sender, EventArgs e)
{
toolStripDropDownButton.BackColor = Color.Red;
}
Upvotes: 0