private void AddUserFigures() { String localDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var userFiguresFiles = Directory.EnumerateFiles(localDirectory, "*UserFigure.txt"); ToolStripMenuItem menuItem; foreach (var userFigureFile in userFiguresFiles) { try { Stream fileStream = File.Open(userFigureFile, FileMode.Open); string userFigureName = userFigureFile.Substring(userFigureFile.LastIndexOf("\\"), userFigureFile.IndexOf("UserFigure.txt") - userFigureFile.LastIndexOf("\\")); UserFigure userFigure = new UserFigure() { UserFigureList = Serializer.GetFigureListFromFile(fileStream) }; menuItem = new ToolStripMenuItem(userFigureName) { Tag = userFigure }; menuItem.Click += new EventHandler(MenuItemUserFigureClickHandler); figuresToolStripMenuItem.DropDownItems.Add(menuItem); } catch (Exception ex) { MessageBoxButtons button = MessageBoxButtons.OK; string caption = "Error"; MessageBox.Show(ex.Message, caption, button); } } }
public override object Clone() { UserFigure clonedFigure = new UserFigure(); foreach (var figure in UserFigureList) { clonedFigure.UserFigureList.Add((Figure)figure.Clone()); } return(clonedFigure); }
internal void MenuItemUserFigureClickHandler(object sender, EventArgs e) { IsHighlighterOn = false; isUserFigureSelected = true; ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender; UserFigure tempUserFigure = (UserFigure)clickedItem.Tag; ConstUserFigure = (UserFigure)tempUserFigure.Clone(); IsFirstUserFigure = true; }