Geekpedia Forums Logo

users moving objects, Getting it right

by Nick Baker on Monday, March 1st - 7:12 AM



Hi all,

i have recently been developing a small alpication in C# were i would like the user to be able to drag and drop the object,

i have basicly succeded but the object keeps jumping when the user clicks to start dragging i think this is becasue of the curser positions giving me the position of the curser on the whole screen and not the form, i have only just fixed it by conteracting the amount it was skipping by...though would really like to know if i can find the curser possition on the form or the possition for the users part of the form on the screen... here is the relative bit of code

 

private void ~~~~{Object}~~~~~~_MouseMove(object sender, MouseEventArgs e)if (Session.DesignMode == true && Session.MoveOn == true)          this.Left = Cursor.Position.X - this.ParentForm.ClientRectangle.Left - Session.XAxisOnControl -12;

{

{          

          this.Top = Cursor.Position.Y - this.ParentForm.ClientRectangle.Top - Session.YAxisOnControl -35;

}

 

 

private void ~~~~{Object}~~~~~~_MouseDown(object sender, MouseEventArgs e)if (Session.DesignMode == true)          Session.MoveOn = true;

{

{

          Session.XAxisOnControl = e.X;

          Session.YAxisOnControl = e.Y;private void ~~~~{Object}~~~~~~_MouseUp(object sender, MouseEventArgs e)if (Session.DesignMode == true)

}

}

 

 

{

          Session.MoveOn = false;

}

 

.....cheers

Nick

for some reason the code spacing came out wrong..........this should be easier to read

 

 

private void ~~~~{Object}~~~~~~_MouseMove(object sender, MouseEventArgs e)

{

      if (Session.DesignMode == true && Session.MoveOn == true)         

{

          this.Left = Cursor.Position.X - this.ParentForm.ClientRectangle.Left - Session.XAxisOnControl -12;{

          this.Top = Cursor.Position.Y - this.ParentForm.ClientRectangle.Top - Session.YAxisOnControl -35;

}

 }

 

private void ~~~~{Object}~~~~~~_MouseDown(object sender, MouseEventArgs e)

{

    if (Session.DesignMode == true)      

{

          Session.MoveOn = true;

          Session.XAxisOnControl = e.X;

              Session.YAxisOnControl = e.Y;

}

}

private void ~~~~{Object}~~~~~~_MouseUp(object sender, MouseEventArgs e)

{

    if (Session.DesignMode == true)

{

          Session.MoveOn = false;

}

 }