All pastes #269860 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-12-06 21:35 UTC
rendered paste body
using System.Windows.Forms;
using System.Drawing;
using System;

public class foo : Form {
        Point initial_control_location;
        Point initial_mouse_position;

        void b_mousemove (object sender, MouseEventArgs e)
        {
                Button b = (Button)sender;
                if (!b.Capture) return;

                b.Location = new Point (initial_control_location.X + MousePosition.X - initial_mouse_position.X,
                                        initial_control_location.Y + MousePosition.Y - initial_mouse_position.Y);
        }

        void b_mousedown (object sender, MouseEventArgs e)
        {
                initial_control_location = ((Button)sender).Location;
                initial_mouse_position = MousePosition;
        }

        public foo () {
                Button b = new Button ();
                b.Location = new Point (15, 15);
                b.Size = new Size (150, 100);
                Controls.Add (b);

                Label l = new Label ();
                l.Text = "hi there";
                l.Location = new Point (20, 20);
                l.Size = new Size (100, 20);
                b.Controls.Add (l);

                b.MouseDown += new MouseEventHandler (b_mousedown);
                b.MouseMove += new MouseEventHandler (b_mousemove);

                Label l2 = new Label ();
                l2.Text = "mouse over me after clicking on the button";
                l2.Location = new Point (20, 150);
                l2.Size = new Size (100, 50);
                Controls.Add (l2);
        }

        public static void Main (string[] args) {
                foo f = new foo ();
                Application.Run (f);
        }
}