Picturebox’ı formun etrafında dolaştırma C#
Aşağıdaki formu oluşturalım.(resim ekleme–> toolbox’tan picturebox ekliyoruz.Seçip propertiesten image özeliği ile bir resim ekliyoruz.SizeMode özelliğini Stretchİmage yapıyoruz. )
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace picturebox_hareketi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (pictureBox1.Top == 0)
{
pictureBox1.Left += 10;
label1.Text = "Left:" + pictureBox1.Left.ToString() + "n Right:" + pictureBox1.Right.ToString() + "n Top:" + pictureBox1.Top.ToString() + "n Bottom" + pictureBox1.Bottom.ToString();
}
if (pictureBox1.Left == 400)
{
pictureBox1.Top += 10;
label1.Text = "Left:" + pictureBox1.Left.ToString() + "n Right:" + pictureBox1.Right.ToString() + "n Top:" + pictureBox1.Top.ToString() + "n Bottom" + pictureBox1.Bottom.ToString();
}
if (pictureBox1.Top == 200)
{
pictureBox1.Left -= 10;
label1.Text = "Left:" + pictureBox1.Left.ToString() + "n Right:" + pictureBox1.Right.ToString() + "n Top:" + pictureBox1.Top.ToString() + "n Bottom" + pictureBox1.Bottom.ToString();
}
if (pictureBox1.Left == 0)
{
pictureBox1.Top -= 10;
label1.Text = "Left:" + pictureBox1.Left.ToString() + "n Right:" + pictureBox1.Right.ToString() + "n Top:" + pictureBox1.Top.ToString() + "n Bottom" + pictureBox1.Bottom.ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
}
}