Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class DefaultForm : Form
- {
- private int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
- private int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
- private bool LeftMove, UpMove;
- public DefaultForm()
- {
- InitializeComponent();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- int speed = 10; // скорость движения окна
- if (!LeftMove)
- {
- Location = new Point(Location.X + speed, Location.Y);
- }
- if (LeftMove)
- {
- Location = new Point(Location.X - speed, Location.Y);
- }
- if (!UpMove)
- {
- Location = new Point(Location.X, Location.Y + speed);
- }
- if (UpMove)
- {
- Location = new Point(Location.X, Location.Y - speed);
- }
- if (Location.X <= 0) // если по X уходит за рамки экрана слева
- LeftMove = false;
- if (Location.X >= screenWidth - Size.Width) // если по X уходит за рамки экрана справа
- LeftMove = true;
- if (Location.Y <= 0) // если по Y уходит за рамки экрана сверху
- UpMove = false;
- if (Location.Y >= screenHeight - Size.Height) // если по Y уходит за рамки экрана снизу
- UpMove = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement