private void ptbContain_MouseDown(object sender, MouseEventArgs e) { if (e.X >= ptbContain.Width - 300) { int x = ptbContain.Width + 300; this.ptbContain.Size = new System.Drawing.Size(x, 2000); } if (e.Button == MouseButtons.Left) { if (CheckDraw == true) { currentPos = startPos = e.Location; drawing = true; } } else { for (int i = 0; i < rectangles.Count; i++) { if (e.X >= rectangles[i].Left && e.X <= rectangles[i].Right && e.Y <= rectangles[i].Bottom && e.Y >= rectangles[i].Top) { rectangles.RemoveAt(i); ptbContain.Invalidate(); } } } if (m_image != null && e.Button == MouseButtons.Left) { PictureBoxObject ptb = new PictureBoxObject(m_image, e.X - m_image.Width / 2, e.Y - m_image.Height / 2); ptbContain.Controls.Add(ptb); ObjectSelect = ptb; } if (e.Button == MouseButtons.Right && ObjectSelect != null) { m_image = null; ObjectSelect.BorderStyle = BorderStyle.None; ObjectSelect = null; } }
public void DeleteObject(PictureBoxObject ptb) { ptbContain.Controls.Remove(ObjectSelect); }
private void LoadDataToFile() { string NameObject; int x, y; if (loadFile.ShowDialog() == DialogResult.OK) { ptbContain.Controls.Clear(); string filePath = loadFile.FileName; StreamReader sr = File.OpenText(filePath); string line = null; line = sr.ReadLine(); while ((line = sr.ReadLine()) != null) { if (line.Trim().CompareTo("<End>") == 0) { break; } string[] result = line.Split(' '); NameObject = result[1].Trim(); x = int.Parse(result[2].ToString()); y = int.Parse(result[3].ToString()); //load vao nao //(2 * ptbContain.Height - y - control.Image.Height)/ 2 if (NameObject.CompareTo("CLOUD") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[0], (x - ListImage[0].Width) / 2, (2 * ptbContain.Height - (y + ListImage[0].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("GRASS") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[1], (x - ListImage[1].Width) / 2, (2 * ptbContain.Height - (y + ListImage[1].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("BIGTREE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[2], (x - ListImage[2].Width) / 2, (2 * ptbContain.Height - (y + ListImage[2].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("SMALLTREE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[3], (x - ListImage[3].Width) / 2, (2 * ptbContain.Height - (y + ListImage[3].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("BIGPIPE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[4], (x - ListImage[4].Width) / 2, (2 * ptbContain.Height - (y + ListImage[4].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("MEDIUMPIPE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[5], (x - ListImage[5].Width) / 2, (2 * ptbContain.Height - (y + ListImage[5].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("SMALLPIPE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[6], (x - ListImage[6].Width) / 2, (2 * ptbContain.Height - (y + ListImage[6].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("FENCE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[7], (x - ListImage[7].Width) / 2, (2 * ptbContain.Height - (y + ListImage[7].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("MOUNTAIN") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[8], (x - ListImage[8].Width) / 2, (2 * ptbContain.Height - (y + ListImage[8].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("HOUSE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[9], (x - ListImage[9].Width) / 2, (2 * ptbContain.Height - (y + ListImage[9].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("BRICK") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[10], (x - ListImage[10].Width) / 2, (2 * ptbContain.Height - (y + ListImage[10].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("LAND") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[11], (x - ListImage[11].Width) / 2, (2 * ptbContain.Height - (y + ListImage[11].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("COINQUESTION") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[12], (x - ListImage[12].Width) / 2, (2 * ptbContain.Height - (y + ListImage[12].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("COIN") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[13], (x - ListImage[13].Width) / 2, (2 * ptbContain.Height - (y + ListImage[13].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); ptbContain.Invalidate(); } else if (NameObject.CompareTo("FLOWER") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[14], (x - ListImage[14].Width) / 2, (2 * ptbContain.Height - (y + ListImage[14].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("STAR") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[15], (x - ListImage[15].Width) / 2, (2 * ptbContain.Height - (y + ListImage[15].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("MUSHROOMBIG") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[16], (x - ListImage[16].Width) / 2, (2 * ptbContain.Height - (y + ListImage[16].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("MUSHROOMLIFE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[17], (x - ListImage[17].Width) / 2, (2 * ptbContain.Height - (y + ListImage[17].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("MUSHROOM") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[18], (x - ListImage[18].Width) / 2, (2 * ptbContain.Height - (y + ListImage[18].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("TURTLE") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[19], (x - ListImage[19].Width) / 2, (2 * ptbContain.Height - (y + ListImage[19].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("BOSS") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[20], (x - ListImage[20].Width) / 2, (2 * ptbContain.Height - (y + ListImage[20].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } else if (NameObject.CompareTo("FLAG") == 0) { PictureBoxObject ptb = new PictureBoxObject(ListImage[21], (x - ListImage[21].Width) / 2, (2 * ptbContain.Height - (y + ListImage[21].Height)) / 2); ptb.BorderStyle = BorderStyle.None; ptbContain.Controls.Add(ptb); } } } }