2

これは、これがうまくいかない理由の多くです。幅と高さの値を計算すると、最初に使用したのと同じ静的な値が得られる理由を一生理解できないため、明らかに何かが欠けているに違いありません。しかし、ハードコードされた値に置き換えると、問題なく機能します。だから明らかに私の計算は悪いですが、私は理由を理解できないようです。誰か助けてもらえますか?さらに詳しい情報が必要な場合はお問い合わせください。

 if(objectList[selectedIndex].Selected == true)
 {
      //The width would be mouselocationx - objectlocationx
      //The height would be mouselocationy - objectlocationy
      //Off set the position so it doesnt snap to mouse location
      //WHY THE *%$!! DOESNT THIS WORK!!?!?!?!?!?!?
      //int width = e.X - objectList[selectedIndex].X;
      //int height = e.Y - objectList[selectedIndex].Y;
      //Why is this so hard??
      //Point location = objectList[selectedIndex].Location;
      //location.X = e.X - (e.X - objectList[selectedIndex].Location.X);
      //location.Y = e.Y - (e.Y - objectList[selectedIndex].Location.Y);
      objectList[selectedIndex].X = e.Location.X - 12;
      objectList[selectedIndex].Y = e.Location.Y - 12;
      objectLocationXLabel.Text = "OBJX: " + objectList[selectedIndex].X.ToString();
      objectLocationYLabel.Text = "OBJY: " + objectList[selectedIndex].Y.ToString();
      panel1.Invalidate();
   }
4

1 に答える 1

1

何をしたいのか全くわかりません。ただし、コメントされたコードには少なくとも2つの問題があります。

location.X = e.X - (e.X - objectList[selectedIndex].Location.X);

と同等です

location.X = objectList[selectedIndex].Location.X;

Point値型です。したがって、これを行うと:

Point location = objectList[selectedIndex].Location;
location.X = ...;

location変更されますが、変更されませんobjectList[selectedIndex].Location

MouseDownコメントに応じて編集する:イベントのオフセットを決定し、それをメンバーに保存して、で使用する必要があると思いますMouseMove

于 2013-01-23T08:22:13.137 に答える