PDA

View Full Version : ریست تایمر



homayon_azizi
یک شنبه 08 مرداد 1391, 17:09 عصر
سلام عرض میکنم خدمت اساتید محترم و دوستان
من دارم یه برنامه می نویسم ، حالا میخوام اگه رو عکس کلیک کردم عکسم zoom in شه و اگه دوباره کلیک کردم عسکم zoom out شه.
حالا خودم اینا رو نوشتم و مشکلی هم ندارم بابتش. مشکل من اینجاست که میخوام با افکت زوم شه و کد افکتشم نوشتم ولی فقط برای بار اول افکته اعمال میشه ، میخوام به ازای هر بار زوم شدن اون افکته فعال باشه.
اینم سورس کامل برنامه : :ناراحت:

Mahmoud.Afrad
یک شنبه 08 مرداد 1391, 19:15 عصر
توی این مثال کار توقف تایمرو باید توی خود تایمر انجام بدید
private void timer1_Tick(object sender, EventArgs e)
{
if (x)
{
height += 10;
width += 10;
}
else if (y)
{
height -= 10;
width -= 10;
}

rec = new Rectangle((pictureBox1.Width-width) / 2, (pictureBox1.Height-height) / 2, width, height);
shape.Reset();
shape.AddRectangle(rec);
pictureBox1.Region = new Region(shape);


if (x && pictureBox1.Size.Height <= rec.Size.Height && pictureBox1.Size.Width <= rec.Size.Width)
timer1.Enabled = false;
else if (y && pictureBox1.Size.Height >= rec.Size.Height && pictureBox1.Size.Width >= rec.Size.Width)
timer1.Enabled = false;
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && x == false)
{
timer1.Enabled = true;
pictureBox1.Width += 400;
pictureBox1.Height += 400;
x = true;
y = false;
}

else if (e.Button == MouseButtons.Left && y == false)
{
timer1.Enabled = true;
pictureBox1.Width -= 400;
pictureBox1.Height -= 400;
y = true;
x = false;
}
}افکت کوچک شدن با خودت

homayon_azizi
دوشنبه 09 مرداد 1391, 15:29 عصر
توی این مثال کار توقف تایمرو باید توی خود تایمر انجام بدید
private void timer1_Tick(object sender, EventArgs e)
{
if (x)
{
height += 10;
width += 10;
}
else if (y)
{
height -= 10;
width -= 10;
}

rec = new Rectangle((pictureBox1.Width-width) / 2, (pictureBox1.Height-height) / 2, width, height);
shape.Reset();
shape.AddRectangle(rec);
pictureBox1.Region = new Region(shape);


if (x && pictureBox1.Size.Height <= rec.Size.Height && pictureBox1.Size.Width <= rec.Size.Width)
timer1.Enabled = false;
else if (y && pictureBox1.Size.Height >= rec.Size.Height && pictureBox1.Size.Width >= rec.Size.Width)
timer1.Enabled = false;
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && x == false)
{
timer1.Enabled = true;
pictureBox1.Width += 400;
pictureBox1.Height += 400;
x = true;
y = false;
}

else if (e.Button == MouseButtons.Left && y == false)
{
timer1.Enabled = true;
pictureBox1.Width -= 400;
pictureBox1.Height -= 400;
y = true;
x = false;
}
}افکت کوچک شدن با خودت


مرسی ، من افکت کوچیک شدنشم نوشتم ولی عکسم کلاٌ از تو صفحه محو میشه. اگه میشه راهنمایی کنید که من چیکار باید بکنم تا با استفاده از zoom out ، هم با افکت بسته شه و هم عکسم به نقطه اول خودش برگرده. :خجالت:

Mahmoud.Afrad
دوشنبه 09 مرداد 1391, 19:46 عصر
فرم لود اضافه شد، case2 اصلاح شد
private Boolean x = false;
private Boolean y = false;
private GraphicsPath shape = new GraphicsPath();
private int height, width, Model;
private Rectangle rec;
private Size originalSize;

private void Form1_Load(object sender, EventArgs e)
{
originalSize = pictureBox1.Size;
}

private void timer1_Tick(object sender, EventArgs e)
{
switch (Model)
{
case 1:
height += 10;
width += 10;
rec = new Rectangle((pictureBox1.Width - width) / 2, (pictureBox1.Height - height) / 2, width, height);
shape.Reset();
shape.AddRectangle(rec);
pictureBox1.Region = new Region(shape);

if (pictureBox1.Size.Height <= rec.Size.Height && pictureBox1.Size.Width <= rec.Size.Width)
timer1.Enabled = false;
if (height <= 0)
{
Model = 0;
}
break;
case 2:
height -= 10;
width -= 10;
rec = new Rectangle((pictureBox1.Width - width) / 2, (pictureBox1.Height - height) / 2, width, height);
shape.Reset();
shape.AddRectangle(rec);
pictureBox1.Region = new Region(shape);

if (originalSize.Height >= rec.Size.Height && originalSize.Width >= rec.Size.Width)
{
timer1.Enabled = false;
pictureBox1.Size = originalSize;
rec.Location = pictureBox1.Location;
shape.Reset();
shape.AddRectangle(rec);
pictureBox1.Region = new Region(shape);

Model = 0;
}
break;
}
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && x == false)
{
Model = 1;
timer1.Enabled = true;
pictureBox1.Width += 400;
pictureBox1.Height += 400;
x = true;
y = false;
}

else if (e.Button == MouseButtons.Left && y == false)
{
Model = 2;
timer1.Enabled = true;
height = pictureBox1.Height;
width = pictureBox1.Width;
y = true;
x = false;
}
}