public void button_MouseMove(object sender, MouseEventArgs e) { StayInsideButton button = (StayInsideButton)sender; if (button != null) { if (e.Button == MouseButtons.Left) { BarObject barObject = (BarObject)button.Tag; if (barObject != null) { Point mouseMovePoint = pnlRoom.PointToClient(button.PointToScreen(e.Location)); button.CheckSetLocation(barObject.TablePositionX + (mouseMovePoint.X - mouseDownPoint.X), barObject.TablePositionY + (mouseMovePoint.Y - mouseDownPoint.Y)); } } } }
public void button_MouseUp(object sender, MouseEventArgs e) { Button button = (Button)sender; BarObject barObject = (BarObject)button.Tag; // The following code down to, but not including the uncommented if(barObject != null) // was the original code before it was modified to implement collision protection. //if (barObject != null && barObject is BarTable) { // // Get positioning. // BarTable barTable = (BarTable)button.Tag; // barTable.TablePositionX = button.Left; // barTable.TablePositionY = button.Top; //} //else if (barObject != null && barObject is Table) { // // Get positioning. // Table table = (Table)button.Tag; // int tableNumber = table.TableNumber; // table = tables[tableNumber - 1]; // //int tableIndex = (Int32)button.Tag - 1; // //Table table = tables[tableIndex]; // table.TablePositionX = button.Left; // table.TablePositionY = button.Top; //} //else if (barObject != null && barObject is BarSeat) { // // Get positioning. // BarSeat barSeat = (BarSeat)button.Tag; // int barSeatNumber = barSeat.TableNumber; // barSeat = barSeats[barSeatNumber - 1]; //} if (barObject != null) { // Get positioning. if (IsCollision(button)) { // If the table, barseat, or bar has been dropped on top of another // table, barseat, or bar, set its position back to the position it was being dragged from button.Left = barObject.TablePositionX; button.Top = barObject.TablePositionY; } else { // If the table, barseat, or bar has been dropped on an empty area of the panel, // set the record of its position that will be saved to the database to the position where it was dropped. barObject.TablePositionX = button.Left; barObject.TablePositionY = button.Top; } } }