How to avoid dragging a form

May 22 2006 1:01 PM

Hi everybody!

 

I'm new on C# programming. I have a main form in my Windows applications that contains other form as a Explorer of folders. I don't want to allow to drag the Explorer form (FrmExplorer). FrmExplorer has a TreeView. I have been looking for information about it and have written the following code:

 

public partial class FrmExplorer : Form

{

 

        public FrmExplorer(string fileName)

        {

            InitializeComponent();

            //To cancel dragging the form

            this.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.FrmExplorer_CancelDrag);

            this.DragEnter += new System.Windows.Forms.DragEventHandler(this.FrmExplorer_EnterDrag);

            this.DragOver += new System.Windows.Forms.DragEventHandler(FrmExplorer_DragOver);

            this.AllowDrop = false;

        }

 

      private void FrmExplorer_CancelDrag(object sender, QueryContinueDragEventArgs e)

        {

            e.Action = DragAction.Cancel;

        }

 

        private void FrmExplorer_EnterDrag(object sender, System.Windows.Forms.DragEventArgs e)

        {

            e.Effect = DragDropEffects.None;

        }

 

        private void FrmExplorer_DragOver(object sender, System.Windows.Forms.DragEventArgs e)

        {

            // Determine whether string data exists in the drop data. If not, then

            // the drop effect reflects that the drop cannot occur.

            if (!e.Data.GetDataPresent(typeof(System.String)))

            {

                e.Effect = DragDropEffects.None;               

                return;

            }

        }       

}

 

I have set the method FrmExplorer_CancelDrag in FrmExplorer Properties in the event QueryContinueDrag. But I still cannot reach the method FrmExplorer_CancelDrag when dragging the form to cancel that action.

 

Does anybody can help me to know what I'm doing wrong or what is it missing?

 

Thanks a lot in advance,

 

Elvia

 

PS: Windows application in Microsoft Visual C# 2005