# Draw Effect Help

• ### Question

• I'm sure this is a easy thing to do, anyone have suggestions on how to create a draw effect with a rectangle. The idea is that it starts small on the outer borders of the screen and grows inward filling in the screen. I have attached some images in order roughly of what I'm want to do.

Tuesday, September 26, 2017 4:02 PM

### Answers

• Just do a loop with DrawRectangle

• Marked as answer by Tuesday, September 26, 2017 5:58 PM
Tuesday, September 26, 2017 4:38 PM

### All replies

• Just do a loop with DrawRectangle

• Marked as answer by Tuesday, September 26, 2017 5:58 PM
Tuesday, September 26, 2017 4:38 PM
• That's what I thought but was hoping there might of been a easier way or a existing function.
Tuesday, September 26, 2017 5:58 PM
• I did not get this working perfectly as I wanted but I can share my snippet. I have a few draw functions I made but I'll share code for just this one so you don't get confused

Paint:

```private void Form1_Paint(object sender, PaintEventArgs e)
{
if(Draw)
{
Pen blackPen = new Pen(Color.Black, 10);
SolidBrush BlackBrush = new SolidBrush(System.Drawing.Color.Black);
int sX = this.Width;
int sY = this.Height;

switch (DrawObject)
{
case 0:
gfx.DrawEllipseRectangle(e);
break;
case 1:
gfx.DrawCircle(e, blackPen, (sX / 2), (sY / 2), 120);
break;
case 2:
gfx.DrawFilledCircle(e, BlackBrush, 200, 200, 120);
break;
case 3:
gfx.DrawExpandingFilledCircle(e, BlackBrush, (sX / 2), (sY / 2), 120, 60, 25);
break;
case 4:
gfx.DrawShrinkingRectangle(e, blackPen, 0, 0, sX, (sY - 5), 60, 5);
break;
default:
break;
}

System.Threading.Thread.Sleep(500);
Draw = false;
this.Refresh();
}
}        ```

Function:

```public void DrawShrinkingRectangle(PaintEventArgs e, Pen pen, int x, int y, int width, int height, int FPS, int Expansion_Rate)
{
int Rate = (1000 / FPS);

do
{
Rectangle Rec = new Rectangle(x, y, width, height);

e.Graphics.DrawRectangle(pen, Rec);
System.Threading.Thread.Sleep(Rate);
x = (x - Expansion_Rate);
y = (y - Expansion_Rate);
width = (width - Expansion_Rate);
height = (height - Expansion_Rate);
} while (height > 0);
}```

Its not perfect but it runs currently off a click event for me. If you change the Pen, you get some fun results.

• Edited by Tuesday, September 26, 2017 8:00 PM
Tuesday, September 26, 2017 7:58 PM