George Summer
George Summer

Reputation: 35

Invisible controls drawing over graphic object

I have a method where I disable or enable some custom controls and then use a graphics object to draw lines and rectangles.

The gist of the method:

void MyMethod()

{

//...

mycontrol.enabled = false;

mycontrol.visible = false;

mycontrol.Invalidate();

mycontrol.Update();

GraphicsObject.DrawLines();

//...

}

Right after this method returns, the screen looks great. I have rectangles and lines where controls used to be.

However, after the click event handler returns (which called the above method). The controls which should be invisible draw over the lines and rectangles (leaving those area's blank - the same color as the background form).

Is there any way to fix this?

Thanks

Upvotes: 1

Views: 560

Answers (1)

Mark Hall
Mark Hall

Reputation: 54562

As I mentioned in my comment if you are drawing on an object if you do not use the OnPaint Method or the Paint Event your custom drawing will not be automatically redrawn. Depending on what you are drawing on you can do something like( I am assuming you are drawing on a Form).

void MyMethod() 
{ 
    //... 
    mycontrol.enabled = false; 
    mycontrol.visible = false; 
    mycontrol.Invalidate(); 
    mycontrol.Update(); 
    this.Invalidate(); 
} 


private void Form1_Paint(object sender, PaintEventArgs e)
{
    //Conditional Logic to determine what you are drawing
    // myPoints is a Point array that you fill elsewhere in your program

    e.Graphics.DrawLines(new Pen(Brushes.Red), myPoints);

}

Upvotes: 1

Related Questions