none
how do i drag an item RRS feed

  • Question

  • hello i am making a dock and i want to be able to drag mt dock around my screen but only want to be able to do it from a button at the button how do i do this

     

     

    • Moved by Harry Zhu Friday, July 9, 2010 9:16 AM (From:Visual C# General)
    Friday, July 2, 2010 3:56 PM

All replies

  • modify it and try it

    put these in the Form's constructor

     

    DragPanel.MouseDown += new MouseEventHandler(DragPanel_MouseDown);

     

    DragPanel.MouseMove += new MouseEventHandler(BarcodeControl_MouseMove);

     

    DragPanel.MouseUp += new MouseEventHandler(BarcodeControl_MouseUp);

    AND after that add the below code to the form's class

    bool hold=false;

    void DragPanel_MouseDown(object sender, MouseEventArgs e)
            {
                hold = true;
            }

            void BarcodeControl_MouseMove(object sender, MouseEventArgs e)
            {
                if (hold)
                {
                    this.Location.Y= DragPanel.Top + e.Y;
                    this.Location.X= DragPanel.Left + e.X;
                }
            }

            void BarcodeControl_MouseUp(object sender, MouseEventArgs e)
            {
                hold = false;
            }

    hope this helps

     


    Mohammed Kamran Azam
    • Proposed as answer by Aaron Alistair Thursday, February 10, 2011 1:40 PM
    Friday, July 2, 2010 9:32 PM
  • 
    

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    
    namespace Dock
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
    
          Process dreamweaver = new Process();
    
    
          // filename is the program file you want to run
          dreamweaver.StartInfo.FileName = "C:/Program Files/Macromedia/Dreamweaver 8/Dreamweaver.exe";
    
    
          dreamweaver.Start();
        }
    
        private void button2_Click(object sender, EventArgs e)
        {
    
          Process contribute = new Process();
    
    
          // filename is the program file you want to run
          contribute.StartInfo.FileName = "C:/Program Files/Macromedia/Contribute 3/Contribute.exe";
    
    
          contribute.Start();
        }
    
        private void button3_Click(object sender, EventArgs e)
        {
          Process fireworks = new Process();
    
    
          // filename is the program file you want to run
          fireworks.StartInfo.FileName = "C:/Program Files/Macromedia/Fireworks 8/Fireworks.exe";
    
    
          fireworks.Start();
        }
    
        private void button5_Click(object sender, EventArgs e)
        {
          Process frontpage = new Process();
    
    
          // filename is the program file you want to run
          frontpage.StartInfo.FileName = "C:/Program Files/Microsoft Office/OFFICE11/FRONTPG.exe";
    
    
          frontpage.Start();
        }
    
        private void button4_Click(object sender, EventArgs e)
        {
    
          Process flash = new Process();
    
    
          // filename is the program file you want to run
          flash.StartInfo.FileName = "C:/Program Files/Macromedia/Flash 8/Flash.exe";
    
    
          flash.Start();
        }
    
        private void button6_Click(object sender, EventArgs e)
        {
          Process lightbox = new Process();
    
    
          // filename is the program file you want to run
          lightbox.StartInfo.FileName = "C:/Program Files/VisualLightBox/VisualLightBox.exe";
    
    
          lightbox.Start();
        }
    
        private void button7_Click(object sender, EventArgs e)
        {
          Process nero = new Process();
    
    
          // filename is the program file you want to run
          nero.StartInfo.FileName = "C:/Program Files/Nero/Nero 10/Nero StartSmart/NeroStartSmart.exe";
    
    
          nero.Start();
        }
    
        private void button8_Click(object sender, EventArgs e)
        {
          Process word = new Process();
    
          ;
          // filename is the program file you want to run
          word.StartInfo.FileName = "C:/Program Files/Microsoft Office/Office12/WINWORD.exe";
    
    
          word.Start();
        }
    
        private void button3_Click_1(object sender, EventArgs e)
        {
          Process autodesk = new Process();
    
    
          // filename is the program file you want to run
          autodesk.StartInfo.FileName = "C:/Program Files/Autodesk/3ds Max 2009/3dsmax.exe";
    
    
          autodesk.Start();
        }
    
        private void button9_Click(object sender, EventArgs e)
        {
          Process powerpoint = new Process();
    
    
          // filename is the program file you want to run
          powerpoint.StartInfo.FileName = "C:/Program Files/Microsoft Office/Office12/POWERPNT.exe";
    
    
          powerpoint.Start();
        }
    
        private void label15_Click(object sender, EventArgs e)
        {
    
        }
    
        private void button10_Click(object sender, EventArgs e)
        {
          Process unity = new Process();
    
    
          // filename is the program file you want to run
          unity.StartInfo.FileName = "C:/Program Files/Unity/Editor/Unity.exe";
    
    
          unity.Start();
        }
    
        private void button11_DoubleClick(object sender, EventArgs e)
        {
          Process visual = new Process();
    
    
          // filename is the program file you want to run
          visual.StartInfo.FileName = "C:/ProgramFiles/Microsoft/VisualStudio10.0/Common7/IDE/devenv.exe";
    
    
          visual.Start();
        }
    
        private void button12_Click(object sender, EventArgs e)
        {
          Process itunes = new Process();
    
    
          // filename is the program file you want to run
          itunes.StartInfo.FileName = "C:/Program Files/iTunes/iTunes.exe";
    
    
          itunes.Start();
        }
    
        private void button13_Click(object sender, EventArgs e)
        {
          Process winamp = new Process();
    
    
          // filename is the program file you want to run
          winamp.StartInfo.FileName = "C:/Program Files/Winamp/winamp.exe";
    
    
          winamp.Start();
        }
    
        private void button14_Click(object sender, EventArgs e)
        {
          Process youcam = new Process();
    
    
          // filename is the program file you want to run
          youcam.StartInfo.FileName = "C:/Program Files/CyberLink/YouCam/YouCam.exe";
    
    
          youcam.Start();
        }
    
        private void button15_Click(object sender, EventArgs e)
        {
          Process msn = new Process();
    
    
          // filename is the program file you want to run
          msn.StartInfo.FileName = "C:/Program Files/Windows Live/Messenger/msnmsgr.exe";
    
    
          msn.Start();
        }
    
        private void button15_Click_1(object sender, EventArgs e)
        {
          Process msn = new Process();
    
    
          // filename is the program file you want to run
          msn.StartInfo.FileName = "C:/Program Files/Windows Live/Messenger/msnmsgr.exe";
    
    
          msn.Start();
        }
    
        private void label1_Click(object sender, EventArgs e)
        {
    
        }
    
        private void label9_Click(object sender, EventArgs e)
        {
    
        }
    
        private void button6_Click_1(object sender, EventArgs e)
        {
          Process irfanview = new Process();
    
    
          // filename is the program file you want to run
          irfanview.StartInfo.FileName = "C:/Program Files/IrfanView/i_view32.exe";
    
    
          irfanview.Start();
        }
    
        private void pictureBox1_Click(object sender, EventArgs e)
        {
          Process frontpage = new Process();
    
    
          // filename is the program file you want to run
          frontpage.StartInfo.FileName = "C:/Program Files/Microsoft Office/OFFICE11/FRONTPG.exe";
    
    
          frontpage.Start();
        }
    
        private void button10_Click_1(object sender, EventArgs e)
        {
          Process corel = new Process();
    
    
          // filename is the program file you want to run
          corel.StartInfo.FileName = "C:/Program Files/Corel/Corel Paint Shop Pro Photo X2/Corel Paint Shop Pro Photo.exe";
    
    
          corel.Start();
        }
    
        private void button14_Click_1(object sender, EventArgs e)
        {
          
     Process email = new Process();
    
    
          // filename is the program file you want to run
          email.StartInfo.FileName = "C:/Program Files/Mozilla Thunderbird/thunderbird.exe";
    
    
          email.Start();
        }
    
        private void button14_Click_2(object sender, EventArgs e)
        {
          Process mail = new Process();
    
    
          // filename is the program file you want to run
          mail.StartInfo.FileName = "C:/Program Files/Mozilla Thunderbird/thunderbird.exe";
    
    
          mail.Start();
    
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
    
        }
    
        private void button16_Click(object sender, EventArgs e)
        {
          DragPanel.MouseDown += new MouseEventHandler(DragPanel_MouseDown);
    
     
    
    DragPanel.MouseMove += new MouseEventHandler(BarcodeControl_MouseMove);
    
     
    
    DragPanel.MouseUp += new MouseEventHandler(BarcodeControl_MouseUp);
    
    AND after that add the below code to the form's class
    
    bool hold=false;
    
    void DragPanel_MouseDown(object sender, MouseEventArgs e)
        {
          hold = true;
        }
    
        void BarcodeControl_MouseMove(object sender, MouseEventArgs e)
        {
          if (hold)
          {
            this.Location.Y= DragPanel.Top + e.Y;
            this.Location.X= DragPanel.Left + e.X;
          }
        }
    
        void BarcodeControl_MouseUp(object sender, MouseEventArgs e)
        {
          hold = false;
        }
        }
      }
    

    is that the correct code if not can you give me the right code as that code isnt working there are 9 errors it says?

    Saturday, July 3, 2010 2:57 PM
  • Hi,

    The question relating to combobox control is a little off-topic here.

    For questions related to WinForms and any WinForm control, please try to use the Windows Forms General forum:

    http://social.msdn.microsoft.com/Forums/en/winforms/threads

    Thanks,

    Harry


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, July 8, 2010 11:45 AM