Reputation: 1270
I am trying to add help functionality to some of my controls and i am having difficulty in selecting the control for help how i would like to.
This is what i would like to do.
Currently i have everything implemented excpet #3, i can do a MouseDown event, that way my click event won't fire when selected(works ok, except for the outline). Does anyone have an idea how i can outline the control and what event would be appropriate to fire when clicked?
Upvotes: 0
Views: 1721
Reputation: 5367
Partial Answer. Here is where I'd start.
Assuming: isInHelpMode
is a private instance variable within the application that is being set to true when Help button is clicked...
Somewhere in the app:
myControl.MouseHover += (sender,eventArgs) =>
{
if(isInHelpMode)
{// draw blue outline
// insert your code to draw the blue outline
}
}
Upvotes: 1
Reputation: 7862
Expanding upon jberger's answer, you can use the Control's MouseHover event to draw a rectangle around the control similar to this:
private void Control_MouseHover ( object sender, EventArgs e ) {
if ( inHelpMode ) {
var c = (Control)sender;
var rect = c.Bounds;
rect.Inflate(1,1);
var g = CreateGraphics ();
ControlPaint.DrawBorder ( g, rect, Color.Blue, ButtonBorderStyle.Solid );
}
}
This assumes you have a private instance variable inHelpMode
that you are setting when the user clicks the Help button.
You likely will also want to remove the blue outline from the control when the user moves the focus of the mouse off of the control. To do that you can use the MouseLeave event:
private void Control_MouseLeave ( object sender, EventArgs e ) {
Invalidate ();
}
Upvotes: 3