small clas example: https://github.com/avk013/oop_image/blob/master/move_pic/move_pic/Form1.cs
==========
namespace WindowsFormsApplication96 { public partial class Form1 : Form { static int shag=1; int xto = shag; int x=shag,y=shag; public enum Direction {Right,Left,Up,Down,None}; public Form1() {InitializeComponent();} public void RotatePicture(PictureBox pictureBox) { Image flipImage = pictureBox.Image; flipImage.RotateFlip(RotateFlipType.RotateNoneFlipX); pictureBox.Image = flipImage;} public void gopict(PictureBox pictureBox, Direction direction=Direction.None, int shag1=0) { if (pictureBox.Left <= 0) { direction = Direction.Right; } if (pictureBox.Left >= this.Size.Width- pictureBox.Width) { direction = Direction.Left; } if (pictureBox.Top <= 0) { direction = Direction.Down; } if (pictureBox.Top >= this.Size.Height - pictureBox.Height) { direction = Direction.Up; } switch (direction) { case Direction.Right:if(x<0) RotatePicture(pb1); x = shag1; break; case Direction.Left: if (x > 0) RotatePicture(pb1); x = -shag1; break; case Direction.Up: y =-shag1; break; case Direction.Down: y = shag1; break; case Direction.None: break;} pictureBox.Left += x; pictureBox.Top += y;} private void timer2_Tick(object sender, EventArgs e) {gopict(pb1, Direction.None,1);} private void button1_Click(object sender, EventArgs e) {gopict(pb1, Direction.Up, 5);} private void button2_Click(object sender, EventArgs e) {gopict(pb1, Direction.Left,5);} private void button4_Click(object sender, EventArgs e) {gopict(pb1, Direction.Down, 5);} private void button3_Click(object sender, EventArgs e) {gopict(pb1, Direction.Right, 5);} }}
Комментариев нет:
Отправить комментарий