private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { topItem = null; i = 0; // create arrayList of shaapes from myModel ArrayList theItemList = myModel.ItemList; // create array of Items from array list AnyItem[] theItems = (AnyItem[])theItemList.ToArray(typeof(AnyItem)); // loop through array checking if mouse is over Item foreach (AnyItem s in theItems) { i++; // check if mouse is over Item if (listBox1.GetItemText(listBox1.SelectedItem).Contains(s.name.ToString()) && listBox1.SelectedIndex + 1 == i) { // if so make Item topItem topItem = s; } } }
private void btnEdit_Click(object sender, EventArgs e) { if (topItem != null) { // message to user to enter new size and colour MessageBox.Show("You May Update Item type Only" + "\r\n", "Select a new type and click the Update button", MessageBoxButtons.OK, MessageBoxIcon.Information); // make editItem the current topItem editItem = topItem; // update values in update panel to selected Item lblSelectedItem.Text = topItem.name.ToString(); cmbUpdateType.Items.Clear(); cmbUpdateType.Items.AddRange(TypeOfItem[topItem.name.ToString()]); cmbUpdateType.SelectedIndex = 0; // show update panel pnlUpdate.Show(); } myModel.UpdateViews(); }
public void SendToBack(AnyItem aItem) { // first shape drawn is at the back // temp arrayList to resort shapes so selected shape is drawn first ArrayList sortList = new ArrayList(); // find index of shape to be drawn first int max = itemList.IndexOf(aItem); // first shape i.e. shape to send to back sortList.Add(aItem); // copy to sortList in correct sequence for (int i = 0; i < max; i++) { sortList.Add(itemList[i]); } // copy sortList back to shapeList for (int i = 0; i < sortList.Count; i++) { itemList[i] = sortList[i]; } UpdateViews(); }
public void BringToFront(AnyItem aItem) { // last shape drawn is at the front // temp arrayList to resort shapes so selected shape is drawn last ArrayList sortList = new ArrayList(itemList); // find index of shape to be drawn last int max = itemList.IndexOf(aItem); // find length of shapeList array int length = itemList.Count; // copy shapeList to sortList excluding selected shape for (int i = max + 1; i < length; i++) { sortList[i - 1] = itemList[i]; } // last shape i.e. shape to bring to front sortList[length - 1] = itemList[max]; // copy sortList back to shapeList for (int i = 0; i < sortList.Count; i++) { itemList[i] = sortList[i]; } UpdateViews(); }
private void panel1_MouseMove(object sender, 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 topItem = null; bool needsDisplay = false; // create arrayList of shaapes from myModel ArrayList theItemList = myModel.ItemList; // create array of Items from array list AnyItem[] theItems = (AnyItem[])theItemList.ToArray(typeof(AnyItem)); // graphics object to draw Items when required Graphics g = this.panel1.CreateGraphics(); // loop through array checking if mouse is over Item foreach (AnyItem s in theItems) { // check if mouse is over Item if (s.HitTest(new Point(e.X, e.Y))) { // if so make Item topItem topItem = s; } if (s.Highlight == true) { // Item to be redrawn needsDisplay = true; // redraw Item s.Display(g); s.Highlight = false; } // 30 Oct moved this piece up to before highlight test // if (s.HitTest(new Point(e.X, e.Y)))// check if mouse is over Item // { // topItem = s; // make Item topItem // } } if (topItem != null) // if there is a topItem { needsDisplay = true; // need to redisplay topItem.Display(g); // redisplay topItem topItem.Highlight = true; } if (needsDisplay) { // redisplay model myModel.UpdateViews(); } } else // mouse is down { // reset position of selected Item by value of mouse move topItem.x_pos = topItem.x_pos + xMove; topItem.y_pos = topItem.y_pos + yMove; myModel.UpdateViews(); } }
public void UpdateItem(AnyItem aItem) { UpdateViews(); }
public void DeleteItem(AnyItem aItem) { itemList.Remove(aItem); UpdateViews(); }
public void AddItem(AnyItem aItem) { itemList.Add(aItem); UpdateViews(); }