這更是一個爲什麼不工作的問題。我顯然必須錯過一些東西,因爲我不能爲我的生活找出爲什麼計算寬度和高度值爲我提供了與我開始時相同的靜態值。但是,當我替代硬編碼值時,它工作得很好。所以顯然我的計算是不好的,但我似乎無法弄清楚爲什麼。誰能幫忙?如果您需要更多信息,請詢問。爲什麼我的計算工作不正常?
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();
}
在你的評論代碼中,你使用'e.X'和'e.Y',但是在你未註釋的代碼中,你使用'e.Location.X'和'e.Location.Y' – cjk
你試過調試器嗎?設置斷點並查看e.Location.X中的內容等。或者是否有編譯錯誤? – Peter
是的,我不認爲這是問題所在。 e.Location.X/Y和e.X/Y是相同的值,只是獲得它的另一種方式。 – Timelord