Thread: Custom buttons and OnPaint Issues

  1. #1
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120

    Custom buttons and OnPaint Issues

    Ok, so i am creating a custom shaped button and I am overriding the OnPaint method in the class and using regions within it to get the shape i wanted. this is is my over rode OnPaint
    Code:
    protected override void OnPaint(PaintEventArgs e)
    {
        GraphicsPath myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
        myGraphicsPath.AddRectangle(new Rectangle(80, 0, 40, 40));
        myGraphicsPath.AddRectangle(new Rectangle(40, 40, 80, 40));
        myGraphicsPath.AddRectangle(new Rectangle(0, 80, 80, 40));
        this.Region = new Region(myGraphicsPath);
        myGraphicsPath.Dispose();
    }
    when i initially load the application with this custom button on it, the button region is black.

    when i mouse over it, it has what looks like one of the other buttons on my application sort of shadowing it.

    click to see the image

    On the image linked above, you can see that the top portion of that shape has half a button and is a different BG color than the rest of it.

    Anyone have an idea why this happens?

    I can pull the same stuff from about and put in an button_Paint method and re-assign the Paint function through the designer and it works fine. Is there something else I am missing when you override an OnPaint?
    Last edited by AtomRiot; 05-10-2007 at 03:36 PM.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  2. #2
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    ok, i figured out something that works.

    I added this to the OnPaint method in the class before i start defining a region
    Code:
    Graphics gfx = e.Graphics;
    gfx.Clear(this.BackColor);
    It works fine now.

    thanks for the mental stimulation.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

Popular pages Recent additions subscribe to a feed