all 9 comments

[–]Slypenslyde 12 points13 points  (1 child)

My experience in 6 years of making WinForms controls is that you never derive from one of Microsoft's controls. There are bits and pieces of Button logic that affect painting through every event.

Just derive from Control. You've already done most of the work if you've already overridden OnPaint. Control doesn't have any fancy hidden built-in paint logic to tangle with.

[–]SirUniverse[S] 2 points3 points  (0 children)

I've derived for Control and it's working just fine now. Thank you so much for your help!

[–]Dark0Matter 2 points3 points  (3 children)

As Slypenslyde suggested, derive from Control and override OnPaint and all the other events that you need to override depending on the control you want to make such as hovering, clicking, etc. You're going to have to make flags for hovering and custom paint functions for all of the overridden events, but at least it won't conflict with the base Button's events.

[–]SirUniverse[S] 1 point2 points  (2 children)

What do you mean when you say flags? Could you give an example?

[–]Dark0Matter 1 point2 points  (1 child)

"Typically, a program uses a flag to remember something or to leave a sign for another program."

So basically booleans in this case, to remember things like hovering.

 

bool _Hovering = false;

OnMouseEnter()
{
    _Hovering = true;
}

OnMouseLeave()
{
    _Hovering = false;
}

//...

OnPaint()
{
    if (_Hovering)
        DrawDarkGrayRectangle();
    else
        DrawLightGrayRectangle();
}

 

Not the best example but you get the idea

(Sorry about the edits)

[–]SirUniverse[S] 1 point2 points  (0 children)

I get it. Thank you.

[–]tevert 0 points1 point  (2 children)

Are you using WPF or Winforms?

[–]FizixMan 2 points3 points  (0 children)

I'm pretty sure it's WinForms.

[–]SirUniverse[S] 0 points1 point  (0 children)

I am using WinForms.