private void Table_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { cont++;//para identificar posteriormente cada item en el mapa currentObj = sender is ReferenceTable?CreateMoveableTable(sender) : CreateMoveableObj(sender); currentObj.Left = 100 + (10 * PnlMap.Controls.Count);//para crear en diferentes lugares currentObj.Top = 100 + (10 * PnlMap.Controls.Count); currentObj.Width = 90; currentObj.Height = 90; currentObj.SizeMode = PictureBoxSizeMode.StretchImage; currentObj.BackColor = Color.Transparent; currentObj.ContextMenuStrip = this.cmenuStripTable; currentObj.MouseDown += Ctr_MouseDown; currentObj.MouseUp += Ctr_MouseUp; currentObj.MouseMove += Ctr_MouseMove; this.PnlMap.Controls.Add(currentObj); this.BtnSave.Enabled = PnlMap.Controls.OfType <MoveableTable>().Count() > 0; ActualizarEstado(); } }
private async void CargarMapaToolStripMenuItem_Click(object sender, EventArgs e) { openFile = new OpenFileDialog(); openFile.InitialDirectory = Directory.CreateDirectory($@"{Environment.CurrentDirectory}/Mapas").FullName; openFile.Multiselect = false; openFile.Filter = "|*.xml"; openFile.ShowHelp = false; if (openFile.ShowDialog() != DialogResult.OK) { return; } var path = openFile.FileName; XmlSerializer reader = new XmlSerializer(typeof(List <XmlTable>)); StreamReader file = new StreamReader(path); var xmlTables = (List <XmlTable>)reader.Deserialize(file); //cargar mesas correspondientes al mapa await GetRelatedTables(xmlTables.First().TackId); foreach (XmlTable item in xmlTables) { MoveableObject temp = tableObjs.Any(t => t.MoveableTableId == item.Id) ? new MoveableTable { BindedEntity = tableObjs.First(t => t.MoveableTableId == item.Id), ContextMenuStrip = cMenuStripMapLoad } : new MoveableObject(); temp.Id = item.Id; temp.Height = item.Height; temp.Width = item.Width; temp.Left = item.Left; temp.Top = item.Top; Point loc = new Point(); loc.X = item.X; loc.Y = item.Y; temp.Location = loc; temp.SizeMode = PictureBoxSizeMode.StretchImage; temp.BackColor = Color.Transparent; var dir = Directory.CreateDirectory($@"{Environment.CurrentDirectory}/Imagenes"); var imgPath = $@"{dir.FullName}/{item.imageFile}"; temp.Image = Image.FromFile(imgPath); this.PnlMapLoad.Controls.Add(temp); } file.Close(); PnlMapLoad.Visible = PnlMapLoad.Controls.Count > 0; UpdateState(); }