Skip to content

Instantly share code, notes, and snippets.

@eggie5
Created November 6, 2012 05:41
Show Gist options
  • Select an option

  • Save eggie5/4022821 to your computer and use it in GitHub Desktop.

Select an option

Save eggie5/4022821 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int x;
int y;
int rec_width;
int rec_height;
Form1 form_ref = null;
int scale = 1;
Boolean growing= false;
public Form1()
{
InitializeComponent();
form_ref = this;
rec_height = this.Height;
rec_width = this.Width;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Console.WriteLine("scale ={4} x={0}, y={1}, w={2}, h={3}", x, y, rec_width, rec_height, scale);
Rectangle rect = new Rectangle(x, y, rec_width, rec_height);
e.Graphics.DrawRectangle(Pens.Red, rect);
}
private void timer1_Tick(object sender, EventArgs e)
{
x +=scale;
y +=scale;
rec_width = form_ref.Width-(x*2);
rec_height = form_ref.Height-(y*2);
if (growing)
scale--;
else
scale++;
if (rec_width < 0 || rec_height < 0)
{
growing = true;
//reset();
}
else if(rec_width > form_ref.Width || rec_height > form_ref.Height)
growing = false;
Invalidate();
}
private void reset()
{
rec_width = form_ref.Width;
rec_height = form_ref.Height;
x = 0; y = 0;
scale = 1;
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment