private void mnuModify_Click(object sender, EventArgs e) { // show update panel pnlUpdate.Show(); if (itemSelected != null) { // make editItem the current itemSelected editItem = itemSelected; // update the colour of the selected item using the colour palette lblUpdateColour.BackColor = itemSelected.itemColor; } model.UpdateViews(); }
/// <summary> method: pnlView_MouseMove /// when mouse moves it checks if mouse is down and/or over shape /// If mouse is down and over shape, it draws border around shape and /// sets new position for shape based on how far mouse has moved. /// If mouse is up and over shape, draw border around shape. /// If mouse if down and not over shape, do nothing. /// </summary> private void pnlView_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { // set last position to current position lastPosition = currentPosition; // set current position to mouse position currentPosition = new Point(e.X, e.Y); // calculate how far mouse has moved int xMove = currentPosition.X - lastPosition.X; int yMove = currentPosition.Y - lastPosition.Y; if (!dragging) // mouse not down { // reset variables itemSelected = null; bool needsDisplay = false; // create arrayList of items from model ArrayList theShoppingList = model.ShoppingList; // create array of items from array list AnyItem[] theItems = (AnyItem[])theShoppingList.ToArray(typeof(AnyItem)); // graphics object to draw items when required Graphics g = this.pnlView.CreateGraphics(); //loop through array checking if mouse is over item foreach (AnyItem s in theItems) { // check if mouse is over shape if (s.HitTest(new Point(e.X, e.Y))) { // if so make item topItem itemSelected = s; } if (s.Highlight == true) { // item to be redrawn needsDisplay = true; // redraw item s.Display(g); s.Highlight = false; } } if (itemSelected != null) // if there is a topItem { needsDisplay = true; // need to redisplay itemSelected.Display(g); // redisplay topItem itemSelected.Highlight = true; } if (needsDisplay) { // redisplay model model.UpdateViews(); } } else // mouse is down { // reset position of selected item by value of mouse move itemSelected.x_pos = itemSelected.x_pos + xMove; itemSelected.y_pos = itemSelected.y_pos + yMove; model.UpdateViews(); } }
/// <summary>method: UpdateItem /// update views /// </summary> /// <param name="anItem"></param> public void UpdateItem(AnyItem anItem) { UpdateViews(); }
/// <summary>method: DeleteItem /// delete item and update views /// </summary> /// <param name="anItem"></param> public void DeleteItem(AnyItem anItem) { shoppingList.Remove(anItem); UpdateViews(); }
/// <summary>method: AddShoppingList /// add shopping list to the model and update views /// </summary> /// <param name="anItem"></param> public void AddItem(AnyItem anItem) { shoppingList.Add(anItem); UpdateViews(); }