Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace R804MoverFigura
- {
- public partial class Principal : Form
- {
- public Principal()
- {
- InitializeComponent();
- }
- private bool arrastrandoElipse1 = false;
- private bool arrastrandoElipse2 = false;
- private ElipseControl elipse1;
- private ElipseControl elipse2;
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- elipse1 = new ElipseControl();
- elipse1.Width = 100;
- elipse1.Height = 100;
- elipse1.Top = 30;
- elipse1.Left = 30;
- elipse1.BackColor = Color.Red;
- this.Controls.Add(elipse1);
- elipse2 = new ElipseControl();
- elipse2.Width = 100;
- elipse2.Height = 100;
- elipse2.Top = 130;
- elipse2.Left = 130;
- elipse2.BackColor = Color.Azure;
- this.Controls.Add(elipse2);
- elipse1.MouseDown += Elipse_MouseDown;
- elipse1.MouseUp += Elipse_MouseUp;
- elipse1.MouseMove += Elipse_MouseMove;
- elipse2.MouseDown += Elipse_MouseDown;
- elipse2.MouseUp += Elipse_MouseUp;
- elipse2.MouseMove += Elipse_MouseMove;
- }
- private void Elipse_MouseDown(object sender, MouseEventArgs eventArgs)
- {
- Control ctlControl = (Control) sender;
- if(eventArgs.Button == MouseButtons.Left)
- {
- ctlControl.Tag = new Point(eventArgs.X, eventArgs.Y);
- if(ctlControl == elipse1)
- {
- arrastrandoElipse1 = true;
- }
- else
- {
- arrastrandoElipse2 = true;
- }
- }
- }
- private void Elipse_MouseUp(object sender, MouseEventArgs eventArgs)
- {
- arrastrandoElipse1 = false;
- arrastrandoElipse2 = false;
- }
- private void Elipse_MouseMove(object sender, MouseEventArgs eventArgs)
- {
- Control ctlControl = (Control) sender;
- if((arrastrandoElipse1 && ctlControl == elipse1) || (arrastrandoElipse2 && ctlControl == elipse2))
- {
- Point punto = (Point) ctlControl.Tag;
- ctlControl.Left = eventArgs.X + ctlControl.Left - punto.X;
- ctlControl.Top = eventArgs.Y + ctlControl.Top - punto.Y;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement