Esempio n. 1
0
        private void usercontrol_MouseMove(object sender, MouseEventArgs e)
        {
            // Bringe das Control nach vorne wenn die Maus drüber fährt
            UserControlSchueler ctrl = sender as UserControlSchueler;

            ctrl.BringToFront();

            if (aktivesUsercontrol == null || aktivesUsercontrol != sender)
            {
                return;
            }

            Point location = aktivesUsercontrol.Location;

            location.Offset(e.Location.X - vorherigeUserControlPos.X, e.Location.Y - vorherigeUserControlPos.Y);

            // Bewegen des Usercontrols auf das Panel begrenzen, sonst lässt sich das aus der Anwendung schieben
            if (location.X < 0)
            {
                location.X = 0;
            }

            if (location.Y < 0)
            {
                location.Y = 0;
            }

            if (location.X > (panelSchueler.Size.Width - aktivesUsercontrol.Size.Width))
            {
                location.X = panelSchueler.Size.Width - aktivesUsercontrol.Size.Width;
            }

            if (location.Y > (panelSchueler.Size.Height - aktivesUsercontrol.Size.Height))
            {
                location.Y = panelSchueler.Size.Height - aktivesUsercontrol.Size.Height;
            }

            aktivesUsercontrol.Location = location;
        }
Esempio n. 2
0
 private void usercontrol_MouseUp(object sender, MouseEventArgs e)
 {
     aktivesUsercontrol = null;
     Cursor             = Cursors.Default;
 }
Esempio n. 3
0
        // https://stackoverflow.com/questions/3868941/how-to-allow-user-to-drag-a-dynamically-created-control-at-the-location-of-his-c

        private void usercontrol_MouseDown(object sender, MouseEventArgs e)
        {
            aktivesUsercontrol      = sender as UserControlSchueler;
            vorherigeUserControlPos = e.Location;
            Cursor = Cursors.Hand;
        }