private void FlowLayoutPanel_DragDrop(object sender, DragEventArgs e)
        {
            MovableButton mb = e.Data.GetData(typeof(MovableButton)) as MovableButton;

            if (mb != null)
            {
                mb = new MovableButton()
                {
                    Text = mb.Text, Tag = mb.Tag
                };
                mb.MouseDown += new MouseEventHandler(InsideButton_MouseDown);
                Point   p            = this.m_FlowLayoutPanel.PointToClient(new Point(e.X, e.Y));
                Control buttonBefore = this.m_FlowLayoutPanel.GetChildAtPoint(p);
                if (buttonBefore == null)
                {
                    m_FlowLayoutPanel.Controls.Add(mb);
                }
                else
                {
                    int index = m_FlowLayoutPanel.Controls.IndexOf(buttonBefore);
                    Console.WriteLine(index);
                    m_FlowLayoutPanel.Controls.Add(mb);
                    m_FlowLayoutPanel.Controls.SetChildIndex(mb, index);
                    m_FlowLayoutPanel.Controls.SetChildIndex(buttonBefore, index + 1);
                }
            }
        }
 private void ButtonTag_Click(object sender, EventArgs e)
 {
     MovableButton mb = sender as MovableButton;
     if (mb != null) {
         mb = new MovableButton() { Text = mb.Text, Tag = mb.Tag };
         mb.MouseDown += new MouseEventHandler(InsideButton_MouseDown);
         m_FlowLayoutPanel.Controls.Add(mb);
     }
 }
 private void FlowLayoutPanel_ControlChange(object sender, ControlEventArgs e)
 {
     textBoxResult.Text = "";
     foreach (Control item in m_FlowLayoutPanel.Controls)
     {
         MovableButton mb = item as MovableButton;
         if (mb != null && mb.Tag != null)
         {
             textBoxResult.Text += mb.Tag.ToString();
         }
     }
 }
        private void ButtonTag_Click(object sender, EventArgs e)
        {
            MovableButton mb = sender as MovableButton;

            if (mb != null)
            {
                mb = new MovableButton()
                {
                    Text = mb.Text, Tag = mb.Tag
                };
                mb.MouseDown += new MouseEventHandler(InsideButton_MouseDown);
                m_FlowLayoutPanel.Controls.Add(mb);
            }
        }
        private bool ButtonExistsInPanel(MovableButton button)
        {
            if (button == null) return false;

            foreach (Control item in m_FlowLayoutPanel.Controls)
            {
                MovableButton mb = item as MovableButton;
                if (mb == null) continue;

                if (button.Text.Equals(mb.Text)) {
                    return true;
                }
            }
            return false;
        }
        private bool ButtonExistsInPanel(MovableButton button)
        {
            if (button == null)
            {
                return(false);
            }

            foreach (Control item in m_FlowLayoutPanel.Controls)
            {
                MovableButton mb = item as MovableButton;
                if (mb == null)
                {
                    continue;
                }

                if (button.Text.Equals(mb.Text))
                {
                    return(true);
                }
            }
            return(false);
        }
 void InsideButton_MouseDown(object sender, MouseEventArgs e)
 {
     MovingButton = sender as MovableButton;
 }
 private void FlowLayoutPanel_MouseDown(object sender, MouseEventArgs e)
 {
     MovingButton = null;
 }
 private void FlowLayoutPanel_DragDrop(object sender, DragEventArgs e)
 {
     MovableButton mb = e.Data.GetData(typeof(MovableButton)) as MovableButton;
     if (mb != null) {
         mb = new MovableButton() { Text = mb.Text, Tag = mb.Tag };
         mb.MouseDown += new MouseEventHandler(InsideButton_MouseDown);
         Point p = this.m_FlowLayoutPanel.PointToClient(new Point(e.X, e.Y));
         Control buttonBefore = this.m_FlowLayoutPanel.GetChildAtPoint( p );
         if (buttonBefore == null)
         {
             m_FlowLayoutPanel.Controls.Add(mb);
         }
         else
         {
             int index = m_FlowLayoutPanel.Controls.IndexOf(buttonBefore);
             Console.WriteLine(index);
             m_FlowLayoutPanel.Controls.Add(mb);
             m_FlowLayoutPanel.Controls.SetChildIndex(mb, index );
             m_FlowLayoutPanel.Controls.SetChildIndex(buttonBefore, index + 1);
         }
     }
 }
 private void FlowLayoutPanel_MouseDown(object sender, MouseEventArgs e)
 {
     MovingButton = null;
 }
 void InsideButton_MouseDown(object sender, MouseEventArgs e)
 {
     MovingButton = sender as MovableButton;
 }